Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/_emerge/
Date: Tue, 07 Feb 2012 23:04:37
Message-Id: 445a6ea22c132f4c06c2cc7c48ec6e7af7116962.zmedico@gentoo
1 commit: 445a6ea22c132f4c06c2cc7c48ec6e7af7116962
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Tue Feb 7 02:58:51 2012 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Tue Feb 7 19:12:32 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=445a6ea2
7
8 Use timeout_add to avoid recursion, bug #402335.
9
10 ---
11 pym/_emerge/AbstractEbuildProcess.py | 37 ++++++++++++++++++++++++++-------
12 pym/_emerge/SubProcess.py | 6 ++++-
13 2 files changed, 34 insertions(+), 9 deletions(-)
14
15 diff --git a/pym/_emerge/AbstractEbuildProcess.py b/pym/_emerge/AbstractEbuildProcess.py
16 index 63368d4..5742cb2 100644
17 --- a/pym/_emerge/AbstractEbuildProcess.py
18 +++ b/pym/_emerge/AbstractEbuildProcess.py
19 @@ -19,7 +19,7 @@ from portage.util import apply_secpass_permissions
20 class AbstractEbuildProcess(SpawnProcess):
21
22 __slots__ = ('phase', 'settings',) + \
23 - ('_build_dir', '_ipc_daemon', '_exit_command',)
24 + ('_build_dir', '_ipc_daemon', '_exit_command', '_exit_timeout_id')
25 _phases_without_builddir = ('clean', 'cleanrm', 'depend', 'help',)
26 _phases_interactive_whitelist = ('config',)
27
28 @@ -157,13 +157,30 @@ class AbstractEbuildProcess(SpawnProcess):
29 def _exit_command_callback(self):
30 if self._registered:
31 # Let the process exit naturally, if possible.
32 - self.scheduler.schedule(self._reg_id, timeout=self._exit_timeout)
33 - if self._registered:
34 - # If it doesn't exit naturally in a reasonable amount
35 - # of time, kill it (solves bug #278895). We try to avoid
36 - # this when possible since it makes sandbox complain about
37 - # being killed by a signal.
38 - self.cancel()
39 + self._exit_timeout_id = \
40 + self.scheduler.timeout_add(self._exit_timeout,
41 + self._exit_command_timeout_cb)
42 +
43 + def _exit_command_timeout_cb(self):
44 + if self._registered:
45 + # If it doesn't exit naturally in a reasonable amount
46 + # of time, kill it (solves bug #278895). We try to avoid
47 + # this when possible since it makes sandbox complain about
48 + # being killed by a signal.
49 + self.cancelled = True
50 + self._cancel()
51 + self._exit_timeout_id = \
52 + self.scheduler.timeout_add(self._cancel_timeout,
53 + self._cancel_timeout_cb)
54 + else:
55 + self._exit_timeout_id = None
56 +
57 + return False # only run once
58 +
59 + def _cancel_timeout_cb(self):
60 + self._exit_timeout_id = None
61 + self.wait()
62 + return False # only run once
63
64 def _orphan_process_warn(self):
65 phase = self.phase
66 @@ -253,6 +270,10 @@ class AbstractEbuildProcess(SpawnProcess):
67 def _set_returncode(self, wait_retval):
68 SpawnProcess._set_returncode(self, wait_retval)
69
70 + if self._exit_timeout_id is not None:
71 + self.scheduler.source_remove(self._exit_timeout_id)
72 + self._exit_timeout_id = None
73 +
74 if self._ipc_daemon is not None:
75 self._ipc_daemon.cancel()
76 if self._exit_command.exitcode is not None:
77
78 diff --git a/pym/_emerge/SubProcess.py b/pym/_emerge/SubProcess.py
79 index 37922dc..c5cac7d 100644
80 --- a/pym/_emerge/SubProcess.py
81 +++ b/pym/_emerge/SubProcess.py
82 @@ -16,6 +16,10 @@ class SubProcess(AbstractPollTask):
83 # serve this purpose alone.
84 _dummy_pipe_fd = 9
85
86 + # This is how much time we allow for waitpid to succeed after
87 + # we've sent a kill signal to our subprocess.
88 + _cancel_timeout = 1000 # 1 second
89 +
90 def _poll(self):
91 if self.returncode is not None:
92 return self.returncode
93 @@ -60,7 +64,7 @@ class SubProcess(AbstractPollTask):
94
95 if self._registered:
96 if self.cancelled:
97 - timeout = 1000
98 + timeout = self._cancel_timeout
99 self.scheduler.schedule(self._reg_id, timeout=timeout)
100 if self._registered:
101 try: