Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/pms-test-suite:master commit in: pmstestsuite/
Date: Tue, 03 Jan 2012 15:52:46
Message-Id: 04f53d753978b0c1af8b88bbc6e1da169c7372b5.mgorny@gentoo
1 commit: 04f53d753978b0c1af8b88bbc6e1da169c7372b5
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Tue Jan 3 11:45:56 2012 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Tue Jan 3 11:45:56 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=04f53d75
7
8 Use subprocess to spawn D-Bus.
9
10 ---
11 pmstestsuite/dbus_handler.py | 23 +++++++++--------------
12 1 files changed, 9 insertions(+), 14 deletions(-)
13
14 diff --git a/pmstestsuite/dbus_handler.py b/pmstestsuite/dbus_handler.py
15 index 694ed84..78abe43 100644
16 --- a/pmstestsuite/dbus_handler.py
17 +++ b/pmstestsuite/dbus_handler.py
18 @@ -2,7 +2,7 @@
19 # (c) 2011-2012 Michał Górny <mgorny@g.o>
20 # Released under the terms of the 2-clause BSD license.
21
22 -import dbus, os, signal, tempfile
23 +import dbus, os, signal, subprocess, tempfile
24 from dbus.mainloop.glib import DBusGMainLoop
25
26 dbus_interface_name = 'org.gentoo.pmstestsuite'
27 @@ -36,22 +36,17 @@ class DBusHandler(object):
28 tmpf.write(dbus_config % (uid, os.getuid()))
29 tmpf.flush()
30
31 - (read_fd, write_fd) = os.pipe()
32 - self.dbus_pid = os.fork()
33 - if self.dbus_pid == 0:
34 - os.close(read_fd)
35 - os.execlp('dbus-daemon', 'dbus-daemon', '--nofork',
36 - '--config-file=%s' % tmpf.name,
37 - '--print-address=%d' % write_fd)
38 - else:
39 - addr = os.read(read_fd, 1024)
40 - os.close(write_fd)
41 - tmpf.close()
42 + self.subp = subprocess.Popen(['dbus-daemon', '--nofork',
43 + '--config-file=%s' % tmpf.name, '--print-address'],
44 + stdout = subprocess.PIPE, close_fds = True)
45
46 - self.bus_address = addr.strip()
47 + addr = self.subp.stdout.readline()
48 + tmpf.close()
49 +
50 + self.bus_address = addr.strip()
51
52 def terminate(self):
53 - os.kill(self.dbus_pid, signal.SIGTERM)
54 + self.subp.terminate()
55
56 def __init__(self, uid):
57 """ Initialize DBusHandler. Add it to main GLib loop. """