ryantimwilson / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
05ec6e
From c5698fe9076a8dc3472140c7d67f4524430f80a0 Mon Sep 17 00:00:00 2001
05ec6e
From: Daan De Meyer <daan.j.demeyer@gmail.com>
05ec6e
Date: Tue, 22 Oct 2024 10:59:27 +0200
05ec6e
Subject: [PATCH 1/3] bus-util: Return ENOMEDIUM if XDG_RUNTIME_DIR is unset
05ec6e
05ec6e
bus_log_connect_error() checks for ENOMEDIUM, not ENXIO.
05ec6e
---
05ec6e
 src/shared/bus-util.c | 2 +-
05ec6e
 1 file changed, 1 insertion(+), 1 deletion(-)
05ec6e
05ec6e
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
05ec6e
index 6ea046ee6d435..57c60dcb67d33 100644
05ec6e
--- a/src/shared/bus-util.c
05ec6e
+++ b/src/shared/bus-util.c
05ec6e
@@ -259,7 +259,7 @@ int bus_connect_user_systemd(sd_bus **ret_bus) {
05ec6e
 
05ec6e
         e = secure_getenv("XDG_RUNTIME_DIR");
05ec6e
         if (!e)
05ec6e
-                return -ENXIO;
05ec6e
+                return -ENOMEDIUM;
05ec6e
 
05ec6e
         ee = bus_address_escape(e);
05ec6e
         if (!ee)
05ec6e
05ec6e
From d0316b7a0d356ba12325ce5a00b0cbe0bc359461 Mon Sep 17 00:00:00 2001
05ec6e
From: Daan De Meyer <daan.j.demeyer@gmail.com>
05ec6e
Date: Tue, 22 Oct 2024 11:12:17 +0200
05ec6e
Subject: [PATCH 2/3] bus-util: Special case when DBUS_SESSION_BUS_ADDRESS is
05ec6e
 set and XDG_RUNTIME_DIR isn't
05ec6e
05ec6e
We noticed some failures because we have code that connects to user
05ec6e
managers by setting DBUS_SESSION_BUS_ADDRESS without setting XDG_RUNTIME_DIR.
05ec6e
If that's the case, connect to the user session bus instead of the
05ec6e
private manager bus as we can't connect to the latter if XDG_RUNTIME_DIR
05ec6e
is not set.
05ec6e
---
05ec6e
 src/shared/bus-util.c | 12 +++++++++++-
05ec6e
 1 file changed, 11 insertions(+), 1 deletion(-)
05ec6e
05ec6e
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
05ec6e
index 57c60dcb67d33..fa4f879b7bac3 100644
05ec6e
--- a/src/shared/bus-util.c
05ec6e
+++ b/src/shared/bus-util.c
05ec6e
@@ -496,6 +496,8 @@ int bus_connect_transport_systemd(
05ec6e
                 RuntimeScope runtime_scope,
05ec6e
                 sd_bus **ret_bus) {
05ec6e
 
05ec6e
+        int r;
05ec6e
+
05ec6e
         assert(transport >= 0);
05ec6e
         assert(transport < _BUS_TRANSPORT_MAX);
05ec6e
         assert(ret_bus);
05ec6e
@@ -508,7 +510,15 @@ int bus_connect_transport_systemd(
05ec6e
                 switch (runtime_scope) {
05ec6e
 
05ec6e
                 case RUNTIME_SCOPE_USER:
05ec6e
-                        return bus_connect_user_systemd(ret_bus);
05ec6e
+                        r = bus_connect_user_systemd(ret_bus);
05ec6e
+                        /* We used to always fall back to the user session bus if we couldn't connect to the
05ec6e
+                         * private manager bus. To keep compat with existing code that was setting
05ec6e
+                         * DBUS_SESSION_BUS_ADDRESS without setting XDG_RUNTIME_DIR, connect to the user
05ec6e
+                         * session bus if DBUS_SESSION_BUS_ADDRESS is set and XDG_RUNTIME_DIR isn't. */
05ec6e
+                        if (r == -ENOMEDIUM && secure_getenv("DBUS_SESSION_BUS_ADDRESS"))
05ec6e
+                                r = sd_bus_default_user(ret_bus);
05ec6e
+
05ec6e
+                        return r;
05ec6e
 
05ec6e
                 case RUNTIME_SCOPE_SYSTEM:
05ec6e
                         if (sd_booted() <= 0)
05ec6e
05ec6e
From d64a5b30f10a07001c4124f5c4127452fc3cac99 Mon Sep 17 00:00:00 2001
05ec6e
From: Daan De Meyer <daan.j.demeyer@gmail.com>
05ec6e
Date: Tue, 22 Oct 2024 12:32:02 +0200
05ec6e
Subject: [PATCH 3/3] bus-util: Fix bus_log_connect_error()
05ec6e
05ec6e
---
05ec6e
 src/shared/bus-util.c | 6 +++---
05ec6e
 1 file changed, 3 insertions(+), 3 deletions(-)
05ec6e
05ec6e
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
05ec6e
index fa4f879b7bac3..ce94597955aa3 100644
05ec6e
--- a/src/shared/bus-util.c
05ec6e
+++ b/src/shared/bus-util.c
05ec6e
@@ -56,9 +56,9 @@ int bus_log_connect_error(int r, BusTransport transport, RuntimeScope scope) {
05ec6e
              hint_addr = transport == BUS_TRANSPORT_LOCAL && ERRNO_IS_PRIVILEGE(r);
05ec6e
 
05ec6e
         return log_error_errno(r,
05ec6e
-                               r == hint_vars ? "Failed to connect to %s scope bus via %s transport: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=<user>@.host --user to connect to bus of other user)" :
05ec6e
-                               r == hint_addr ? "Failed to connect to %s scope bus via %s transport: Operation not permitted (consider using --machine=<user>@.host --user to connect to bus of other user)" :
05ec6e
-                                                "Failed to connect to %s scope bus via %s transport: %m", runtime_scope_to_string(scope), bus_transport_to_string(transport));
05ec6e
+                               hint_vars ? "Failed to connect to %s scope bus via %s transport: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=<user>@.host --user to connect to bus of other user)" :
05ec6e
+                               hint_addr ? "Failed to connect to %s scope bus via %s transport: Operation not permitted (consider using --machine=<user>@.host --user to connect to bus of other user)" :
05ec6e
+                                           "Failed to connect to %s scope bus via %s transport: %m", runtime_scope_to_string(scope), bus_transport_to_string(transport));
05ec6e
 }
05ec6e
 
05ec6e
 int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name) {