summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-08 23:35:04 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-09 14:24:59 +0100
commit99428eafb5352bd39bc4329bdba07c6d6f17b03f (patch)
treef1a6a0065b27b9c0fd3549df8d696796e036f02a
parenta3c322b42c7a14584a80e04519c34689ec813210 (diff)
downloadopenembedded-core-contrib-99428eafb5352bd39bc4329bdba07c6d6f17b03f.tar.gz
openembedded-core-contrib-99428eafb5352bd39bc4329bdba07c6d6f17b03f.tar.bz2
openembedded-core-contrib-99428eafb5352bd39bc4329bdba07c6d6f17b03f.zip
qemurunner: Ensure runqemu doesn't survive SIGKILL
Currently, we see runqemu and qemu-system-* processes left behind when bitbake is killed by buildbot. This is due to the use of setpgrp() in the runqemu subprocess call. We need the setpgrp call so that all runqemu processes can easily be killed (by killing their process group). This presents a problem if this controlling process itself is killed however since those processes don't notice the death of the parent and merrily continue on. Rather than hack runqemu to deal with this, we add something to qemurunner, at least for now to resolve the issue. Basically we fork off another process which holds an open pipe to the parent and also is setpgrp. If/when the pipe sees EOF from the parent dieing, it kills the process group. This is like pctrl's PDEATHSIG but for a process group rather than a single process. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/utils/qemurunner.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index a137b11f40..3f3fd8b71c 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -125,6 +125,32 @@ class QemuRunner:
self.runqemu = subprocess.Popen(launch_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, preexec_fn=os.setpgrp)
output = self.runqemu.stdout
+ #
+ # We need the preexec_fn above so that all runqemu processes can easily be killed
+ # (by killing their process group). This presents a problem if this controlling
+ # process itself is killed however since those processes don't notice the death
+ # of the parent and merrily continue on.
+ #
+ # Rather than hack runqemu to deal with this, we add something here instead.
+ # Basically we fork off another process which holds an open pipe to the parent
+ # and also is setpgrp. If/when the pipe sees EOF from the parent dieing, it kills
+ # the process group. This is like pctrl's PDEATHSIG but for a process group
+ # rather than a single process.
+ #
+ r, w = os.pipe()
+ self.monitorpid = os.fork()
+ if self.monitorpid:
+ os.close(r)
+ self.monitorpipe = os.fdopen(w, "w")
+ else:
+ # child process
+ os.setpgrp()
+ os.close(w)
+ r = os.fdopen(r)
+ x = r.read()
+ os.killpg(os.getpgid(self.runqemu.pid), signal.SIGTERM)
+ sys.exit(0)
+
logger.info("runqemu started, pid is %s" % self.runqemu.pid)
logger.info("waiting at most %s seconds for qemu pid" % self.runqemutime)
endtime = time.time() + self.runqemutime
@@ -235,6 +261,7 @@ class QemuRunner:
self.stop_thread()
if self.runqemu:
signal.signal(signal.SIGCHLD, self.origchldhandler)
+ os.kill(self.monitorpid, signal.SIGKILL)
logger.info("Sending SIGTERM to runqemu")
try:
os.killpg(self.runqemu.pid, signal.SIGTERM)