summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils
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:27:46 +0100
commit335260cbfcedc7c348f2e190400efbae67ad92ff (patch)
treed48f9aec1a2b48fc4e3b5b23db95d26d92767b1b /meta/lib/oeqa/utils
parent79bf3f7155e00b96bd205c5bd844cc91ab2e9553 (diff)
downloadpoky-335260cbfcedc7c348f2e190400efbae67ad92ff.tar.gz
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. (From OE-Core rev: 99428eafb5352bd39bc4329bdba07c6d6f17b03f) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/utils')
-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:
125 self.runqemu = subprocess.Popen(launch_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, preexec_fn=os.setpgrp) 125 self.runqemu = subprocess.Popen(launch_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, preexec_fn=os.setpgrp)
126 output = self.runqemu.stdout 126 output = self.runqemu.stdout
127 127
128 #
129 # We need the preexec_fn above so that all runqemu processes can easily be killed
130 # (by killing their process group). This presents a problem if this controlling
131 # process itself is killed however since those processes don't notice the death
132 # of the parent and merrily continue on.
133 #
134 # Rather than hack runqemu to deal with this, we add something here instead.
135 # Basically we fork off another process which holds an open pipe to the parent
136 # and also is setpgrp. If/when the pipe sees EOF from the parent dieing, it kills
137 # the process group. This is like pctrl's PDEATHSIG but for a process group
138 # rather than a single process.
139 #
140 r, w = os.pipe()
141 self.monitorpid = os.fork()
142 if self.monitorpid:
143 os.close(r)
144 self.monitorpipe = os.fdopen(w, "w")
145 else:
146 # child process
147 os.setpgrp()
148 os.close(w)
149 r = os.fdopen(r)
150 x = r.read()
151 os.killpg(os.getpgid(self.runqemu.pid), signal.SIGTERM)
152 sys.exit(0)
153
128 logger.info("runqemu started, pid is %s" % self.runqemu.pid) 154 logger.info("runqemu started, pid is %s" % self.runqemu.pid)
129 logger.info("waiting at most %s seconds for qemu pid" % self.runqemutime) 155 logger.info("waiting at most %s seconds for qemu pid" % self.runqemutime)
130 endtime = time.time() + self.runqemutime 156 endtime = time.time() + self.runqemutime
@@ -235,6 +261,7 @@ class QemuRunner:
235 self.stop_thread() 261 self.stop_thread()
236 if self.runqemu: 262 if self.runqemu:
237 signal.signal(signal.SIGCHLD, self.origchldhandler) 263 signal.signal(signal.SIGCHLD, self.origchldhandler)
264 os.kill(self.monitorpid, signal.SIGKILL)
238 logger.info("Sending SIGTERM to runqemu") 265 logger.info("Sending SIGTERM to runqemu")
239 try: 266 try:
240 os.killpg(self.runqemu.pid, signal.SIGTERM) 267 os.killpg(self.runqemu.pid, signal.SIGTERM)