daemon: don't crash if pa_realpath() fails
authorLennart Poettering <lennart@poettering.net>
Fri, 30 Oct 2009 04:08:48 +0000 (05:08 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 30 Oct 2009 04:08:48 +0000 (05:08 +0100)
src/daemon/main.c

index 9e5647a..576fc3e 100644 (file)
@@ -425,21 +425,24 @@ int main(int argc, char *argv[]) {
 
         pa_set_env("LD_BIND_NOW", "1");
 
-        canonical_rp = pa_realpath(PA_BINARY);
+        if (!(canonical_rp = pa_realpath(PA_BINARY))) {
 
-        if ((rp = pa_readlink("/proc/self/exe"))) {
+            if ((rp = pa_readlink("/proc/self/exe"))) {
 
-            if (pa_streq(rp, canonical_rp))
-                pa_assert_se(execv(rp, argv) == 0);
-            else
-                pa_log_warn("/proc/self/exe does not point to %s, cannot self execute. Are you playing games?", canonical_rp);
+                if (pa_streq(rp, canonical_rp))
+                    pa_assert_se(execv(rp, argv) == 0);
+                else
+                    pa_log_warn("/proc/self/exe does not point to %s, cannot self execute. Are you playing games?", canonical_rp);
 
-            pa_xfree(rp);
+                pa_xfree(rp);
 
-        } else
-            pa_log_warn("Couldn't read /proc/self/exe, cannot self execute. Running in a chroot()?");
+            } else
+                pa_log_warn("Couldn't read /proc/self/exe, cannot self execute. Running in a chroot()?");
 
-        pa_xfree(canonical_rp);
+            pa_xfree(canonical_rp);
+
+        } else
+            pa_log_warn("Couldn't canonicalize binary path, cannot self execute.");
     }
 #endif