poky: sumo refresh 36d5cee56b..d240b885f2

Update poky to sumo HEAD.

Changqing Li (1):
      libsndfile1: CVE-2018-13139

Chen Qi (2):
      runqemu: add SIGTERM handler to make sure things are cleaned up
      runqemu: fix handling of SIGTERM and the problem of line wrapping

Hongxu Jia (1):
      nasm: fix CVE-2018-10016

Ioan-Adrian Ratiu (1):
      rootfs: always update the opkg index

Jagadeesh Krishnanjanappa (1):
      runqemu: exit gracefully with an error message if qemu system is not evaluated

Joe Slater (1):
      libtiff: fix CVE-2017-17095

Khem Raj (1):
      x264: Disable asm on musl/x86

Nicolas Dechesne (1):
      checklayer: avoid recursive loop in add_layer_dependencies

Ola x Nilsson (1):
      externalsrc.bbclass: Set BB_DONT_CACHE for non-target recipes

Richard Purdie (1):
      recipes: Update git.gnome.org addresses after upstream changes

Sinan Kaya (3):
      libxml2: CVE-2018-14404
      python3: CVE-2018-1061
      git: CVE-2018-11233

Change-Id: Ic2daa2803af197180e605346f59bab03f8264e19
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/poky/scripts/runqemu b/poky/scripts/runqemu
index d998494..bd3aee0 100755
--- a/poky/scripts/runqemu
+++ b/poky/scripts/runqemu
@@ -27,6 +27,7 @@
 import shutil
 import glob
 import configparser
+import signal
 
 class RunQemuError(Exception):
     """Custom exception to raise on known errors."""
@@ -233,6 +234,10 @@
         # slirp qemus are running.
         self.mac_tap = "52:54:00:12:34:"
         self.mac_slirp = "52:54:00:12:35:"
+        # pid of the actual qemu process
+        self.qemupid = None
+        # avoid cleanup twice
+        self.cleaned = False
 
     def acquire_lock(self, error=True):
         logger.debug("Acquiring lockfile %s..." % self.lock)
@@ -1110,6 +1115,11 @@
             qbsys = 'riscv64'
         elif mach == 'qemuriscv32':
             qbsys = 'riscv32'
+        else:
+            logger.error("Unable to determine QEMU PC System emulator for %s machine." % mach)
+            logger.error("As %s is not among valid QEMU machines such as," % mach)
+            logger.error("qemux86-64, qemux86, qemuarm64, qemuarm, qemumips64, qemumips64el, qemumipsel, qemumips, qemuppc")
+            raise RunQemuError("Set qb_system_name with suitable QEMU PC System emulator in .*qemuboot.conf.")
 
         return 'qemu-system-%s' % qbsys
 
@@ -1189,6 +1199,7 @@
                 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'),
@@ -1198,12 +1209,25 @@
         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)
-        if process.wait():
-            logger.error("Failed to run qemu: %s", process.stderr.read().decode())
+        process = subprocess.Popen(cmds, stderr=subprocess.PIPE)
+        self.qemupid = process.pid
+        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:
+            return
+
+        # avoid dealing with SIGTERM when cleanup function is running
+        signal.signal(signal.SIGTERM, signal.SIG_IGN)
+
+        logger.info("Cleaning up")
         if self.cleantap:
             cmd = 'sudo %s %s %s' % (self.qemuifdown, self.tap, self.bindir_native)
             logger.debug('Running %s' % cmd)
@@ -1227,6 +1251,8 @@
             shutil.rmtree(self.rootfs)
             shutil.rmtree('%s.pseudo_state' % self.rootfs)
 
+        self.cleaned = True
+
     def load_bitbake_env(self, mach=None):
         if self.bitbake_e:
             return
@@ -1282,6 +1308,14 @@
         return 0
     try:
         config = BaseConfig()
+
+        def sigterm_handler(signum, frame):
+            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()
         config.read_qemuboot()
         config.check_and_set()
@@ -1300,8 +1334,8 @@
         traceback.print_exc()
         return 1
     finally:
-        print("Cleanup")
         config.cleanup()
+        subprocess.run(["tput", "smam"])
 
 if __name__ == "__main__":
     sys.exit(main())