Cope with dbus-launch not being in DBUS_BINDIR
authorColin Walters <walters@verbum.org>
Tue, 14 Jul 2009 15:43:54 +0000 (11:43 -0400)
committerColin Walters <walters@verbum.org>
Tue, 14 Jul 2009 15:43:54 +0000 (11:43 -0400)
This is a temporary hack for systems which use DBUS_BINDIR=/bin,
but then move dbus-launch back into /usr/bin.  Longer term,
we should explicitly support this in upstream code, or even better
figure out how to move dbus-launch into /bin (e.g. dynamically
load libX11 if available), or have a --with-x11-tools configure
option.

dbus/dbus-sysdeps-unix.c

index f2ea7fd..2ae7909 100644 (file)
@@ -2884,7 +2884,8 @@ _dbus_get_tmpdir(void)
  * without writing any data to stdout. Verify the @p result length
  * before and after this function call to cover this case.
  *
- * @param progname initial path to exec
+ * @param progname initial path to exec (may or may not be absolute)
+ * @param path_fallback if %TRUE, search PATH for executable
  * @param argv NULL-terminated list of arguments
  * @param result a DBusString where the output can be append
  * @param error a DBusError to store the error in case of failure
@@ -2892,6 +2893,7 @@ _dbus_get_tmpdir(void)
  */
 static dbus_bool_t
 _read_subprocess_line_argv (const char *progpath,
+                            dbus_bool_t path_fallback,
                             char       * const *argv,
                             DBusString *result,
                             DBusError  *error)
@@ -2903,19 +2905,13 @@ _read_subprocess_line_argv (const char *progpath,
   int status;
   int orig_len;
   int i;
-  DBusString uuid;
+
   dbus_bool_t retval;
   sigset_t new_set, old_set;
   
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
   retval = FALSE;
 
-  if (!_dbus_string_init (&uuid))
-    {
-      _DBUS_SET_OOM (error);
-      return FALSE;
-    }
-
   /* We need to block any existing handlers for SIGCHLD temporarily; they
    * will cause waitpid() below to fail.
    * https://bugs.freedesktop.org/show_bug.cgi?id=21347
@@ -2995,11 +2991,22 @@ _read_subprocess_line_argv (const char *progpath,
       for (i = 3; i < maxfds; i++)
         close (i);
 
-      sigprocmask(SIG_SETMASK, &old_set, NULL);
+      sigprocmask (SIG_SETMASK, &old_set, NULL);
 
       /* If it looks fully-qualified, try execv first */
       if (progpath[0] == '/')
-        execv (progpath, argv);
+        {
+          execv (progpath, argv);
+          /* Ok, that failed.  Now if path_fallback is given, let's
+           * try unqualified.  This is mostly a hack to work
+           * around systems which ship dbus-launch in /usr/bin
+           * but everything else in /bin (because dbus-launch
+           * depends on X11).
+           */
+          if (path_fallback)
+            /* We must have a slash, because we checked above */
+            execvp (strrchr (progpath, '/')+1, argv);
+        }
       else
         execvp (progpath, argv);
 
@@ -3126,7 +3133,8 @@ _dbus_get_autolaunch_address (DBusString *address,
 
   _dbus_assert (i == _DBUS_N_ELEMENTS (argv));
 
-  retval = _read_subprocess_line_argv (DBUS_BINDIR "/dbus-launch", 
+  retval = _read_subprocess_line_argv (DBUS_BINDIR "/dbus-launch",
+                                       TRUE,
                                        argv, address, error);
 
  out: