summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils/qemurunner.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/utils/qemurunner.py')
-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)