diff --git a/src/hal.c b/src/hal.c index e75ed2a..4c34a0a 100644 --- a/src/hal.c +++ b/src/hal.c @@ -17,6 +17,8 @@ #include #include +#include +#include #include #include #include "log.h" @@ -25,14 +27,26 @@ DBusConnection *pusb_hal_dbus_connect(void) { DBusConnection *dbus = NULL; DBusError error; + uid_t real_uid; dbus_error_init(&error); if (!(dbus = dbus_bus_get(DBUS_BUS_SYSTEM, &error))) { - log_error("Cannot connect to system bus: %s\n", - error.message); - dbus_error_free(&error); - return (NULL); + /* Workaround for https://bugs.freedesktop.org/show_bug.cgi?id=11876 */ + if (!geteuid() && (real_uid = getuid())) + { + dbus_error_free(&error); + setuid(geteuid()); + dbus = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + setuid(real_uid); + } + if (!dbus) + { + log_error("Cannot connect to system bus: %s\n", + error.message); + dbus_error_free(&error); + return (NULL); + } } return (dbus); }