Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH V2 0/1] runqemu: fix handling of SIGTERM and the problem of line wrapping
@ 2018-09-25  7:08 Chen Qi
  2018-09-25  7:08 ` [PATCH V2 1/1] " Chen Qi
  0 siblings, 1 reply; 2+ messages in thread
From: Chen Qi @ 2018-09-25  7:08 UTC (permalink / raw)
  To: openembedded-core

Changes in V2:
* Change to get rid of shell=True

The following changes since commit c6edf2f8bc5778b267e3a7f4e8875d22f359fb8d:

  build-appliance-image: Update to master head revision (2018-09-24 12:31:33 +0100)

are available in the git repository at:

  git://git.pokylinux.org/poky-contrib ChenQi/runqemu-fix
  http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=ChenQi/runqemu-fix

Chen Qi (1):
  runqemu: fix handling of SIGTERM and the problem of line wrapping

 scripts/runqemu | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

-- 
1.9.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH V2 1/1] runqemu: fix handling of SIGTERM and the problem of line wrapping
  2018-09-25  7:08 [PATCH V2 0/1] runqemu: fix handling of SIGTERM and the problem of line wrapping Chen Qi
@ 2018-09-25  7:08 ` Chen Qi
  0 siblings, 0 replies; 2+ messages in thread
From: Chen Qi @ 2018-09-25  7:08 UTC (permalink / raw)
  To: openembedded-core

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.

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 scripts/runqemu | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/scripts/runqemu b/scripts/runqemu
index 409d17c..087220c 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -1202,6 +1202,7 @@ class BaseConfig(object):
                 self.qemu_opt += " -serial mon:vc -serial null"
 
     def start_qemu(self):
+        import shlex
         if self.kernel:
             kernel_opts = "-kernel %s -append '%s %s %s %s'" % (self.kernel, self.kernel_cmdline,
                                                                 self.kernel_cmdline_script, self.get('QB_KERNEL_CMDLINE_APPEND'),
@@ -1211,11 +1212,16 @@ class BaseConfig(object):
         else:
             kernel_opts = ""
         cmd = "%s %s" % (self.qemu_opt, kernel_opts)
+        cmds = shlex.split(cmd)
         logger.info('Running %s\n' % cmd)
-        process = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
+        process = subprocess.Popen(cmds, stderr=subprocess.PIPE)
         self.qemupid = process.pid
-        if process.wait():
-            logger.error("Failed to run qemu: %s", process.stderr.read().decode())
+        retcode = process.wait()
+        if retcode:
+            if retcode == -signal.SIGTERM:
+                logger.info("Qemu terminated by SIGTERM")
+            else:
+                logger.error("Failed to run qemu: %s", process.stderr.read().decode())
 
     def cleanup(self):
         if self.cleaned:
@@ -1310,6 +1316,7 @@ def main():
             logger.info("SIGTERM received")
             os.kill(config.qemupid, signal.SIGTERM)
             config.cleanup()
+            subprocess.run(["tput", "smam"])
         signal.signal(signal.SIGTERM, sigterm_handler)
 
         config.check_args()
@@ -1331,6 +1338,7 @@ def main():
         return 1
     finally:
         config.cleanup()
+        subprocess.run(["tput", "smam"])
 
 if __name__ == "__main__":
     sys.exit(main())
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-25  7:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-25  7:08 [PATCH V2 0/1] runqemu: fix handling of SIGTERM and the problem of line wrapping Chen Qi
2018-09-25  7:08 ` [PATCH V2 1/1] " Chen Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox