diff options
author | Michał Górny <mgorny@gentoo.org> | 2012-01-03 12:31:54 +0100 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2012-01-03 12:31:54 +0100 |
commit | 7e5c58594f88551c0727647faa7ea85fed6bf205 (patch) | |
tree | b7e16731be1bc0c07e412b2841681bf477249561 /pmstestsuite | |
parent | Support running local D-Bus bus. (diff) | |
download | pms-test-suite-7e5c58594f88551c0727647faa7ea85fed6bf205.tar.gz pms-test-suite-7e5c58594f88551c0727647faa7ea85fed6bf205.tar.bz2 pms-test-suite-7e5c58594f88551c0727647faa7ea85fed6bf205.zip |
Generate D-Bus configuration file in runtime.
Diffstat (limited to 'pmstestsuite')
-rw-r--r-- | pmstestsuite/dbus_handler.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/pmstestsuite/dbus_handler.py b/pmstestsuite/dbus_handler.py index 9a8c529..456e63d 100644 --- a/pmstestsuite/dbus_handler.py +++ b/pmstestsuite/dbus_handler.py @@ -2,27 +2,51 @@ # (c) 2011-2012 Michał Górny <mgorny@gentoo.org> # Released under the terms of the 2-clause BSD license. -import dbus, os, signal +import dbus, os, signal, tempfile from dbus.mainloop.glib import DBusGMainLoop dbus_interface_name = 'org.gentoo.pmstestsuite' dbus_bus_name = dbus_interface_name dbus_object_prefix = '/org/gentoo/pmstestsuite' +dbus_config = """<?xml version="1.0"?> +<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> + +<busconfig> + <type>session</type> + <listen>unix:tmpdir=/tmp</listen> + + <user>%s</user> + + <policy context="default"> + <allow user="root"/> + + <allow send_destination="*" eavesdrop="true"/> + <allow eavesdrop="true"/> + <allow own="*"/> + </policy> +</busconfig>""" + class DBusHandler(object): """ A class handling all D-Bus interaction for PMS Test Suite. """ def start_dbus(self, uid): + tmpf = tempfile.NamedTemporaryFile('w') + tmpf.write(dbus_config % uid) + 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=bus.conf', # XXX: path + '--config-file=%s' % tmpf.name, '--print-address=%d' % write_fd) else: addr = os.read(read_fd, 1024) os.close(write_fd) + tmpf.close() self.bus_address = addr.strip() |