Merge ~sylvain-pineau/checkbox-ng:add-dbus-var-extra-env into checkbox-ng:master

Proposed by Sylvain Pineau
Status: Merged
Approved by: Sylvain Pineau
Approved revision: d10b634a0053d18ae8ab3a33bd219360df714c6c
Merged at revision: 7bdbaee6fe1b0532b36036623032df157cad462d
Proposed branch: ~sylvain-pineau/checkbox-ng:add-dbus-var-extra-env
Merge into: checkbox-ng:master
Diff against target: 71 lines (+17/-6)
1 file modified
plainbox/impl/session/remote_assistant.py (+17/-6)
Reviewer Review Type Date Requested Status
Jonathan Cave (community) Approve
Review via email: mp+392582@code.launchpad.net

Commit message

remote_assistant: Add existing dbus process env var to the target user execution env

DBUS_SESSION_BUS_ADDRESS, but also XDG_RUNTIME_DIR.

Description of the change

remote_assistant: Add existing dbus process env var to the target user execution env

DBUS_SESSION_BUS_ADDRESS, but also XDG_RUNTIME_DIR.

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :
Revision history for this message
Jonathan Cave (jocave) wrote :

Looks good to me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/plainbox/impl/session/remote_assistant.py b/plainbox/impl/session/remote_assistant.py
2index 9e726b5..cc32e60 100644
3--- a/plainbox/impl/session/remote_assistant.py
4+++ b/plainbox/impl/session/remote_assistant.py
5@@ -21,6 +21,7 @@ import json
6 import gettext
7 import logging
8 import os
9+import pwd
10 import time
11 from collections import namedtuple
12 from tempfile import SpooledTemporaryFile
13@@ -219,7 +220,14 @@ class RemoteSessionAssistant():
14 'strings /proc/*/environ 2>/dev/null | '
15 'grep -m 1 -oP "(?<=XAUTHORITY=).*"',
16 shell=True, universal_newlines=True).rstrip()
17- return {'DISPLAY': display_value, 'XAUTHORITY': xauth_value}
18+ uid = pwd.getpwnam(self._normal_user).pw_uid
19+ return {
20+ 'DISPLAY': display_value,
21+ 'XAUTHORITY': xauth_value,
22+ 'XDG_RUNTIME_DIR': '/run/user/{}'.format(uid),
23+ 'DBUS_SESSION_BUS_ADDRESS':
24+ 'unix:path=/run/user/{}/bus'.format(uid)
25+ }
26 except CalledProcessError:
27 return None
28
29@@ -244,9 +252,13 @@ class RemoteSessionAssistant():
30 "XAUTHORITY" in p_environ and
31 p_user != 'gdm'
32 ): # gdm uses :1024
33+ uid = pwd.getpwnam(self._normal_user).pw_uid
34 return {
35 'DISPLAY': p_environ['DISPLAY'],
36- 'XAUTHORITY': p_environ['XAUTHORITY']
37+ 'XAUTHORITY': p_environ['XAUTHORITY'],
38+ 'XDG_RUNTIME_DIR': '/run/user/{}'.format(uid),
39+ 'DBUS_SESSION_BUS_ADDRESS':
40+ 'unix:path=/run/user/{}/bus'.format(uid)
41 }
42
43 @allowed_when(Idle)
44@@ -272,16 +284,15 @@ class RemoteSessionAssistant():
45 else:
46 self._normal_user = self._launcher.normal_user
47 if not self._normal_user:
48- import pwd
49 try:
50 self._normal_user = pwd.getpwuid(1000).pw_name
51 _logger.warning(
52 ("normal_user not supplied via config(s). "
53- "non-root jobs will run as %s"), self._normal_user)
54+ "non-root jobs will run as %s"), self._normal_user)
55 except KeyError:
56 raise RuntimeError(
57 ("normal_user not supplied via config(s). "
58- "Username for uid 1000 not found"))
59+ "Username for uid 1000 not found"))
60 runner_kwargs = {
61 'normal_user_provider': lambda: self._normal_user,
62 'stdin': self._pipe_to_subproc,
63@@ -668,7 +679,7 @@ class RemoteSessionAssistant():
64 if result_dict.get('outcome') not in [
65 'pass', 'fail', 'skip']:
66 result_dict['outcome'] = IJobResult.OUTCOME_PASS
67- except json.JSONDecodeError as e:
68+ except json.JSONDecodeError:
69 pass
70 result = MemoryJobResult(result_dict)
71 if self._last_job:

Subscribers

People subscribed via source and target branches