From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 301491384B4 for ; Mon, 23 Nov 2015 16:31:32 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0308E21C0CC; Mon, 23 Nov 2015 16:31:29 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 830EE21C0CC for ; Mon, 23 Nov 2015 16:31:28 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 38DC7340666 for ; Mon, 23 Nov 2015 16:31:27 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 5ED76A7F for ; Mon, 23 Nov 2015 16:31:23 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1448296135.007236f06506744fdb67910af5d7fb69783dbfe1.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/_emerge/ X-VCS-Repository: proj/portage X-VCS-Files: pym/_emerge/SpawnProcess.py X-VCS-Directories: pym/_emerge/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 007236f06506744fdb67910af5d7fb69783dbfe1 X-VCS-Branch: master Date: Mon, 23 Nov 2015 16:31:23 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 59461151-0707-476b-812a-c1051fbd6baf X-Archives-Hash: 93c59f4cb22635c4efcbe7d2ad15de8a commit: 007236f06506744fdb67910af5d7fb69783dbfe1 Author: Zac Medico gentoo org> AuthorDate: Sat Nov 21 19:41:07 2015 +0000 Commit: Zac Medico gentoo org> CommitDate: Mon Nov 23 16:28:55 2015 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=007236f0 SpawnProcess: re-check cgroup.procs until empty (bug 566420) For subshell die support (bug 465008), re-check cgroup.procs until it's empty, in case any of the listed processes fork before we've had a chance to kill them. X-Gentoo-Bug: 566420 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=566420 Acked-by: Alexander Berntsen gentoo.org> pym/_emerge/SpawnProcess.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/pym/_emerge/SpawnProcess.py b/pym/_emerge/SpawnProcess.py index b4b4b5b..e046640 100644 --- a/pym/_emerge/SpawnProcess.py +++ b/pym/_emerge/SpawnProcess.py @@ -16,6 +16,8 @@ from _emerge.SubProcess import SubProcess import portage from portage import os from portage.const import BASH_BINARY +from portage.localization import _ +from portage.output import EOutput from portage.util import writemsg_level from portage.util._async.PipeLogger import PipeLogger @@ -35,6 +37,10 @@ class SpawnProcess(SubProcess): __slots__ = ("args",) + \ _spawn_kwarg_names + ("_pipe_logger", "_selinux_type",) + # Max number of attempts to kill the processes listed in cgroup.procs, + # given that processes may fork before they can be killed. + _CGROUP_CLEANUP_RETRY_MAX = 8 + def _start(self): if self.fd_pipes is None: @@ -209,10 +215,24 @@ class SpawnProcess(SubProcess): elif e.errno != errno.ESRCH: raise - # step 1: kill all orphans - pids = get_pids(self.cgroup) + # step 1: kill all orphans (loop in case of new forks) + remaining = self._CGROUP_CLEANUP_RETRY_MAX + while remaining: + remaining -= 1 + pids = get_pids(self.cgroup) + if pids: + kill_all(pids, signal.SIGKILL) + else: + break + if pids: - kill_all(pids, signal.SIGKILL) + msg = [] + msg.append( + _("Failed to kill pid(s) in '%(cgroup)s': %(pids)s") % dict( + cgroup=os.path.join(self.cgroup, 'cgroup.procs'), + pids=' '.join(str(pid) for pid in pids))) + + self._elog('eerror', msg) # step 2: remove the cgroup try: @@ -221,3 +241,8 @@ class SpawnProcess(SubProcess): # it may be removed already, or busy # we can't do anything good about it pass + + def _elog(self, elog_funcname, lines): + elog_func = getattr(EOutput(), elog_funcname) + for line in lines: + elog_func(line)