diff options
author | Michał Górny <mgorny@gentoo.org> | 2012-01-03 12:45:56 +0100 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2012-01-03 12:45:56 +0100 |
commit | 04f53d753978b0c1af8b88bbc6e1da169c7372b5 (patch) | |
tree | a9d426894213eaad56a68817e0b5ec6e83a2c4c6 | |
parent | Allow current user rather than explicit root. (diff) | |
download | pms-test-suite-04f53d753978b0c1af8b88bbc6e1da169c7372b5.tar.gz pms-test-suite-04f53d753978b0c1af8b88bbc6e1da169c7372b5.tar.bz2 pms-test-suite-04f53d753978b0c1af8b88bbc6e1da169c7372b5.zip |
Use subprocess to spawn D-Bus.
-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. """ |