diff options
-rwxr-xr-x | scripts/runqemu | 24 |
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): | |||
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 |
@@ -1517,7 +1517,7 @@ class BaseConfig(object): | |||
1517 | for descriptor in self.portlocks.values(): | 1517 | for descriptor in self.portlocks.values(): |
1518 | pass_fds.append(descriptor.fileno()) | 1518 | pass_fds.append(descriptor.fileno()) |
1519 | process = subprocess.Popen(cmds, stderr=subprocess.PIPE, pass_fds=pass_fds, env=self.qemu_environ) | 1519 | process = subprocess.Popen(cmds, stderr=subprocess.PIPE, pass_fds=pass_fds, env=self.qemu_environ) |
1520 | self.qemupid = process.pid | 1520 | self.qemuprocess = process |
1521 | retcode = process.wait() | 1521 | retcode = process.wait() |
1522 | if retcode: | 1522 | if retcode: |
1523 | if retcode == -signal.SIGTERM: | 1523 | if retcode == -signal.SIGTERM: |
@@ -1533,6 +1533,15 @@ class BaseConfig(object): | |||
1533 | signal.signal(signal.SIGTERM, signal.SIG_IGN) | 1533 | signal.signal(signal.SIGTERM, signal.SIG_IGN) |
1534 | 1534 | ||
1535 | logger.info("Cleaning up") | 1535 | logger.info("Cleaning up") |
1536 | |||
1537 | if self.qemuprocess: | ||
1538 | try: | ||
1539 | # give it some time to shut down, ignore return values and output | ||
1540 | self.qemuprocess.send_signal(signal.SIGTERM) | ||
1541 | self.qemuprocess.communicate(timeout=5) | ||
1542 | except subprocess.TimeoutExpired: | ||
1543 | self.qemuprocess.kill() | ||
1544 | |||
1536 | with open('/proc/uptime', 'r') as f: | 1545 | with open('/proc/uptime', 'r') as f: |
1537 | uptime_seconds = f.readline().split()[0] | 1546 | uptime_seconds = f.readline().split()[0] |
1538 | logger.info('Host uptime: %s\n' % uptime_seconds) | 1547 | logger.info('Host uptime: %s\n' % uptime_seconds) |
@@ -1560,6 +1569,9 @@ class BaseConfig(object): | |||
1560 | else: | 1569 | else: |
1561 | shutil.rmtree(ent) | 1570 | shutil.rmtree(ent) |
1562 | 1571 | ||
1572 | # Deliberately ignore the return code of 'tput smam'. | ||
1573 | subprocess.call(["tput", "smam"]) | ||
1574 | |||
1563 | self.cleaned = True | 1575 | self.cleaned = True |
1564 | 1576 | ||
1565 | def run_bitbake_env(self, mach=None): | 1577 | def run_bitbake_env(self, mach=None): |
@@ -1636,12 +1648,8 @@ def main(): | |||
1636 | subprocess.check_call([renice, str(os.getpid())]) | 1648 | subprocess.check_call([renice, str(os.getpid())]) |
1637 | 1649 | ||
1638 | def sigterm_handler(signum, frame): | 1650 | def sigterm_handler(signum, frame): |
1639 | logger.info("SIGTERM received") | 1651 | logger.info("Received signal: %s" % (signum)) |
1640 | if config.qemupid: | ||
1641 | os.kill(config.qemupid, signal.SIGTERM) | ||
1642 | config.cleanup() | 1652 | config.cleanup() |
1643 | # Deliberately ignore the return code of 'tput smam'. | ||
1644 | subprocess.call(["tput", "smam"]) | ||
1645 | signal.signal(signal.SIGTERM, sigterm_handler) | 1653 | signal.signal(signal.SIGTERM, sigterm_handler) |
1646 | 1654 | ||
1647 | config.check_args() | 1655 | config.check_args() |
@@ -1663,8 +1671,6 @@ def main(): | |||
1663 | return 1 | 1671 | return 1 |
1664 | finally: | 1672 | finally: |
1665 | config.cleanup() | 1673 | config.cleanup() |
1666 | # Deliberately ignore the return code of 'tput smam'. | ||
1667 | subprocess.call(["tput", "smam"]) | ||
1668 | 1674 | ||
1669 | if __name__ == "__main__": | 1675 | if __name__ == "__main__": |
1670 | sys.exit(main()) | 1676 | sys.exit(main()) |