From d58d65ebf0cbff15a30c9c89375b412e758bb043 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 3 Jun 2018 10:36:12 +0200 Subject: [PATCH] lib/dbus/Glue: use private connection Avoid interfering with libraries also using the shared connection. --- src/lib/dbus/Connection.cxx | 9 +++++++++ src/lib/dbus/Connection.hxx | 5 +++++ src/lib/dbus/Glue.cxx | 4 +++- 3 files changed, 17 insertions(+), 1 deletion(-) 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()); }