34109b2
From 260a4414ac26cc5e91dc56b6a10b5dda3dae22cd Mon Sep 17 00:00:00 2001
34109b2
From: Michael Catanzaro <mcatanzaro@gnome.org>
34109b2
Date: Thu, 24 Sep 2020 15:06:44 -0500
34109b2
Subject: [PATCH] Don't use dbus-broker if not running under systemd
34109b2
34109b2
Since gdm@febeb9a9, gdm no longer runs a systemd user session, because
34109b2
gdm supports multiseat but systemd only allows one graphical session per
34109b2
user. Since gdm currently runs as the gdm user, that means we cannot use
34109b2
systemd there. Benjamin Berg says we could fix that by changing gdm to
34109b2
use temporary users for each seat, but that would be a lot of work.
34109b2
34109b2
Meanwhile, dbus-broker relies on systemd to autostart D-Bus services. So
34109b2
if we are not running a systemd user session, nothing gets autostarted
34109b2
in response to D-Bus calls. That means orca never gets any response to
34109b2
its method calls to org.a11y.atspi.Registry, and we wind up with no
34109b2
accessibility on the gnome-shell login screen.
34109b2
34109b2
Fix this by implementing Benjamin's suggested check to see if we are
34109b2
running under systemd before using dbus-broker. So now we will use
34109b2
dbus-daemon on the login screen, but we will still use dbus-broker for
34109b2
the user session (except in distros that still prefer dbus-daemon...
34109b2
which is actually the default configuration). libsystemd is added as a
34109b2
build dependency whenever built with dbus-broker support, which should
34109b2
be uncontroversial because it won't work without systemd.
34109b2
34109b2
I expect dbus-daemon is going to live alongside dbus-broker for a long
34109b2
time, because it seems very hard for us to migrate fully.
34109b2
34109b2
Big thanks to Benjamin Berg for discovering the problem and suggesting
34109b2
this solution.
34109b2
34109b2
Fixes #25
34109b2
---
34109b2
 bus/at-spi-bus-launcher.c | 18 ++++++++++++++++++
34109b2
 bus/meson.build           | 11 ++++++++++-
34109b2
 2 files changed, 28 insertions(+), 1 deletion(-)
34109b2
34109b2
diff --git a/bus/at-spi-bus-launcher.c b/bus/at-spi-bus-launcher.c
34109b2
index 362fd05f..d7c66900 100644
34109b2
--- a/bus/at-spi-bus-launcher.c
34109b2
+++ b/bus/at-spi-bus-launcher.c
34109b2
@@ -39,6 +39,9 @@
34109b2
 #include <X11/Xlib.h>
34109b2
 #include <X11/Xatom.h>
34109b2
 #endif
34109b2
+#ifdef DBUS_BROKER
34109b2
+#include <systemd/sd-login.h>
34109b2
+#endif
34109b2
 
34109b2
 typedef enum {
34109b2
   A11Y_BUS_STATE_IDLE = 0,
34109b2
@@ -392,11 +395,26 @@ static gboolean
34109b2
 ensure_a11y_bus_broker (A11yBusLauncher *app, char *config_path)
34109b2
 {
34109b2
   char *argv[] = { DBUS_BROKER, config_path, "--scope", "user", NULL };
34109b2
+  char *unit;
34109b2
   struct sockaddr_un addr = { .sun_family = AF_UNIX };
34109b2
   socklen_t addr_len = sizeof(addr);
34109b2
   GPid pid;
34109b2
   GError *error = NULL;
34109b2
 
34109b2
+  /* This detects whether we are running under systemd. We only try to
34109b2
+   * use dbus-broker if we are running under systemd because D-Bus
34109b2
+   * service activation won't work otherwise.
34109b2
+   */
34109b2
+  if (sd_pid_get_user_unit (getpid (), &unit) >= 0)
34109b2
+    {
34109b2
+      free (unit);
34109b2
+    }
34109b2
+  else
34109b2
+    {
34109b2
+      app->state = A11Y_BUS_STATE_ERROR;
34109b2
+      return FALSE;
34109b2
+    }
34109b2
+
34109b2
   if ((app->listenfd = socket (PF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0)) < 0)
34109b2
     g_error ("Failed to create listening socket: %s", strerror (errno));
34109b2
 
34109b2
diff --git a/bus/meson.build b/bus/meson.build
34109b2
index 0fff5a89..f6c32c99 100644
34109b2
--- a/bus/meson.build
34109b2
+++ b/bus/meson.build
34109b2
@@ -48,13 +48,16 @@ else
34109b2
   endif
34109b2
 endif
34109b2
 
34109b2
+needs_systemd = false
34109b2
 if get_option('dbus_broker') != 'default'
34109b2
   launcher_args += '-DDBUS_BROKER="@0@"'.format(get_option('dbus_broker'))
34109b2
+  needs_systemd = true
34109b2
 else
34109b2
   dbus_broker = find_program('dbus-broker-launch',
34109b2
                              required: false)
34109b2
   if dbus_broker.found()
34109b2
     launcher_args += '-DDBUS_BROKER="@0@"'.format(dbus_broker.path())
34109b2
+    needs_systemd = true
34109b2
   endif
34109b2
 endif
34109b2
 
34109b2
@@ -62,9 +65,15 @@ if get_option('default_bus') == 'dbus-broker'
34109b2
   launcher_args += '-DWANT_DBUS_BROKER'
34109b2
 endif
34109b2
 
34109b2
+if needs_systemd
34109b2
+  systemd_dep = dependency('libsystemd')
34109b2
+else
34109b2
+  systemd_dep = dependency('', required: false)
34109b2
+endif
34109b2
+
34109b2
 executable('at-spi-bus-launcher', 'at-spi-bus-launcher.c',
34109b2
            include_directories: [ root_inc, include_directories('.') ],
34109b2
-           dependencies: [ gio_dep, x11_deps ],
34109b2
+           dependencies: [ gio_dep, systemd_dep, x11_deps ],
34109b2
            c_args: launcher_args,
34109b2
            install: true,
34109b2
            install_dir: atspi_libexecdir)
34109b2
-- 
34109b2
GitLab