1 |
commit: 7e5c58594f88551c0727647faa7ea85fed6bf205 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Jan 3 11:31:54 2012 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jan 3 11:31:54 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=7e5c5859 |
7 |
|
8 |
Generate D-Bus configuration file in runtime. |
9 |
|
10 |
--- |
11 |
bus.conf | 18 ------------------ |
12 |
pmstestsuite/dbus_handler.py | 28 ++++++++++++++++++++++++++-- |
13 |
2 files changed, 26 insertions(+), 20 deletions(-) |
14 |
|
15 |
diff --git a/bus.conf b/bus.conf |
16 |
deleted file mode 100644 |
17 |
index a078c1c..0000000 |
18 |
--- a/bus.conf |
19 |
+++ /dev/null |
20 |
@@ -1,18 +0,0 @@ |
21 |
-<?xml version="1.0"?> |
22 |
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" |
23 |
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> |
24 |
- |
25 |
-<busconfig> |
26 |
- <type>session</type> |
27 |
- <listen>unix:tmpdir=/tmp</listen> |
28 |
- |
29 |
- <user>portage</user> <!-- XXX --> |
30 |
- |
31 |
- <policy context="default"> |
32 |
- <allow user="root"/> |
33 |
- |
34 |
- <allow send_destination="*" eavesdrop="true"/> |
35 |
- <allow eavesdrop="true"/> |
36 |
- <allow own="*"/> |
37 |
- </policy> |
38 |
-</busconfig> |
39 |
|
40 |
diff --git a/pmstestsuite/dbus_handler.py b/pmstestsuite/dbus_handler.py |
41 |
index 9a8c529..456e63d 100644 |
42 |
--- a/pmstestsuite/dbus_handler.py |
43 |
+++ b/pmstestsuite/dbus_handler.py |
44 |
@@ -2,27 +2,51 @@ |
45 |
# (c) 2011-2012 Michał Górny <mgorny@g.o> |
46 |
# Released under the terms of the 2-clause BSD license. |
47 |
|
48 |
-import dbus, os, signal |
49 |
+import dbus, os, signal, tempfile |
50 |
from dbus.mainloop.glib import DBusGMainLoop |
51 |
|
52 |
dbus_interface_name = 'org.gentoo.pmstestsuite' |
53 |
dbus_bus_name = dbus_interface_name |
54 |
dbus_object_prefix = '/org/gentoo/pmstestsuite' |
55 |
|
56 |
+dbus_config = """<?xml version="1.0"?> |
57 |
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" |
58 |
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> |
59 |
+ |
60 |
+<busconfig> |
61 |
+ <type>session</type> |
62 |
+ <listen>unix:tmpdir=/tmp</listen> |
63 |
+ |
64 |
+ <user>%s</user> |
65 |
+ |
66 |
+ <policy context="default"> |
67 |
+ <allow user="root"/> |
68 |
+ |
69 |
+ <allow send_destination="*" eavesdrop="true"/> |
70 |
+ <allow eavesdrop="true"/> |
71 |
+ <allow own="*"/> |
72 |
+ </policy> |
73 |
+</busconfig>""" |
74 |
+ |
75 |
class DBusHandler(object): |
76 |
""" A class handling all D-Bus interaction for PMS Test Suite. """ |
77 |
|
78 |
def start_dbus(self, uid): |
79 |
+ tmpf = tempfile.NamedTemporaryFile('w') |
80 |
+ tmpf.write(dbus_config % uid) |
81 |
+ tmpf.flush() |
82 |
+ |
83 |
(read_fd, write_fd) = os.pipe() |
84 |
self.dbus_pid = os.fork() |
85 |
if self.dbus_pid == 0: |
86 |
os.close(read_fd) |
87 |
os.execlp('dbus-daemon', 'dbus-daemon', '--nofork', |
88 |
- '--config-file=bus.conf', # XXX: path |
89 |
+ '--config-file=%s' % tmpf.name, |
90 |
'--print-address=%d' % write_fd) |
91 |
else: |
92 |
addr = os.read(read_fd, 1024) |
93 |
os.close(write_fd) |
94 |
+ tmpf.close() |
95 |
|
96 |
self.bus_address = addr.strip() |