50
51
def __init__(self, testing_mode='live'):
51
52
self._stack = ExitStack()
52
53
self.tmpdir = self._stack.enter_context(temporary_directory())
53
self.config_path = os.path.join(self.tmpdir, 'dbus-session.conf')
54
self.config_path = os.path.join(self.tmpdir, 'dbus-system.conf')
54
55
self.ini_path = None
55
56
self.serverdir = self._stack.enter_context(temporary_directory())
56
57
self._testing_mode = testing_mode
59
# Set up the dbus-daemon session configuration file.
60
with open(test_data_path('dbus-session.conf.in'),
60
# Set up the dbus-daemon system configuration file.
61
with open(test_data_path('dbus-system.conf.in'),
61
62
'r', encoding='utf-8') as fp:
62
63
template = fp.read()
63
config = template.format(tmpdir=self.tmpdir)
64
username = pwd.getpwuid(os.getuid()).pw_name
65
config = template.format(tmpdir=self.tmpdir, user=username)
64
66
with open(self.config_path, 'w', encoding='utf-8') as fp:
68
with open('/tmp/debug.log', 'a', encoding='utf-8') as fp:
66
70
# We need a client.ini file for the subprocess.
67
71
ini_tmpdir = self._stack.enter_context(temporary_directory())
68
72
ini_vardir = self._stack.enter_context(temporary_directory())
119
123
dbus_address = lines[0].strip()
120
124
daemon_pid = int(lines[1].strip())
121
125
self._stack.callback(self._kill, daemon_pid)
122
#print('DBUS_SESSION_BUS_ADDRESS={}'.format(dbus_address))
126
#print("DBUS_SYSTEM_BUS_ADDRESS='{}'".format(dbus_address))
123
127
# Set the service's address into the environment for rendezvous.
124
self._stack.enter_context(reset_envar('DBUS_SESSION_BUS_ADDRESS'))
125
os.environ['DBUS_SESSION_BUS_ADDRESS'] = dbus_address
128
self._stack.enter_context(reset_envar('DBUS_SYSTEM_BUS_ADDRESS'))
129
os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = dbus_address
134
138
def _kill(self, pid):
135
with open('/tmp/debug.log', 'a', encoding='utf-8') as fp:
136
print('FORCE', pid, file=fp)
137
139
os.kill(pid, signal.SIGTERM)
138
140
# Wait for it to die.
139
141
until = datetime.datetime.now() + datetime.timedelta(seconds=10)
144
146
except ProcessLookupError:
146
with open('/tmp/debug.log', 'a', encoding='utf-8') as fp:
147
print('GONE', pid, file=fp)
149
149
def shutdown(self):
150
150
self._stack.close()