Merge lp:~laney/apport/pkttyagent into lp:~ubuntu-core-dev/ubuntu/hirsute/apport/ubuntu

Proposed by Iain Lane
Status: Merged
Merged at revision: 2851
Proposed branch: lp:~laney/apport/pkttyagent
Merge into: lp:~ubuntu-core-dev/ubuntu/hirsute/apport/ubuntu
Diff against target: 113 lines (+58/-2)
2 files modified
apport/hookutils.py (+52/-2)
apport/report.py (+6/-0)
To merge this branch: bzr merge lp:~laney/apport/pkttyagent
Reviewer Review Type Date Requested Status
Brian Murray Pending
Ubuntu Core Development Team Pending
Review via email: mp+400664@code.launchpad.net

Description of the change

There are two annoying things with this branch that I'd appreciate some help with.

  1) Some dots '.' appear over the prompt. They should be paused while the command is being executed I think.
  2) You get prompted multiple times for your passphrase if there are multiple root commands. I've not verified this but I think probably killing *once* at the end of apport, and not spawning a fresh agent each time, would maybe fix this.

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

Regarding the dots appearing over the prompt, this has happened for as long as I can remember.

Revision history for this message
Brian Murray (brian-murray) wrote :

I think calling _kill_pttyagent() after calling report.add_hooks_info() would accomplish issue #2.

lp:~laney/apport/pkttyagent updated
2852. By Iain Lane

Move pkttyagent killing to add_hooks_info()

This ensures we only kill the agent after all the hooks have been run.

Revision history for this message
Iain Lane (laney) wrote :

Cheers. I did your suggestion but it doesn't fix it. After some further reading it's because we don't allow "auth_admin_keep" for pkexec. I think that's deliberate - or at least should be fixed outside of apport - and this MP lets the information be collected at least.

I think the new method is better though as we avoid spawning it multiple times, which is still nice.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'apport/hookutils.py'
2--- apport/hookutils.py 2021-03-24 15:06:11 +0000
3+++ apport/hookutils.py 2021-04-07 10:22:32 +0000
4@@ -22,6 +22,7 @@
5 import stat
6 import base64
7 import tempfile
8+import select
9 import shutil
10 import locale
11 import json
12@@ -32,6 +33,7 @@
13 import apport.fileutils
14
15 _invalid_key_chars_re = re.compile(r'[^0-9a-zA-Z_.-]')
16+_AGENT = None
17
18
19 def path_to_key(path):
20@@ -404,10 +406,57 @@
21 return res
22
23
24+def _spawn_pkttyagent():
25+ global _AGENT
26+
27+ if _AGENT is not None:
28+ return
29+ if os.geteuid() == 0:
30+ return
31+ if not sys.stdin.isatty():
32+ return
33+ if not os.path.exists('/usr/bin/pkttyagent'):
34+ return
35+
36+ try:
37+ (r, w) = os.pipe2(0)
38+ except OSError:
39+ return
40+
41+ _AGENT = subprocess.Popen(['pkttyagent', '--notify-fd', str(w), '--fallback'],
42+ close_fds=False,
43+ stdin=subprocess.PIPE,
44+ stdout=subprocess.PIPE)
45+
46+ os.close(w)
47+
48+ with select.epoll() as epoll:
49+ while True:
50+ epoll.register(r, select.EPOLLIN)
51+ events = epoll.poll()
52+ for fd, event_type in events:
53+ if event_type & select.EPOLLHUP:
54+ os.close(r)
55+ return
56+ return
57+
58+
59+def kill_pkttyagent():
60+ global _AGENT
61+
62+ if _AGENT is None:
63+ return
64+
65+ _AGENT.terminate()
66+ _AGENT.wait()
67+ _AGENT = None
68+
69+
70 def _root_command_prefix():
71 if os.getuid() == 0:
72 return []
73 elif os.path.exists('/usr/bin/pkexec'):
74+ _spawn_pkttyagent()
75 return ['pkexec']
76 # the package hook won't have everything it wanted but that's okay
77 else:
78@@ -425,8 +474,9 @@
79 otherwise left as bytes.
80 '''
81 assert isinstance(command, list), 'command must be a list'
82- return command_output(_root_command_prefix() + command, input, stderr,
83- keep_locale=True, decode_utf8=decode_utf8)
84+ output = command_output(_root_command_prefix() + command, input, stderr,
85+ keep_locale=True, decode_utf8=decode_utf8)
86+ return output
87
88
89 def attach_root_command_outputs(report, command_map):
90
91=== modified file 'apport/report.py'
92--- apport/report.py 2020-12-02 22:34:56 +0000
93+++ apport/report.py 2021-04-07 10:22:32 +0000
94@@ -31,6 +31,7 @@
95 import apport
96 import apport.fileutils
97 from apport.packaging_impl import impl as packaging
98+from apport.hookutils import kill_pkttyagent
99
100 _data_dir = os.environ.get('APPORT_DATA_DIR', '/usr/share/apport')
101 _hook_dir = '%s/package-hooks/' % (_data_dir)
102@@ -930,6 +931,11 @@
103 return True if the hook requested to stop the report filing process,
104 False otherwise.
105 '''
106+ ret = self._add_hooks_info(ui, package, srcpackage)
107+ kill_pkttyagent()
108+ return ret
109+
110+ def _add_hooks_info(self, ui, package, srcpackage):
111 # determine package names, unless already given as arguments
112 # avoid path traversal
113 if not package:

Subscribers

People subscribed via source and target branches