After the addition of the qmp socket, runqemu started failing:

ERROR - Failed to run qemu: qemu-system-aarch64: -qmp 
unix:/home/yocto/actions-runner-meta-openembedded/_work/meta-openembedded/meta-openembedded/yoe/build/tmp/.3eg5fiid,server,wait:
UNIX socket path 
'/home/yocto/actions-runner-meta-openembedded/_work/meta-openembedded/meta-openembedded/yoe/build/tmp/.3eg5fiid'
 is too long
Path must be less than 108 bytes

To avoid this, run qemu within tmpdir and use a relative path to the socket.
This avoids having to patch the socket code within qemu.

Update the client code to chdir and only use a relative path to the socket
to match.

Signed-off-by: Richard Purdie <[email protected]>
---
 meta/lib/oeqa/utils/qemurunner.py | 56 ++++++++++++++++++-------------
 1 file changed, 32 insertions(+), 24 deletions(-)

diff --git a/meta/lib/oeqa/utils/qemurunner.py 
b/meta/lib/oeqa/utils/qemurunner.py
index cb0be5603c0..3d3213d3d31 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -186,8 +186,10 @@ class QemuRunner:
         except:
             self.logger.error("qemurunner: qmp.py missing, please ensure it's 
installed")
             return False
-        qmp_port = self.tmpdir + "/." + next(tempfile._get_candidate_names())
-        qmp_param = ' -S -qmp unix:%s,server,wait' % (qmp_port)
+        # Path relative to tmpdir used as cwd for qemu below to avoid unix 
socket path length issues
+        qmp_file = "." + next(tempfile._get_candidate_names())
+        qmp_param = ' -S -qmp unix:./%s,server,wait' % (qmp_file)
+        qmp_port = self.tmpdir + "/" + qmp_file
 
         try:
             if self.serial_ports >= 2:
@@ -224,7 +226,7 @@ class QemuRunner:
         # blocking at the end of the runqemu script when using this within
         # oe-selftest (this makes stty error out immediately). There ought
         # to be a proper fix but this will suffice for now.
-        self.runqemu = subprocess.Popen(launch_cmd, shell=True, 
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, 
preexec_fn=os.setpgrp, env=env)
+        self.runqemu = subprocess.Popen(launch_cmd, shell=True, 
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, 
preexec_fn=os.setpgrp, env=env, cwd=self.tmpdir)
         output = self.runqemu.stdout
 
         #
@@ -287,31 +289,37 @@ class QemuRunner:
         # This will allow us to read status from Qemu if the the process
         # is still alive
         self.logger.debug("QMP Initializing to %s" % (qmp_port))
+        # chdir dance for path length issues with unix sockets
+        origpath = os.getcwd()
         try:
-            self.qmp = qmp.QEMUMonitorProtocol(qmp_port)
-        except OSError as msg:
-            self.logger.warning("Failed to initialize qemu monitor socket: %s 
File: %s" % (msg, msg.filename))
-            return False
+            os.chdir(os.path.dirname(qmp_port))
+            try:
+               self.qmp = qmp.QEMUMonitorProtocol(os.path.basename(qmp_port))
+            except OSError as msg:
+                self.logger.warning("Failed to initialize qemu monitor socket: 
%s File: %s" % (msg, msg.filename))
+                return False
 
-        self.logger.debug("QMP Connecting to %s" % (qmp_port))
-        if not os.path.exists(qmp_port) and self.is_alive():
-            self.logger.debug("QMP Port does not exist waiting for it to be 
created")
-            endtime = time.time() + self.runqemutime
-            while not os.path.exists(qmp_port) and self.is_alive() and 
time.time() < endtime:
-               self.logger.warning("QMP port does not exist yet!")
-               time.sleep(0.5)
+            self.logger.debug("QMP Connecting to %s" % (qmp_port))
             if not os.path.exists(qmp_port) and self.is_alive():
-                self.logger.warning("QMP Port still does not exist but QEMU is 
alive")
-                return False
+                self.logger.debug("QMP Port does not exist waiting for it to 
be created")
+                endtime = time.time() + self.runqemutime
+                while not os.path.exists(qmp_port) and self.is_alive() and 
time.time() < endtime:
+                   self.logger.warning("QMP port does not exist yet!")
+                   time.sleep(0.5)
+                if not os.path.exists(qmp_port) and self.is_alive():
+                    self.logger.warning("QMP Port still does not exist but 
QEMU is alive")
+                    return False
 
-        try:
-            self.qmp.connect()
-        except OSError as msg:
-            self.logger.warning("Failed to connect qemu monitor socket: %s 
File: %s" % (msg, msg.filename))
-            return False
-        except qmp.QMPConnectError as msg:
-            self.logger.warning("Failed to communicate with qemu monitor: %s" 
% (msg))
-            return False
+            try:
+                self.qmp.connect()
+            except OSError as msg:
+                self.logger.warning("Failed to connect qemu monitor socket: %s 
File: %s" % (msg, msg.filename))
+                return False
+            except qmp.QMPConnectError as msg:
+                self.logger.warning("Failed to communicate with qemu monitor: 
%s" % (msg))
+                return False
+        finally:
+            os.chdir(origpath)
 
         # Release the qemu porcess to continue running
         self.run_monitor('cont')
-- 
2.30.2

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#151380): 
https://lists.openembedded.org/g/openembedded-core/message/151380
Mute This Topic: https://lists.openembedded.org/mt/82625315/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to