]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
qemurunner: Fix a bug with fork/exit handling
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 3 Mar 2025 13:13:31 +0000 (13:13 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 3 Mar 2025 18:01:15 +0000 (18:01 +0000)
If you send this forked process a SIGTERM, it will execute all of the
parent's exit code leading to two sets of console/exit output which is
extremely confusing. Wrap the code in a try/finally to ensure we always
call os._exit() to avoid this.

I spent far too long trying to work out the crazy console output from this.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oeqa/utils/qemurunner.py

index 04e033491406564aa668460fec063355a15d1d19..c4db0cf038b73352e2ab8a44e17349a590798fe6 100644 (file)
@@ -267,12 +267,15 @@ class QemuRunner:
             self.monitorpipe = os.fdopen(w, "w")
         else:
             # child process
-            os.setpgrp()
-            os.close(w)
-            r = os.fdopen(r)
-            x = r.read()
-            os.killpg(os.getpgid(self.runqemu.pid), signal.SIGTERM)
-            os._exit(0)
+            try:
+                os.setpgrp()
+                os.close(w)
+                r = os.fdopen(r)
+                x = r.read()
+                os.killpg(os.getpgid(self.runqemu.pid), signal.SIGTERM)
+            finally:
+                # We must exit under all circumstances
+                os._exit(0)
 
         self.logger.debug("runqemu started, pid is %s" % self.runqemu.pid)
         self.logger.debug("waiting at most %d seconds for qemu pid (%s)" %