From: Sotir Danailov Date: Wed, 8 Jan 2025 22:51:15 +0000 (+0100) Subject: dbus: replace hardcoded dbus address with environment variable X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F4511%2Fhead;p=thirdparty%2Flxc.git dbus: replace hardcoded dbus address with environment variable Signed-off-by: Sotir Danailov --- diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index b4ab0aa69..eea2b1f6d 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -1226,6 +1226,7 @@ static bool start_scope(DBusConnection *connection, const char *scope_name) static DBusConnection *open_systemd(void) { __do_free char *user_bus = NULL; + const char *env_dbus_addr = getenv("DBUS_SESSION_BUS_ADDRESS"); char *s = NULL; DBusMessageIter iter; DBusError dbus_error; @@ -1234,11 +1235,20 @@ static DBusConnection *open_systemd(void) DBusPendingCall* pending; dbus_error_init(&dbus_error); - user_bus = strdup("unix:path=/run/user/1000/bus"); // TODO get from $DBUS_SESSION_BUS_ADDRESS + + if (!env_dbus_addr) { + WARN("Environment variable 'DBUS_SESSION_BUS_ADDRESS' not set"); + user_bus = strdup("unix:path=/run/user/1000/bus"); + } else { + user_bus = strdup(env_dbus_addr); + } + if (!user_bus) { return log_error(NULL, "Failed opening user dbus"); } + TRACE("Using dbus unix socket: '%s'", user_bus); + connection = dbus_connection_open(user_bus, &dbus_error); if (!connection) { DEBUG("Failed opening dbus connection: %s: %s",