Mir

Merge lp:~vanvugt/mir/fix-1406073 into lp:mir

Proposed by Daniel van Vugt on 2014-12-28
Status: Merged
Approved by: Daniel van Vugt on 2014-12-29
Approved revision: 2190
Merged at revision: 2188
Proposed branch: lp:~vanvugt/mir/fix-1406073
Merge into: lp:mir
Diff against target: 112 lines (+59/-17)
3 files modified
cmake/MirCommon.cmake (+4/-11)
src/CMakeLists.txt (+6/-0)
src/wrapper.c (+49/-6)
To merge this branch: bzr merge lp:~vanvugt/mir/fix-1406073
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration 2014-12-28 Approve on 2014-12-29
Mir development team 2014-12-28 Pending
Review via email: mp+245410@code.launchpad.net

Commit message

Make the binary wrapper completely position independent, so it continues
to work after directory renames/moves and on hosts other than the build
machine too. (LP: #1406073)

Description of the change

Part of my daily workflow is to build on one host and rsync binaries to another (e.g. a phone). That workflow no longer works without this fix.

A child branch of this one further improves on what's here...
lp:~vanvugt/mir/fix-1406098

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmake/MirCommon.cmake'
2--- cmake/MirCommon.cmake 2014-12-11 06:14:56 +0000
3+++ cmake/MirCommon.cmake 2014-12-28 14:37:15 +0000
4@@ -174,17 +174,10 @@
5 add_executable(${TARGET} ${ARGN})
6 set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${REAL_EXECUTABLE})
7
8- add_executable(${TARGET}-wrapper ${PROJECT_SOURCE_DIR}/cmake/src/wrapper.c)
9- set_property(TARGET ${TARGET}-wrapper
10- APPEND_STRING PROPERTY COMPILE_FLAGS " -DEXECUTABLE=\\\"${REAL_EXECUTABLE}\\\"")
11- set_property(TARGET ${TARGET}-wrapper
12- APPEND_STRING PROPERTY COMPILE_FLAGS " -DBUILD_PREFIX=\\\"${CMAKE_BINARY_DIR}\\\"")
13- set_property(TARGET ${TARGET}-wrapper
14- APPEND_STRING PROPERTY COMPILE_FLAGS " -D_BSD_SOURCE")
15- set_property(TARGET ${TARGET}-wrapper
16- PROPERTY OUTPUT_NAME ${TARGET})
17-
18- add_dependencies(${TARGET} ${TARGET}-wrapper)
19+ add_custom_target(${TARGET}-wrapped
20+ ln -fs wrapper ${CMAKE_BINARY_DIR}/bin/${TARGET}
21+ )
22+ add_dependencies(${TARGET} ${TARGET}-wrapped)
23
24 install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/${REAL_EXECUTABLE}
25 DESTINATION ${CMAKE_INSTALL_BINDIR}
26
27=== modified file 'src/CMakeLists.txt'
28--- src/CMakeLists.txt 2014-12-19 21:52:32 +0000
29+++ src/CMakeLists.txt 2014-12-28 14:37:15 +0000
30@@ -23,6 +23,12 @@
31 add_subdirectory(client/)
32 add_subdirectory(utils/)
33
34+add_executable(wrapper wrapper.c)
35+set_property(TARGET wrapper
36+ APPEND_STRING PROPERTY COMPILE_FLAGS " -DEXECUTABLE_FORMAT=\\\".%s-uninstalled\\\"")
37+set_property(TARGET wrapper
38+ APPEND_STRING PROPERTY COMPILE_FLAGS " -D_BSD_SOURCE")
39+
40 set(
41 MIR_GENERATED_INCLUDE_DIRECTORIES
42 ${MIR_GENERATED_INCLUDE_DIRECTORIES}
43
44=== renamed file 'cmake/src/wrapper.c' => 'src/wrapper.c'
45--- cmake/src/wrapper.c 2014-12-03 00:24:52 +0000
46+++ src/wrapper.c 2014-12-28 14:37:15 +0000
47@@ -1,16 +1,59 @@
48+/*
49+ * Copyright © 2014 Canonical Ltd.
50+ *
51+ * This program is free software: you can redistribute it and/or modify it
52+ * under the terms of the GNU General Public License version 3,
53+ * as published by the Free Software Foundation.
54+ *
55+ * This program is distributed in the hope that it will be useful,
56+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
57+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58+ * GNU General Public License for more details.
59+ *
60+ * You should have received a copy of the GNU General Public License
61+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
62+ *
63+ * Author: Daniel van Vugt <daniel.van.vugt@canonical.com>
64+ */
65+
66+#include <string.h>
67 #include <stdlib.h>
68 #include <stdio.h>
69 #include <unistd.h>
70-#include <assert.h>
71
72 int main(int argc, char** argv)
73 {
74- assert(argc > 0);
75- setenv("MIR_CLIENT_PLATFORM_PATH", BUILD_PREFIX "/lib/client-modules/", 1);
76-
77- argv[0] = BUILD_PREFIX "/bin/" EXECUTABLE;
78+ char path[1024], *dest = path, *dest_max = path+sizeof(path)-1;
79+ char *pivot = path;
80+ size_t pivot_max = 0;
81+ const char *src = argv[0], *name = argv[0];
82+
83+ (void)argc;
84+ while (*src && dest < dest_max)
85+ {
86+ *dest = *src;
87+ if (*dest == '/')
88+ {
89+ pivot = dest + 1;
90+ name = src + 1;
91+ }
92+ ++src;
93+ ++dest;
94+ }
95+ pivot_max = dest_max - pivot;
96+
97+ strncpy(pivot, "../lib/client-modules/", pivot_max);
98+ *dest_max = '\0';
99+ setenv("MIR_CLIENT_PLATFORM_PATH", path, 1);
100+ printf("MIR_CLIENT_PLATFORM_PATH=%s\n", path);
101+
102+ snprintf(pivot, pivot_max, EXECUTABLE_FORMAT, name);
103+ *dest_max = '\0';
104+ printf("exec=%s\n", path);
105+
106+ argv[0] = path;
107 execv(argv[0], argv);
108
109- perror("Failed to execute real binary " EXECUTABLE);
110+ fprintf(stderr, "Failed to execute: %s\n", path);
111 return 1;
112 }

Subscribers

People subscribed via source and target branches