summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMikko Rapeli <mikko.rapeli@linaro.org>2023-02-15 16:50:41 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-03-09 13:19:03 +0000
commit351110f0cf25ae5952ed3e09026607fcc38f7e8a (patch)
treeb49902489449bd7e5cd78093b0fa1cb3a417afe4 /scripts
parent4cd4e6d9bad9750f083be7dd97d37b0c83a8482e (diff)
downloadpoky-351110f0cf25ae5952ed3e09026607fcc38f7e8a.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. (From OE-Core rev: 929e7679c1d9b21ac5130a9cbc83c415fb9f63f5) 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> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/runqemu24
1 files changed, 15 insertions, 9 deletions
diff --git a/scripts/runqemu b/scripts/runqemu
index 0cce8bb96a..5a98abfffe 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -211,7 +211,7 @@ class BaseConfig(object):
211 self.mac_slirp = "52:54:00:12:35:" 211 self.mac_slirp = "52:54:00:12:35:"
212 # pid of the actual qemu process 212 # pid of the actual qemu process
213 self.qemu_environ = os.environ.copy() 213 self.qemu_environ = os.environ.copy()
214 self.qemupid = None 214 self.qemuprocess = None
215 # avoid cleanup twice 215 # avoid cleanup twice
216 self.cleaned = False 216 self.cleaned = False
217 # Files to cleanup after run 217 # Files to cleanup after run
@@ -1512,7 +1512,7 @@ class BaseConfig(object):
1512 for descriptor in self.portlocks.values(): 1512 for descriptor in self.portlocks.values():
1513 pass_fds.append(descriptor.fileno()) 1513 pass_fds.append(descriptor.fileno())
1514 process = subprocess.Popen(cmds, stderr=subprocess.PIPE, pass_fds=pass_fds, env=self.qemu_environ) 1514 process = subprocess.Popen(cmds, stderr=subprocess.PIPE, pass_fds=pass_fds, env=self.qemu_environ)
1515 self.qemupid = process.pid 1515 self.qemuprocess = process
1516 retcode = process.wait() 1516 retcode = process.wait()
1517 if retcode: 1517 if retcode:
1518 if retcode == -signal.SIGTERM: 1518 if retcode == -signal.SIGTERM:
@@ -1528,6 +1528,15 @@ class BaseConfig(object):
1528 signal.signal(signal.SIGTERM, signal.SIG_IGN) 1528 signal.signal(signal.SIGTERM, signal.SIG_IGN)
1529 1529
1530 logger.info("Cleaning up") 1530 logger.info("Cleaning up")
1531
1532 if self.qemuprocess:
1533 try:
1534 # give it some time to shut down, ignore return values and output
1535 self.qemuprocess.send_signal(signal.SIGTERM)
1536 self.qemuprocess.communicate(timeout=5)
1537 except subprocess.TimeoutExpired:
1538 self.qemuprocess.kill()
1539
1531 with open('/proc/uptime', 'r') as f: 1540 with open('/proc/uptime', 'r') as f:
1532 uptime_seconds = f.readline().split()[0] 1541 uptime_seconds = f.readline().split()[0]
1533 logger.info('Host uptime: %s\n' % uptime_seconds) 1542 logger.info('Host uptime: %s\n' % uptime_seconds)
@@ -1555,6 +1564,9 @@ class BaseConfig(object):
1555 else: 1564 else:
1556 shutil.rmtree(ent) 1565 shutil.rmtree(ent)
1557 1566
1567 # Deliberately ignore the return code of 'tput smam'.
1568 subprocess.call(["tput", "smam"])
1569
1558 self.cleaned = True 1570 self.cleaned = True
1559 1571
1560 def run_bitbake_env(self, mach=None): 1572 def run_bitbake_env(self, mach=None):
@@ -1631,12 +1643,8 @@ def main():
1631 subprocess.check_call([renice, str(os.getpid())]) 1643 subprocess.check_call([renice, str(os.getpid())])
1632 1644
1633 def sigterm_handler(signum, frame): 1645 def sigterm_handler(signum, frame):
1634 logger.info("SIGTERM received") 1646 logger.info("Received signal: %s" % (signum))
1635 if config.qemupid:
1636 os.kill(config.qemupid, signal.SIGTERM)
1637 config.cleanup() 1647 config.cleanup()
1638 # Deliberately ignore the return code of 'tput smam'.
1639 subprocess.call(["tput", "smam"])
1640 signal.signal(signal.SIGTERM, sigterm_handler) 1648 signal.signal(signal.SIGTERM, sigterm_handler)
1641 1649
1642 config.check_args() 1650 config.check_args()
@@ -1658,8 +1666,6 @@ def main():
1658 return 1 1666 return 1
1659 finally: 1667 finally:
1660 config.cleanup() 1668 config.cleanup()
1661 # Deliberately ignore the return code of 'tput smam'.
1662 subprocess.call(["tput", "smam"])
1663 1669
1664if __name__ == "__main__": 1670if __name__ == "__main__":
1665 sys.exit(main()) 1671 sys.exit(main())