]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
login: support user-bus on dbus1
authorDavid Herrmann <dh.herrmann@gmail.com>
Mon, 31 Aug 2015 16:07:46 +0000 (18:07 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Mon, 31 Aug 2015 16:12:37 +0000 (18:12 +0200)
dbus-1.10 was just released, including systemd units to run
`dbus-daemon --session` as systemd user unit. This allows using a
user-bus with dbus1, just like we do per default with kdbus.

All the dbus libraries have already been fixed long ago to use the
user-bus as default. Hence, there's no need to set
DBUS_SESSION_BUS_ADDRESS= if we use the user-bus. However, gdm and
friends continue to spawn a session bus if this variable is not set
(instead of checking for the existence of the user-bus). Hence, we force
the user-bus, if it is available, in pam_systemd. Once gdm and friends
are fixed, we can continue to drop this again. However, that might take
a while.

With this in place, all that is needed to make the user-bus work is:
    `systemctl --global enable dbus.socket`

If dbus.socket is not enabled, the legacy session-bus is still used.

Based on a patch by: Jan Alexander Steffens <jan.steffens@gmail.com>

src/login/pam_systemd.c
xorg/50-systemd-user.sh

index f83d18b0358f413ab4174d07b4fe61c1be888c15..71c84d8e0a9efaa272cd1fdfbb153dacbdde2607 100644 (file)
@@ -179,24 +179,37 @@ static int export_legacy_dbus_address(
                 const char *runtime) {
 
         _cleanup_free_ char *s = NULL;
-        int r;
+        int r = PAM_BUF_ERR;
 
-        /* skip export if kdbus is not active */
-        if (!is_kdbus_available())
-                return PAM_SUCCESS;
+        if (is_kdbus_available()) {
+                if (asprintf(&s, KERNEL_USER_BUS_ADDRESS_FMT ";" UNIX_USER_BUS_ADDRESS_FMT, uid, runtime) < 0)
+                        goto error;
+        } else {
+                /* FIXME: We *realy* should move the access() check into the
+                 * daemons that spawn dbus-daemon, instead of forcing
+                 * DBUS_SESSION_BUS_ADDRESS= here. */
+
+                s = strjoin(runtime, "/bus", NULL);
+                if (!s)
+                        goto error;
+
+                if (access(s, F_OK) < 0)
+                        return PAM_SUCCESS;
 
-        if (asprintf(&s, KERNEL_USER_BUS_ADDRESS_FMT ";" UNIX_USER_BUS_ADDRESS_FMT, uid, runtime) < 0) {
-                pam_syslog(handle, LOG_ERR, "Failed to set bus variable.");
-                return PAM_BUF_ERR;
+                s = mfree(s);
+                if (asprintf(&s, UNIX_USER_BUS_ADDRESS_FMT, runtime) < 0)
+                        goto error;
         }
 
         r = pam_misc_setenv(handle, "DBUS_SESSION_BUS_ADDRESS", s, 0);
-        if (r != PAM_SUCCESS) {
-                pam_syslog(handle, LOG_ERR, "Failed to set bus variable.");
-                return r;
-        }
+        if (r != PAM_SUCCESS)
+                goto error;
 
         return PAM_SUCCESS;
+
+error:
+        pam_syslog(handle, LOG_ERR, "Failed to set bus variable.");
+        return r;
 }
 
 _public_ PAM_EXTERN int pam_sm_open_session(
index f4df13b61958eac15f78b295d85daf7c4669542c..4d497672283bbf463b9a93fe2559a86f1d19b7e7 100755 (executable)
@@ -1,3 +1,7 @@
 #!/bin/sh
 
 systemctl --user import-environment DISPLAY XAUTHORITY
+
+if which dbus-update-activation-environment >/dev/null 2>&1; then
+        dbus-update-activation-environment DISPLAY XAUTHORITY
+fi