From e937650ccd4eec25035dcf5ddb52a23b49140063 Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Thu, 24 Nov 2016 16:25:31 +0100 Subject: [PATCH] atomic_dbus: keep the name until the process exits The call dbus.service.BusName() claims the name while the returned object is alive. It wasn't stored into a variable, so the name was released immediately, but the service keeps running (potentially indefinitely) with no use. Fix this by calling request_name() directly, so that we can give useful feedback (and end the process) when the name is already owned by another process. Fixes #763 Closes: #770 Approved by: cgwalters --- atomic_dbus.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/atomic_dbus.py b/atomic_dbus.py index 59e3b11..e43da01 100755 --- a/atomic_dbus.py +++ b/atomic_dbus.py @@ -29,6 +29,8 @@ from Atomic.trust import Trust from Atomic.uninstall import Uninstall from Atomic.verify import Verify +DBUS_NAME_FLAG_DO_NOT_QUEUE = 4 +DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER = 1 class atomic_dbus(slip.dbus.service.Object): default_polkit_auth_required = "org.atomic.readwrite" @@ -570,7 +572,10 @@ if __name__ == "__main__": mainloop = GObject.MainLoop() dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) system_bus = dbus.SystemBus() - busname = dbus.service.BusName("org.atomic", system_bus) - atomic_object = atomic_dbus(system_bus, "/org/atomic/object") - slip.dbus.service.set_mainloop(mainloop) - mainloop.run() + + if (system_bus.request_name("org.atomic", DBUS_NAME_FLAG_DO_NOT_QUEUE) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER): + atomic_object = atomic_dbus(system_bus, "/org/atomic/object") + slip.dbus.service.set_mainloop(mainloop) + mainloop.run() + else: + print("Another process owns the 'org.atomic' D-Bus name. Exiting.")