[Piuparts-commits] [SCM] piuparts git repository branch, piatti, updated. 0.44-689-gbf31baf
Andreas Beckmann
debian at abeckmann.de
Sun Jun 10 11:10:21 UTC 2012
The following commit has been merged in the piatti branch:
commit 6458dc5eeededf4d345dc99d9fc296c977847b6c
Author: Andreas Beckmann <debian at abeckmann.de>
Date: Wed Jun 6 08:22:57 2012 +0200
p: improve killing of running processes
Rewrite Chroot.terminate_running_processes():
check for new processes getting spawned in the chroot while
the chroot is being shut down and continue killing them.
Signed-off-by: Andreas Beckmann <debian at abeckmann.de>
diff --git a/debian/changelog b/debian/changelog
index 2c089c9..77de8c4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -55,6 +55,8 @@ piuparts (0.45) UNRELEASED; urgency=low
- Set time limit to 30 minutes per command. (Closes: #654423)
- Terminate all processes running inside the chroot before removing the
chroot; also in case piuparts aborts due to an error.
+ - Continue killing running processes as long as new processes get spawned
+ in the chroot.
* piuparts.conf:
- Make master-command a [global] instead of a [section] setting.
The section name will be given as an argument to this command.
diff --git a/piuparts.py b/piuparts.py
index 8b5abd8..904b971 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -1231,21 +1231,30 @@ class Chroot:
def terminate_running_processes(self):
- for signo in [ 15, 9 ]:
- p = subprocess.Popen(["lsof", "-t", "+D", self.name],
- stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- stdout, _ = p.communicate()
- if stdout:
- pidlist = [int(pidstr) for pidstr in stdout.split("\n") if len(pidstr)]
- for pid in pidlist:
- if pid > 0:
- try:
- if signo == 15:
- os.kill(pid, SIGTERM)
- else:
- os.kill(pid, SIGKILL)
- except OSError:
- pass
+ """Terminate all processes running in the chroot."""
+ seen = []
+ while True:
+ p = subprocess.Popen(["lsof", "-t", "+D", self.name],
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ stdout, _ = p.communicate()
+ if not stdout:
+ break
+
+ pidlist = reversed([int(pidstr) for pidstr in stdout.split("\n") if len(pidstr) and int(pidstr) > 0])
+ if not pidlist:
+ break
+
+ for pid in pidlist:
+ try:
+ signo = (SIGTERM, SIGKILL)[pid in seen]
+ os.kill(pid, signo)
+ seen.append(pid)
+ logging.debug("kill -%d %d" % (signo, pid))
+ time.sleep(0.25)
+ except OSError:
+ pass
+
+ time.sleep(5)
def mount_selinux(self):
--
piuparts git repository
More information about the Piuparts-commits
mailing list