1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-30 12:29:55 +00:00

runqemu: kill qemu if it hangs

qemu doesn't always behave well and can hang too.
kill it with force if it was still alive. Move clean up
commands into cleanup() function.

(From OE-Core rev: 079c2935d2f585ce49e1c7daab2155fcf0094c48)

Signed-off-by: Mikko Rapeli <mikko.rapeli@linaro.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Mikko Rapeli
2023-02-15 16:50:41 +02:00
committed by Richard Purdie
parent c7b05d5657
commit bfb4d48d7c
+15 -9
View File
@@ -211,7 +211,7 @@ class BaseConfig(object):
self.mac_slirp = "52:54:00:12:35:" self.mac_slirp = "52:54:00:12:35:"
# pid of the actual qemu process # pid of the actual qemu process
self.qemu_environ = os.environ.copy() self.qemu_environ = os.environ.copy()
self.qemupid = None self.qemuprocess = None
# avoid cleanup twice # avoid cleanup twice
self.cleaned = False self.cleaned = False
# Files to cleanup after run # Files to cleanup after run
@@ -1531,7 +1531,7 @@ class BaseConfig(object):
for descriptor in self.portlocks.values(): for descriptor in self.portlocks.values():
pass_fds.append(descriptor.fileno()) pass_fds.append(descriptor.fileno())
process = subprocess.Popen(cmds, stderr=subprocess.PIPE, pass_fds=pass_fds, env=self.qemu_environ) process = subprocess.Popen(cmds, stderr=subprocess.PIPE, pass_fds=pass_fds, env=self.qemu_environ)
self.qemupid = process.pid self.qemuprocess = process
retcode = process.wait() retcode = process.wait()
if retcode: if retcode:
if retcode == -signal.SIGTERM: if retcode == -signal.SIGTERM:
@@ -1554,6 +1554,15 @@ class BaseConfig(object):
signal.signal(signal.SIGTERM, signal.SIG_IGN) signal.signal(signal.SIGTERM, signal.SIG_IGN)
logger.info("Cleaning up") logger.info("Cleaning up")
if self.qemuprocess:
try:
# give it some time to shut down, ignore return values and output
self.qemuprocess.send_signal(signal.SIGTERM)
self.qemuprocess.communicate(timeout=5)
except subprocess.TimeoutExpired:
self.qemuprocess.kill()
with open('/proc/uptime', 'r') as f: with open('/proc/uptime', 'r') as f:
uptime_seconds = f.readline().split()[0] uptime_seconds = f.readline().split()[0]
logger.info('Host uptime: %s\n' % uptime_seconds) logger.info('Host uptime: %s\n' % uptime_seconds)
@@ -1581,6 +1590,9 @@ class BaseConfig(object):
else: else:
shutil.rmtree(ent) shutil.rmtree(ent)
# Deliberately ignore the return code of 'tput smam'.
subprocess.call(["tput", "smam"])
self.cleaned = True self.cleaned = True
def run_bitbake_env(self, mach=None): def run_bitbake_env(self, mach=None):
@@ -1657,12 +1669,8 @@ def main():
subprocess.check_call([renice, str(os.getpid())]) subprocess.check_call([renice, str(os.getpid())])
def sigterm_handler(signum, frame): def sigterm_handler(signum, frame):
logger.info("SIGTERM received") logger.info("Received signal: %s" % (signum))
if config.qemupid:
os.kill(config.qemupid, signal.SIGTERM)
config.cleanup() config.cleanup()
# Deliberately ignore the return code of 'tput smam'.
subprocess.call(["tput", "smam"])
signal.signal(signal.SIGTERM, sigterm_handler) signal.signal(signal.SIGTERM, sigterm_handler)
config.check_args() config.check_args()
@@ -1686,8 +1694,6 @@ def main():
finally: finally:
config.cleanup_cmd() config.cleanup_cmd()
config.cleanup() config.cleanup()
# Deliberately ignore the return code of 'tput smam'.
subprocess.call(["tput", "smam"])
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main()) sys.exit(main())