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
=== modified file 'apport/hookutils.py'
--- apport/hookutils.py 2021-03-24 15:06:11 +0000
+++ apport/hookutils.py 2021-04-07 10:22:32 +0000
@@ -22,6 +22,7 @@
22import stat22import stat
23import base6423import base64
24import tempfile24import tempfile
25import select
25import shutil26import shutil
26import locale27import locale
27import json28import json
@@ -32,6 +33,7 @@
32import apport.fileutils33import apport.fileutils
3334
34_invalid_key_chars_re = re.compile(r'[^0-9a-zA-Z_.-]')35_invalid_key_chars_re = re.compile(r'[^0-9a-zA-Z_.-]')
36_AGENT = None
3537
3638
37def path_to_key(path):39def path_to_key(path):
@@ -404,10 +406,57 @@
404 return res406 return res
405407
406408
409def _spawn_pkttyagent():
410 global _AGENT
411
412 if _AGENT is not None:
413 return
414 if os.geteuid() == 0:
415 return
416 if not sys.stdin.isatty():
417 return
418 if not os.path.exists('/usr/bin/pkttyagent'):
419 return
420
421 try:
422 (r, w) = os.pipe2(0)
423 except OSError:
424 return
425
426 _AGENT = subprocess.Popen(['pkttyagent', '--notify-fd', str(w), '--fallback'],
427 close_fds=False,
428 stdin=subprocess.PIPE,
429 stdout=subprocess.PIPE)
430
431 os.close(w)
432
433 with select.epoll() as epoll:
434 while True:
435 epoll.register(r, select.EPOLLIN)
436 events = epoll.poll()
437 for fd, event_type in events:
438 if event_type & select.EPOLLHUP:
439 os.close(r)
440 return
441 return
442
443
444def kill_pkttyagent():
445 global _AGENT
446
447 if _AGENT is None:
448 return
449
450 _AGENT.terminate()
451 _AGENT.wait()
452 _AGENT = None
453
454
407def _root_command_prefix():455def _root_command_prefix():
408 if os.getuid() == 0:456 if os.getuid() == 0:
409 return []457 return []
410 elif os.path.exists('/usr/bin/pkexec'):458 elif os.path.exists('/usr/bin/pkexec'):
459 _spawn_pkttyagent()
411 return ['pkexec']460 return ['pkexec']
412 # the package hook won't have everything it wanted but that's okay461 # the package hook won't have everything it wanted but that's okay
413 else:462 else:
@@ -425,8 +474,9 @@
425 otherwise left as bytes.474 otherwise left as bytes.
426 '''475 '''
427 assert isinstance(command, list), 'command must be a list'476 assert isinstance(command, list), 'command must be a list'
428 return command_output(_root_command_prefix() + command, input, stderr,477 output = command_output(_root_command_prefix() + command, input, stderr,
429 keep_locale=True, decode_utf8=decode_utf8)478 keep_locale=True, decode_utf8=decode_utf8)
479 return output
430480
431481
432def attach_root_command_outputs(report, command_map):482def attach_root_command_outputs(report, command_map):
433483
=== modified file 'apport/report.py'
--- apport/report.py 2020-12-02 22:34:56 +0000
+++ apport/report.py 2021-04-07 10:22:32 +0000
@@ -31,6 +31,7 @@
31import apport31import apport
32import apport.fileutils32import apport.fileutils
33from apport.packaging_impl import impl as packaging33from apport.packaging_impl import impl as packaging
34from apport.hookutils import kill_pkttyagent
3435
35_data_dir = os.environ.get('APPORT_DATA_DIR', '/usr/share/apport')36_data_dir = os.environ.get('APPORT_DATA_DIR', '/usr/share/apport')
36_hook_dir = '%s/package-hooks/' % (_data_dir)37_hook_dir = '%s/package-hooks/' % (_data_dir)
@@ -930,6 +931,11 @@
930 return True if the hook requested to stop the report filing process,931 return True if the hook requested to stop the report filing process,
931 False otherwise.932 False otherwise.
932 '''933 '''
934 ret = self._add_hooks_info(ui, package, srcpackage)
935 kill_pkttyagent()
936 return ret
937
938 def _add_hooks_info(self, ui, package, srcpackage):
933 # determine package names, unless already given as arguments939 # determine package names, unless already given as arguments
934 # avoid path traversal940 # avoid path traversal
935 if not package:941 if not package:

Subscribers

People subscribed via source and target branches