From 0724e37e3cba290ad0529b3ffc178bce7e5f929e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 23 Jul 2015 07:31:48 +0200 Subject: [PATCH] Use DBUS instead of pid file to prevent multiple simultaneous instances The pid file solution was racy. Since we register DBUS name anyway, we can use it for this purpose. --- qubesmanager/main.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/qubesmanager/main.py b/qubesmanager/main.py index 864c784..81b34e4 100755 --- a/qubesmanager/main.py +++ b/qubesmanager/main.py @@ -2002,23 +2002,15 @@ def sighup_handler(signum, frame): def main(): - # Avoid starting more than one instance of the app - lock = QubesDaemonPidfile("qubes-manager") - if lock.pidfile_exists(): - if lock.read_pid() == os.getpid(): - pass - elif lock.pidfile_is_stale(): - lock.remove_pidfile() - print "Removed stale pidfile " \ - "(has the previous daemon instance crashed?)." - else: - show_running_manager_via_dbus() - exit(0) - - lock.create_pidfile() - signal.signal(signal.SIGHUP, sighup_handler) + global system_bus + system_bus = QDBusConnection.systemBus() + # Avoid starting more than one instance of the app + if not system_bus.registerService('org.qubesos.QubesManager'): + show_running_manager_via_dbus() + return + global qubes_host qubes_host = QubesHost() @@ -2065,9 +2057,6 @@ def main(): wm.add_watch(os.path.dirname(table_widgets.qubes_dom0_updates_stat_file), EventsCodes.OP_FLAGS.get('IN_CREATE')) - global system_bus - system_bus = QDBusConnection.systemBus() - system_bus.registerService('org.qubesos.QubesManager') system_bus.registerObject(dbus_object_path, manager_window) trayIcon.show() @@ -2075,7 +2064,6 @@ def main(): show_manager() app.exec_() - lock.remove_pidfile() trayIcon = None