diff options
author | Mikko Rapeli <mikko.rapeli@linaro.org> | 2023-02-15 16:50:41 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-02-23 12:11:29 +0000 |
commit | bfb4d48d7c3e2bee595629aaf2b9260075b196bc (patch) | |
tree | fa5a32c3092840c9c587a0ae5fd357733f960dd9 /scripts | |
parent | c7b05d56573cb3304ba05d375a54d0484da23425 (diff) | |
download | poky-bfb4d48d7c3e2bee595629aaf2b9260075b196bc.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: 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>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/runqemu | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/scripts/runqemu b/scripts/runqemu index def11ea911..cedf4f62ad 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 |
@@ -1531,7 +1531,7 @@ class BaseConfig(object): | |||
1531 | for descriptor in self.portlocks.values(): | 1531 | for descriptor in self.portlocks.values(): |
1532 | pass_fds.append(descriptor.fileno()) | 1532 | pass_fds.append(descriptor.fileno()) |
1533 | process = subprocess.Popen(cmds, stderr=subprocess.PIPE, pass_fds=pass_fds, env=self.qemu_environ) | 1533 | process = subprocess.Popen(cmds, stderr=subprocess.PIPE, pass_fds=pass_fds, env=self.qemu_environ) |
1534 | self.qemupid = process.pid | 1534 | self.qemuprocess = process |
1535 | retcode = process.wait() | 1535 | retcode = process.wait() |
1536 | if retcode: | 1536 | if retcode: |
1537 | if retcode == -signal.SIGTERM: | 1537 | if retcode == -signal.SIGTERM: |
@@ -1554,6 +1554,15 @@ class BaseConfig(object): | |||
1554 | signal.signal(signal.SIGTERM, signal.SIG_IGN) | 1554 | signal.signal(signal.SIGTERM, signal.SIG_IGN) |
1555 | 1555 | ||
1556 | logger.info("Cleaning up") | 1556 | logger.info("Cleaning up") |
1557 | |||
1558 | if self.qemuprocess: | ||
1559 | try: | ||
1560 | # give it some time to shut down, ignore return values and output | ||
1561 | self.qemuprocess.send_signal(signal.SIGTERM) | ||
1562 | self.qemuprocess.communicate(timeout=5) | ||
1563 | except subprocess.TimeoutExpired: | ||
1564 | self.qemuprocess.kill() | ||
1565 | |||
1557 | with open('/proc/uptime', 'r') as f: | 1566 | with open('/proc/uptime', 'r') as f: |
1558 | uptime_seconds = f.readline().split()[0] | 1567 | uptime_seconds = f.readline().split()[0] |
1559 | logger.info('Host uptime: %s\n' % uptime_seconds) | 1568 | logger.info('Host uptime: %s\n' % uptime_seconds) |
@@ -1581,6 +1590,9 @@ class BaseConfig(object): | |||
1581 | else: | 1590 | else: |
1582 | shutil.rmtree(ent) | 1591 | shutil.rmtree(ent) |
1583 | 1592 | ||
1593 | # Deliberately ignore the return code of 'tput smam'. | ||
1594 | subprocess.call(["tput", "smam"]) | ||
1595 | |||
1584 | self.cleaned = True | 1596 | self.cleaned = True |
1585 | 1597 | ||
1586 | def run_bitbake_env(self, mach=None): | 1598 | def run_bitbake_env(self, mach=None): |
@@ -1657,12 +1669,8 @@ def main(): | |||
1657 | subprocess.check_call([renice, str(os.getpid())]) | 1669 | subprocess.check_call([renice, str(os.getpid())]) |
1658 | 1670 | ||
1659 | def sigterm_handler(signum, frame): | 1671 | def sigterm_handler(signum, frame): |
1660 | logger.info("SIGTERM received") | 1672 | logger.info("Received signal: %s" % (signum)) |
1661 | if config.qemupid: | ||
1662 | os.kill(config.qemupid, signal.SIGTERM) | ||
1663 | config.cleanup() | 1673 | config.cleanup() |
1664 | # Deliberately ignore the return code of 'tput smam'. | ||
1665 | subprocess.call(["tput", "smam"]) | ||
1666 | signal.signal(signal.SIGTERM, sigterm_handler) | 1674 | signal.signal(signal.SIGTERM, sigterm_handler) |
1667 | 1675 | ||
1668 | config.check_args() | 1676 | config.check_args() |
@@ -1686,8 +1694,6 @@ def main(): | |||
1686 | finally: | 1694 | finally: |
1687 | config.cleanup_cmd() | 1695 | config.cleanup_cmd() |
1688 | config.cleanup() | 1696 | config.cleanup() |
1689 | # Deliberately ignore the return code of 'tput smam'. | ||
1690 | subprocess.call(["tput", "smam"]) | ||
1691 | 1697 | ||
1692 | if __name__ == "__main__": | 1698 | if __name__ == "__main__": |
1693 | sys.exit(main()) | 1699 | sys.exit(main()) |