[oe-commits] [openembedded-core] 12/14: runqemu: fix handling of SIGTERM and the problem of line wrapping

git at git.openembedded.org git at git.openembedded.org
Thu Oct 18 10:10:26 UTC 2018


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch sumo
in repository openembedded-core.

commit a2ee5c8a1ff449250e6f37fccf01b85a7361b24c
Author: Chen Qi <Qi.Chen at windriver.com>
AuthorDate: Tue Sep 25 15:08:25 2018 +0800

    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 at windriver.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
    Signed-off-by: Armin Kuster <akuster808 at gmail.com>
---
 scripts/runqemu | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/scripts/runqemu b/scripts/runqemu
index cb36c20..bd3aee0 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -1199,6 +1199,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'),
@@ -1208,11 +1209,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:
@@ -1307,6 +1313,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()
@@ -1328,6 +1335,7 @@ def main():
         return 1
     finally:
         config.cleanup()
+        subprocess.run(["tput", "smam"])
 
 if __name__ == "__main__":
     sys.exit(main())

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list