diff --git a/src/lib/dbus/Connection.cxx b/src/lib/dbus/Connection.cxx index 8564dfec8..cb5e9de24 100644 --- a/src/lib/dbus/Connection.cxx +++ b/src/lib/dbus/Connection.cxx @@ -42,6 +42,15 @@ ODBus::Connection::GetSystem() return Connection(c); } +ODBus::Connection +ODBus::Connection::GetSystemPrivate() +{ + ODBus::Error error; + auto *c = dbus_bus_get_private(DBUS_BUS_SYSTEM, error); + error.CheckThrow("DBus connection error"); + return Connection(c); +} + ODBus::Connection ODBus::Connection::Open(const char *address) { diff --git a/src/lib/dbus/Connection.hxx b/src/lib/dbus/Connection.hxx index 8ebb6e84d..43347070d 100644 --- a/src/lib/dbus/Connection.hxx +++ b/src/lib/dbus/Connection.hxx @@ -69,6 +69,7 @@ public: } static Connection GetSystem(); + static Connection GetSystemPrivate(); static Connection Open(const char *address); operator DBusConnection *() noexcept { @@ -78,6 +79,10 @@ public: operator bool() const noexcept { return c != nullptr; } + + void Close() noexcept { + dbus_connection_close(c); + } }; } /* namespace ODBus */ diff --git a/src/lib/dbus/Glue.cxx b/src/lib/dbus/Glue.cxx index 8e8d25893..07e264e27 100644 --- a/src/lib/dbus/Glue.cxx +++ b/src/lib/dbus/Glue.cxx @@ -25,7 +25,7 @@ namespace ODBus { void Glue::Connect() { - watch.SetConnection(Connection::GetSystem()); + watch.SetConnection(Connection::GetSystemPrivate()); dbus_connection_set_exit_on_disconnect(GetConnection(), false); } @@ -33,6 +33,8 @@ Glue::Connect() void Glue::Disconnect() { + GetConnection().Close(); + watch.SetConnection(Connection()); }