summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikko Rapeli <mikko.rapeli@linaro.org>2023-02-15 16:50:41 +0200
committerSteve Sakoman <steve@sakoman.com>2023-02-25 09:25:51 -1000
commit9047a07bc8a8c440cb30c6bb49710362eae41330 (patch)
tree669441b538d7889747796ce7c90acfe7b18d5de4
parent3e1a4d572922eadc85ff6ac169722ad7ab118cf4 (diff)
downloadopenembedded-core-9047a07bc8a8c440cb30c6bb49710362eae41330.tar.gz
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. Signed-off-by: Mikko Rapeli <mikko.rapeli@linaro.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> (cherry picked from commit 079c2935d2f585ce49e1c7daab2155fcf0094c48) Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rwxr-xr-xscripts/runqemu24
1 files changed, 15 insertions, 9 deletions
diff --git a/scripts/runqemu b/scripts/runqemu
index a6ea578564..db35d83fa9 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -211,7 +211,7 @@ class BaseConfig(object):
self.mac_slirp = "52:54:00:12:35:"
# pid of the actual qemu process
self.qemu_environ = os.environ.copy()
- self.qemupid = None
+ self.qemuprocess = None
# avoid cleanup twice
self.cleaned = False
# Files to cleanup after run
@@ -1517,7 +1517,7 @@ class BaseConfig(object):
for descriptor in self.portlocks.values():
pass_fds.append(descriptor.fileno())
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()
if retcode:
if retcode == -signal.SIGTERM:
@@ -1533,6 +1533,15 @@ class BaseConfig(object):
signal.signal(signal.SIGTERM, signal.SIG_IGN)
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:
uptime_seconds = f.readline().split()[0]
logger.info('Host uptime: %s\n' % uptime_seconds)
@@ -1560,6 +1569,9 @@ class BaseConfig(object):
else:
shutil.rmtree(ent)
+ # Deliberately ignore the return code of 'tput smam'.
+ subprocess.call(["tput", "smam"])
+
self.cleaned = True
def run_bitbake_env(self, mach=None):
@@ -1636,12 +1648,8 @@ def main():
subprocess.check_call([renice, str(os.getpid())])
def sigterm_handler(signum, frame):
- logger.info("SIGTERM received")
- if config.qemupid:
- os.kill(config.qemupid, signal.SIGTERM)
+ logger.info("Received signal: %s" % (signum))
config.cleanup()
- # Deliberately ignore the return code of 'tput smam'.
- subprocess.call(["tput", "smam"])
signal.signal(signal.SIGTERM, sigterm_handler)
config.check_args()
@@ -1663,8 +1671,6 @@ def main():
return 1
finally:
config.cleanup()
- # Deliberately ignore the return code of 'tput smam'.
- subprocess.call(["tput", "smam"])
if __name__ == "__main__":
sys.exit(main())