From 05ec6ebbd8170632e7bf3a99dfdbffa32603f378 Mon Sep 17 00:00:00 2001 From: Ryan Wilson Date: Oct 22 2024 17:53:32 +0000 Subject: Backport bus-util: Return ENOMEDIUM if XDG_RUNTIME_DIR is unset --- diff --git a/34851.patch b/34851.patch new file mode 100644 index 0000000..e923768 --- /dev/null +++ b/34851.patch @@ -0,0 +1,96 @@ +From c5698fe9076a8dc3472140c7d67f4524430f80a0 Mon Sep 17 00:00:00 2001 +From: Daan De Meyer +Date: Tue, 22 Oct 2024 10:59:27 +0200 +Subject: [PATCH 1/3] bus-util: Return ENOMEDIUM if XDG_RUNTIME_DIR is unset + +bus_log_connect_error() checks for ENOMEDIUM, not ENXIO. +--- + src/shared/bus-util.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c +index 6ea046ee6d435..57c60dcb67d33 100644 +--- a/src/shared/bus-util.c ++++ b/src/shared/bus-util.c +@@ -259,7 +259,7 @@ int bus_connect_user_systemd(sd_bus **ret_bus) { + + e = secure_getenv("XDG_RUNTIME_DIR"); + if (!e) +- return -ENXIO; ++ return -ENOMEDIUM; + + ee = bus_address_escape(e); + if (!ee) + +From d0316b7a0d356ba12325ce5a00b0cbe0bc359461 Mon Sep 17 00:00:00 2001 +From: Daan De Meyer +Date: Tue, 22 Oct 2024 11:12:17 +0200 +Subject: [PATCH 2/3] bus-util: Special case when DBUS_SESSION_BUS_ADDRESS is + set and XDG_RUNTIME_DIR isn't + +We noticed some failures because we have code that connects to user +managers by setting DBUS_SESSION_BUS_ADDRESS without setting XDG_RUNTIME_DIR. +If that's the case, connect to the user session bus instead of the +private manager bus as we can't connect to the latter if XDG_RUNTIME_DIR +is not set. +--- + src/shared/bus-util.c | 12 +++++++++++- + 1 file changed, 11 insertions(+), 1 deletion(-) + +diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c +index 57c60dcb67d33..fa4f879b7bac3 100644 +--- a/src/shared/bus-util.c ++++ b/src/shared/bus-util.c +@@ -496,6 +496,8 @@ int bus_connect_transport_systemd( + RuntimeScope runtime_scope, + sd_bus **ret_bus) { + ++ int r; ++ + assert(transport >= 0); + assert(transport < _BUS_TRANSPORT_MAX); + assert(ret_bus); +@@ -508,7 +510,15 @@ int bus_connect_transport_systemd( + switch (runtime_scope) { + + case RUNTIME_SCOPE_USER: +- return bus_connect_user_systemd(ret_bus); ++ r = bus_connect_user_systemd(ret_bus); ++ /* We used to always fall back to the user session bus if we couldn't connect to the ++ * private manager bus. To keep compat with existing code that was setting ++ * DBUS_SESSION_BUS_ADDRESS without setting XDG_RUNTIME_DIR, connect to the user ++ * session bus if DBUS_SESSION_BUS_ADDRESS is set and XDG_RUNTIME_DIR isn't. */ ++ if (r == -ENOMEDIUM && secure_getenv("DBUS_SESSION_BUS_ADDRESS")) ++ r = sd_bus_default_user(ret_bus); ++ ++ return r; + + case RUNTIME_SCOPE_SYSTEM: + if (sd_booted() <= 0) + +From d64a5b30f10a07001c4124f5c4127452fc3cac99 Mon Sep 17 00:00:00 2001 +From: Daan De Meyer +Date: Tue, 22 Oct 2024 12:32:02 +0200 +Subject: [PATCH 3/3] bus-util: Fix bus_log_connect_error() + +--- + src/shared/bus-util.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c +index fa4f879b7bac3..ce94597955aa3 100644 +--- a/src/shared/bus-util.c ++++ b/src/shared/bus-util.c +@@ -56,9 +56,9 @@ int bus_log_connect_error(int r, BusTransport transport, RuntimeScope scope) { + hint_addr = transport == BUS_TRANSPORT_LOCAL && ERRNO_IS_PRIVILEGE(r); + + return log_error_errno(r, +- 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=@.host --user to connect to bus of other user)" : +- r == hint_addr ? "Failed to connect to %s scope bus via %s transport: Operation not permitted (consider using --machine=@.host --user to connect to bus of other user)" : +- "Failed to connect to %s scope bus via %s transport: %m", runtime_scope_to_string(scope), bus_transport_to_string(transport)); ++ 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=@.host --user to connect to bus of other user)" : ++ hint_addr ? "Failed to connect to %s scope bus via %s transport: Operation not permitted (consider using --machine=@.host --user to connect to bus of other user)" : ++ "Failed to connect to %s scope bus via %s transport: %m", runtime_scope_to_string(scope), bus_transport_to_string(transport)); + } + + int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name) { diff --git a/systemd.spec b/systemd.spec index 28f2b20..bf7f84b 100644 --- a/systemd.spec +++ b/systemd.spec @@ -44,7 +44,7 @@ Url: https://systemd.io # Allow users to specify the version and release when building the rpm by # setting the %%version_override and %%release_override macros. Version: %{?version_override}%{!?version_override:256.7} -Release: %{?release_override}%{!?release_override:1.2}%{?dist} +Release: %{?release_override}%{!?release_override:1.3}%{?dist} %global stable %(c="%version"; [ "$c" = "${c#*.*}" ]; echo $?) @@ -145,6 +145,9 @@ Patch0902: https://github.com/systemd/systemd/pull/34400.patch # Fix error when upgrading from v255 Patch0903: 0001-keep-on-using-DBus-as-fallback-if-varlink-is-not-ava.patch +# bus-util: Return ENOMEDIUM if XDG_RUNTIME_DIR is unset +Patch0904: https://github.com/systemd/systemd/pull/34851.patch + %endif %ifarch %{ix86} x86_64 aarch64 riscv64