]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus-launch: Generalize support for discovering an existing bus
authorSimon McVittie <smcv@collabora.com>
Wed, 16 Mar 2022 13:24:53 +0000 (13:24 +0000)
committerSimon McVittie <smcv@collabora.com>
Tue, 29 Mar 2022 14:38:43 +0000 (14:38 +0000)
Previously we were looking for an existing bus via
_dbus_lookup_user_bus(), meaning a user bus $XDG_RUNTIME_DIR/bus
(in practice this is managed by systemd --user, although in principle
there's nothing to stop other session frameworks from providing the
same thing).

_dbus_lookup_session_address() looks for an externally-managed
dbus-daemon in a more general way: on macOS it uses launchd, and on other
Unix it's a thin wrapper around _dbus_lookup_user_bus(). Let's try that,
so that macOS users can get their existing dbus-daemon from launchd.

This partially resolves dbus/dbus#385, although initially only for macOS
users who have (unusually) enabled X11 autolaunching support.

Signed-off-by: Simon McVittie <smcv@collabora.com>
dbus/dbus-sysdeps-unix.c
dbus/dbus-sysdeps-unix.h
dbus/dbus-sysdeps.h
tools/dbus-launch.c

index 8743589fd621b2958f59978f0909079d55152513..1c4d0f6f4a31a1e3166328c4805e0ca03c24a741 100644 (file)
@@ -4424,7 +4424,7 @@ _dbus_lookup_session_address_launchd (DBusString *address, DBusError  *error)
 }
 #endif
 
-dbus_bool_t
+static dbus_bool_t
 _dbus_lookup_user_bus (dbus_bool_t *supported,
                        DBusString  *address,
                        DBusError   *error)
index a051b5429b4681f8921ed988e79e68be7013a797..f0b4c7285112d38869ff96733379232448be0ed6 100644 (file)
@@ -90,11 +90,6 @@ dbus_bool_t _dbus_lookup_launchd_socket (DBusString *socket_path,
                                          const char *launchd_env_var,
                                          DBusError  *error);
 
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_lookup_user_bus (dbus_bool_t *supported,
-                                   DBusString  *address,
-                                   DBusError   *error);
-
 /** Information about a UNIX user */
 typedef struct DBusUserInfo  DBusUserInfo;
 /** Information about a UNIX group */
index 95691c6911dbb266731d0f3f916778c685ca2664..80ba68c9dffff7ac417a980bad0434b416e21dfd 100644 (file)
@@ -628,6 +628,7 @@ dbus_bool_t _dbus_get_autolaunch_address (const char *scope,
                                           DBusString *address,
                                                              DBusError  *error);
 
+DBUS_PRIVATE_EXPORT
 dbus_bool_t _dbus_lookup_session_address (dbus_bool_t *supported,
                                           DBusString  *address,
                                           DBusError   *error);
index f1a5b9708a99e8142a1ab167fc447581aa0b7179..78bd97d44756d23175ad0a7dc524d7f8dff97384 100644 (file)
@@ -843,8 +843,8 @@ main (int argc, char **argv)
   int bus_pid_to_babysitter_pipe[2];
   int bus_address_to_launcher_pipe[2];
   char *config_file;
-  dbus_bool_t user_bus_supported = FALSE;
-  DBusString user_bus;
+  dbus_bool_t existing_bus_supported = FALSE;
+  DBusString existing_bus;
   const char *error_str;
 #ifdef DBUS_BUILD_X11
   DBusError error = DBUS_ERROR_INIT;
@@ -1028,12 +1028,14 @@ main (int argc, char **argv)
           exit (1);
         }
 
-      if (!_dbus_string_init (&user_bus))
+      if (!_dbus_string_init (&existing_bus))
         tool_oom ("initializing");
 
       /* If we have an XDG_RUNTIME_DIR and it contains a suitable socket,
        * dbus-launch --autolaunch can use it, since --autolaunch implies
        * "I'm OK with getting a bus that is already active".
+       * Similarly, if we're on macOS with launchd enabled, we can reuse
+       * that here.
        *
        * (However, plain dbus-launch without --autolaunch must not do so,
        * because that would break lots of regression tests, which often
@@ -1044,19 +1046,20 @@ main (int argc, char **argv)
        * on the X11 display and in ~/.dbus/session-bus, for full
        * backwards compatibility.
        */
-      if (!_dbus_lookup_user_bus (&user_bus_supported, &user_bus, &error))
+      if (!_dbus_lookup_session_address (&existing_bus_supported,
+                                         &existing_bus, &error))
         {
           fprintf (stderr, "%s\n", error.message);
           exit (1);
         }
-      else if (user_bus_supported)
+      else if (existing_bus_supported)
         {
-          verbose ("=== Using existing user bus \"%s\"\n",
-                   _dbus_string_get_const_data (&user_bus));
+          verbose ("=== Using existing session bus \"%s\"\n",
+                   _dbus_string_get_const_data (&existing_bus));
         }
       else
         {
-          _dbus_string_free (&user_bus);
+          _dbus_string_free (&existing_bus);
         }
 
       verbose ("Autolaunch enabled (using X11).\n");
@@ -1203,16 +1206,16 @@ main (int argc, char **argv)
       close (bus_pid_to_babysitter_pipe[READ_END]);
       close (bus_pid_to_babysitter_pipe[WRITE_END]);
 
-      /* If we have a user bus and want to use it, do so instead of
+      /* If we have an existing bus and want to use it, do so instead of
        * exec'ing a new dbus-daemon. */
-      if (autolaunch && user_bus_supported)
+      if (autolaunch && existing_bus_supported)
         {
           do_write (bus_pid_to_launcher_pipe[WRITE_END], "0\n", 2);
           close (bus_pid_to_launcher_pipe[WRITE_END]);
 
           do_write (bus_address_to_launcher_pipe[WRITE_END],
-                    _dbus_string_get_const_data (&user_bus),
-                    _dbus_string_get_length (&user_bus));
+                    _dbus_string_get_const_data (&existing_bus),
+                    _dbus_string_get_length (&existing_bus));
           do_write (bus_address_to_launcher_pipe[WRITE_END], "\n", 1);
           close (bus_address_to_launcher_pipe[WRITE_END]);