Merge lp:~vanvugt/compiz/fix-1015898 into lp:compiz/0.9.8

Proposed by Daniel van Vugt on 2012-06-21
Status: Merged
Approved by: Sam Spilsbury on 2012-06-22
Approved revision: 3258
Merged at revision: 3257
Proposed branch: lp:~vanvugt/compiz/fix-1015898
Merge into: lp:compiz/0.9.8
Diff against target: 99 lines (+35/-18)
3 files modified
plugins/decor/decor.xml.in (+2/-2)
src/main.cpp (+33/-1)
src/screen.cpp (+0/-15)
To merge this branch: bzr merge lp:~vanvugt/compiz/fix-1015898
Reviewer Review Type Date Requested Status
Sam Spilsbury 2012-06-21 Approve on 2012-06-22
Review via email: mp+111344@code.launchpad.net

Description of the change

Add reliable detection of the compiz bin directory, which works even if
compiz is started without an explicit path (LP: #1015898)

To post a comment you must log in.
lp:~vanvugt/compiz/fix-1015898 updated on 2012-06-21
3258. By Daniel van Vugt on 2012-06-21

Simplify.

Sam Spilsbury (smspillaz) wrote :

Looks good

36 +static void
37 +detectCompizBinPath (char **argv)

I would say that this should be put in an anonymous namespace without static linkage, however I'm not too sure if its applicable here. Would like thumper to comment.

Daniel van Vugt (vanvugt) wrote :

static is the same as namespace {}

I don't care either way.

Sam Spilsbury (smspillaz) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/decor/decor.xml.in'
2--- plugins/decor/decor.xml.in 2012-06-20 07:46:15 +0000
3+++ plugins/decor/decor.xml.in 2012-06-21 07:15:24 +0000
4@@ -99,8 +99,8 @@
5 </subgroup>
6 <option name="command" type="string">
7 <_short>Command</_short>
8- <_long>Decorator command line that is executed if no decorator is already running. Use prefix "./" if you want the program run from the compiz bin directory.</_long>
9- <default>exec \"$COMPIZ_BIN_PATH/compiz-decorator\"</default>
10+ <_long>Decorator command line that is executed if no decorator is already running.</_long>
11+ <default>exec \"${COMPIZ_BIN_PATH}compiz-decorator\"</default>
12 </option>
13 <option name="mipmap" type="bool">
14 <_short>Mipmap</_short>
15
16=== modified file 'src/main.cpp'
17--- src/main.cpp 2012-04-24 14:22:03 +0000
18+++ src/main.cpp 2012-06-21 07:15:24 +0000
19@@ -33,6 +33,7 @@
20 #include <unistd.h>
21 #include <string.h>
22 #include <sys/wait.h>
23+#include <libgen.h>
24
25 #include "privatescreen.h"
26 #include "privatestackdebugger.h"
27@@ -202,7 +203,36 @@
28 delete modHandler;
29 }
30
31-
32+/*
33+ * Try to detect the true bin directory compiz was run from and store it
34+ * in environment variable COMPIZ_BIN_PATH. If all else fails, don't define it.
35+ */
36+static void
37+detectCompizBinPath (char **argv)
38+{
39+ const char *bin = argv[0];
40+#ifdef __linux__
41+ char exe[PATH_MAX];
42+ if (readlink ("/proc/self/exe", exe, sizeof(exe)-1) > 0)
43+ bin = exe;
44+#endif
45+ if (strchr (bin, '/')) // dirname needs a '/' to work reliably
46+ {
47+ // We need a private copy for dirname() to modify
48+ char *tmpBin = strdup (bin);
49+ if (tmpBin)
50+ {
51+ const char *binDir = dirname (tmpBin);
52+ if (binDir)
53+ {
54+ char env[PATH_MAX];
55+ snprintf (env, sizeof(env)-1, "COMPIZ_BIN_PATH=%s/", binDir);
56+ putenv (strdup (env)); // parameter needs to be leaked!
57+ }
58+ free (tmpBin);
59+ }
60+ }
61+}
62
63 int
64 main (int argc, char **argv)
65@@ -213,6 +243,8 @@
66 programArgc = argc;
67 programArgv = argv;
68
69+ detectCompizBinPath (argv);
70+
71 signal (SIGCHLD, chldSignalHandler);
72
73 if (!manager.parseArguments (argc, argv))
74
75=== modified file 'src/screen.cpp'
76--- src/screen.cpp 2012-06-18 06:22:29 +0000
77+++ src/screen.cpp 2012-06-21 07:15:24 +0000
78@@ -3897,21 +3897,6 @@
79
80 putenv (strdup (env.c_str ())); // parameter needs to be leaked!
81
82- // We need a private copy of argv[0] for dirname() to modify
83- char *argv0 = strdup (programArgv[0]);
84- if (argv0 != NULL)
85- {
86- const char *binpath = dirname (argv0);
87- if (binpath == NULL)
88- binpath = ".";
89- char binenv[PATH_MAX];
90- snprintf (binenv, sizeof(binenv)-1, "COMPIZ_BIN_PATH=%s/", binpath);
91- putenv (strdup (binenv)); // parameter needs to be leaked!
92- if (binpath != NULL && command.substr (0, 2) == "./")
93- command.replace (0, 1, binpath);
94- free (argv0);
95- }
96-
97 exit (execl ("/bin/sh", "/bin/sh", "-c", command.c_str (), NULL));
98 }
99 }

Subscribers

People subscribed via source and target branches