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-09-25 23:15:49 +0100
commit0e10a37618c089dc472896a0354aec10ee332913 (patch)
tree01e8837bc88f3e41832a8f01c87bec7b449735c4 /scripts
parent07bf5b5e034b99e36693a9f354fbb40fcc819d9e (diff)
downloadpoky-0e10a37618c089dc472896a0354aec10ee332913.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) Signed-off-by: Chen Qi <Qi.Chen@windriver.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 409d17c648..087220ca0a 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -1202,6 +1202,7 @@ class BaseConfig(object):
1202 self.qemu_opt += " -serial mon:vc -serial null" 1202 self.qemu_opt += " -serial mon:vc -serial null"
1203 1203
1204 def start_qemu(self): 1204 def start_qemu(self):
1205 import shlex
1205 if self.kernel: 1206 if self.kernel:
1206 kernel_opts = "-kernel %s -append '%s %s %s %s'" % (self.kernel, self.kernel_cmdline, 1207 kernel_opts = "-kernel %s -append '%s %s %s %s'" % (self.kernel, self.kernel_cmdline,
1207 self.kernel_cmdline_script, self.get('QB_KERNEL_CMDLINE_APPEND'), 1208 self.kernel_cmdline_script, self.get('QB_KERNEL_CMDLINE_APPEND'),
@@ -1211,11 +1212,16 @@ class BaseConfig(object):
1211 else: 1212 else:
1212 kernel_opts = "" 1213 kernel_opts = ""
1213 cmd = "%s %s" % (self.qemu_opt, kernel_opts) 1214 cmd = "%s %s" % (self.qemu_opt, kernel_opts)
1215 cmds = shlex.split(cmd)
1214 logger.info('Running %s\n' % cmd) 1216 logger.info('Running %s\n' % cmd)
1215 process = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE) 1217 process = subprocess.Popen(cmds, stderr=subprocess.PIPE)
1216 self.qemupid = process.pid 1218 self.qemupid = process.pid
1217 if process.wait(): 1219 retcode = process.wait()
1218 logger.error("Failed to run qemu: %s", process.stderr.read().decode()) 1220 if retcode:
1221 if retcode == -signal.SIGTERM:
1222 logger.info("Qemu terminated by SIGTERM")
1223 else:
1224 logger.error("Failed to run qemu: %s", process.stderr.read().decode())
1219 1225
1220 def cleanup(self): 1226 def cleanup(self):
1221 if self.cleaned: 1227 if self.cleaned:
@@ -1310,6 +1316,7 @@ def main():
1310 logger.info("SIGTERM received") 1316 logger.info("SIGTERM received")
1311 os.kill(config.qemupid, signal.SIGTERM) 1317 os.kill(config.qemupid, signal.SIGTERM)
1312 config.cleanup() 1318 config.cleanup()
1319 subprocess.run(["tput", "smam"])
1313 signal.signal(signal.SIGTERM, sigterm_handler) 1320 signal.signal(signal.SIGTERM, sigterm_handler)
1314 1321
1315 config.check_args() 1322 config.check_args()
@@ -1331,6 +1338,7 @@ def main():
1331 return 1 1338 return 1
1332 finally: 1339 finally:
1333 config.cleanup() 1340 config.cleanup()
1341 subprocess.run(["tput", "smam"])
1334 1342
1335if __name__ == "__main__": 1343if __name__ == "__main__":
1336 sys.exit(main()) 1344 sys.exit(main())