Merge lp:~kissiel/checkbox/fix-1569575-root-leftovers-crash into lp:checkbox

Proposed by Maciej Kisielewski
Status: Merged
Approved by: Maciej Kisielewski
Approved revision: 4316
Merged at revision: 4324
Proposed branch: lp:~kissiel/checkbox/fix-1569575-root-leftovers-crash
Merge into: lp:checkbox
Diff against target: 33 lines (+14/-9)
1 file modified
plainbox/plainbox/impl/ctrl.py (+14/-9)
To merge this branch: bzr merge lp:~kissiel/checkbox/fix-1569575-root-leftovers-crash
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+293041@code.launchpad.net

Description of the change

This patch handles PermissionError exceptions coming from TemporaryDirectory.

Consider a job, that is run as root that runs cp somedir .

When the temp cwd context manager is left, the cleanup is run as the user
running plainbox, not root. This caused plainbox to crashed.

This patch makes plainbox display a warning and proceed.

9ca20ea plainbox:ctrl: catch tempcwd errors and print warning

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

I'm ok with the patch, doing the cleanup as root from python is 1. not easy and 2. if it was possible from plainbox it would open the door to all sort of arbitrary commands being run as root. So +1 to log a warning and proceed. thanks

review: Approve
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

\o/ Let's land it then.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plainbox/plainbox/impl/ctrl.py'
2--- plainbox/plainbox/impl/ctrl.py 2015-09-25 08:39:43 +0000
3+++ plainbox/plainbox/impl/ctrl.py 2016-04-27 04:01:05 +0000
4@@ -606,15 +606,20 @@
5 # Create a nest for all the private executables needed for execution
6 prefix = 'cwd-'
7 suffix = '.{}'.format(job.checksum)
8- with tempfile.TemporaryDirectory(suffix, prefix) as cwd_dir:
9- logger.debug(
10- _("Job temporary current working directory: %s"), cwd_dir)
11- try:
12- yield cwd_dir
13- finally:
14- leftovers = self._find_leftovers(cwd_dir)
15- if leftovers:
16- self.on_leftover_files(job, config, cwd_dir, leftovers)
17+ try:
18+ with tempfile.TemporaryDirectory(suffix, prefix) as cwd_dir:
19+ logger.debug(
20+ _("Job temporary current working directory: %s"), cwd_dir)
21+ try:
22+ yield cwd_dir
23+ finally:
24+ leftovers = self._find_leftovers(cwd_dir)
25+ if leftovers:
26+ self.on_leftover_files(job, config, cwd_dir, leftovers)
27+ except PermissionError as exc:
28+ logger.warning(
29+ _("There was a problem with temporary cwd %s, %s"),
30+ cwd_dir, exc)
31
32 def _find_leftovers(self, cwd_dir):
33 """

Subscribers

People subscribed via source and target branches