summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorChen Qi <Qi.Chen@windriver.com>2018-09-25 15:08:25 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-10-18 11:08:53 +0100
commit30a244ba7b61c025402f541a7b9b05ffb2bf8224 (patch)
treeeab42149a3dddbad56d034b709672eefa466768a /scripts
parentfff3aa6b075ba68d150e3dc76af96b14a29bb517 (diff)
downloadpoky-30a244ba7b61c025402f541a7b9b05ffb2bf8224.tar.gz
runqemu: fix handling of SIGTERM and the problem of line wrapping
The current handling of SIGTERM is incorrect as the process pid returned by Popen call with shell setting to True is actualy the shell instead of the qemu process. So use shlex to split cmd so that we can avoid using shell=True. This ensures the child process is the actual qemu process. Also, as we install a SIGTERM handler, we need handle the situation of qemu terminated by SIGTERM, otherwise we will get ERROR message in such case. Besides, we have a problem that after running qemu, the terminal's behavior is incorrect regarding long lines or long commands. Long commands or long outputs should appear in multiple lines, but they appear in the same line, overriding previous output. Use `tput smam' to fix this problem. (From OE-Core rev: e8acef383767cfd1ef0c3d3c45d9d6eb1c83b3e7) (From OE-Core rev: a2ee5c8a1ff449250e6f37fccf01b85a7361b24c) Signed-off-by: Chen Qi <Qi.Chen@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> Signed-off-by: Armin Kuster <akuster808@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/runqemu14
1 files changed, 11 insertions, 3 deletions
diff --git a/scripts/runqemu b/scripts/runqemu
index cb36c2007b..bd3aee0c2f 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -1199,6 +1199,7 @@ class BaseConfig(object):
1199 self.qemu_opt += " -serial mon:vc -serial null" 1199 self.qemu_opt += " -serial mon:vc -serial null"
1200 1200
1201 def start_qemu(self): 1201 def start_qemu(self):
1202 import shlex
1202 if self.kernel: 1203 if self.kernel:
1203 kernel_opts = "-kernel %s -append '%s %s %s %s'" % (self.kernel, self.kernel_cmdline, 1204 kernel_opts = "-kernel %s -append '%s %s %s %s'" % (self.kernel, self.kernel_cmdline,
1204 self.kernel_cmdline_script, self.get('QB_KERNEL_CMDLINE_APPEND'), 1205 self.kernel_cmdline_script, self.get('QB_KERNEL_CMDLINE_APPEND'),
@@ -1208,11 +1209,16 @@ class BaseConfig(object):
1208 else: 1209 else:
1209 kernel_opts = "" 1210 kernel_opts = ""
1210 cmd = "%s %s" % (self.qemu_opt, kernel_opts) 1211 cmd = "%s %s" % (self.qemu_opt, kernel_opts)
1212 cmds = shlex.split(cmd)
1211 logger.info('Running %s\n' % cmd) 1213 logger.info('Running %s\n' % cmd)
1212 process = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE) 1214 process = subprocess.Popen(cmds, stderr=subprocess.PIPE)
1213 self.qemupid = process.pid 1215 self.qemupid = process.pid
1214 if process.wait(): 1216 retcode = process.wait()
1215 logger.error("Failed to run qemu: %s", process.stderr.read().decode()) 1217 if retcode:
1218 if retcode == -signal.SIGTERM:
1219 logger.info("Qemu terminated by SIGTERM")
1220 else:
1221 logger.error("Failed to run qemu: %s", process.stderr.read().decode())
1216 1222
1217 def cleanup(self): 1223 def cleanup(self):
1218 if self.cleaned: 1224 if self.cleaned:
@@ -1307,6 +1313,7 @@ def main():
1307 logger.info("SIGTERM received") 1313 logger.info("SIGTERM received")
1308 os.kill(config.qemupid, signal.SIGTERM) 1314 os.kill(config.qemupid, signal.SIGTERM)
1309 config.cleanup() 1315 config.cleanup()
1316 subprocess.run(["tput", "smam"])
1310 signal.signal(signal.SIGTERM, sigterm_handler) 1317 signal.signal(signal.SIGTERM, sigterm_handler)
1311 1318
1312 config.check_args() 1319 config.check_args()
@@ -1328,6 +1335,7 @@ def main():
1328 return 1 1335 return 1
1329 finally: 1336 finally:
1330 config.cleanup() 1337 config.cleanup()
1338 subprocess.run(["tput", "smam"])
1331 1339
1332if __name__ == "__main__": 1340if __name__ == "__main__":
1333 sys.exit(main()) 1341 sys.exit(main())