diff options
-rw-r--r-- | pmstestsuite/dbus_handler.py | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/pmstestsuite/dbus_handler.py b/pmstestsuite/dbus_handler.py index 694ed84..78abe43 100644 --- a/pmstestsuite/dbus_handler.py +++ b/pmstestsuite/dbus_handler.py @@ -2,7 +2,7 @@ # (c) 2011-2012 Michał Górny <mgorny@gentoo.org> # Released under the terms of the 2-clause BSD license. -import dbus, os, signal, tempfile +import dbus, os, signal, subprocess, tempfile from dbus.mainloop.glib import DBusGMainLoop dbus_interface_name = 'org.gentoo.pmstestsuite' @@ -36,22 +36,17 @@ class DBusHandler(object): tmpf.write(dbus_config % (uid, os.getuid())) tmpf.flush() - (read_fd, write_fd) = os.pipe() - self.dbus_pid = os.fork() - if self.dbus_pid == 0: - os.close(read_fd) - os.execlp('dbus-daemon', 'dbus-daemon', '--nofork', - '--config-file=%s' % tmpf.name, - '--print-address=%d' % write_fd) - else: - addr = os.read(read_fd, 1024) - os.close(write_fd) - tmpf.close() + self.subp = subprocess.Popen(['dbus-daemon', '--nofork', + '--config-file=%s' % tmpf.name, '--print-address'], + stdout = subprocess.PIPE, close_fds = True) - self.bus_address = addr.strip() + addr = self.subp.stdout.readline() + tmpf.close() + + self.bus_address = addr.strip() def terminate(self): - os.kill(self.dbus_pid, signal.SIGTERM) + self.subp.terminate() def __init__(self, uid): """ Initialize DBusHandler. Add it to main GLib loop. """ |