From nobody Sun Sep 28 15:58:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758964361648457.6398707032573; Sat, 27 Sep 2025 02:12:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v2Qra-0004Mw-VC; Sat, 27 Sep 2025 05:05:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v2QrZ-0004Kz-EQ; Sat, 27 Sep 2025 05:05:05 -0400 Received: from isrv.corpit.ru ([212.248.84.144]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v2QrJ-0006w2-J3; Sat, 27 Sep 2025 05:05:03 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id DD86415855F; Sat, 27 Sep 2025 12:03:02 +0300 (MSK) Received: from think4mjt.origo (mjtthink.wg.tls.msk.ru [192.168.177.146]) by tsrv.corpit.ru (Postfix) with ESMTP id B9B3529157C; Sat, 27 Sep 2025 12:03:05 +0300 (MSK) From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Peter Delevoryas , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , John Snow , Michael Tokarev Subject: [Stable-7.2.21 10/16] python/machine: Fix AF_UNIX path too long on macOS Date: Sat, 27 Sep 2025 12:02:54 +0300 Message-ID: <20250927090304.2901324-10-mjt@tls.msk.ru> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=212.248.84.144; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1758964362927116600 From: Peter Delevoryas On macOS, private $TMPDIR's are the default. These $TMPDIR's are generated from a user's unix UID and UUID [1], which can create a relatively long path: /var/folders/d7/rz20f6hd709c1ty8f6_6y_z40000gn/T/ QEMU's avocado tests create a temporary directory prefixed by "avo_qemu_sock_", and create QMP sockets within _that_ as well. The QMP socket is unnecessarily long, because a temporary directory is created for every QEMUMachine object. /avo_qemu_sock_uh3w_dgc/qemu-37331-10bacf110-monitor.sock The path limit for unix sockets on macOS is 104: [2] /* * [XSI] Definitions for UNIX IPC domain. */ struct sockaddr_un { unsigned char sun_len; /* sockaddr len including null */ sa_family_t sun_family; /* [XSI] AF_UNIX */ char sun_path[104]; /* [XSI] path name (gag) */ }; This results in avocado tests failing on macOS because the QMP unix socket can't be created, because the path is too long: ERROR| Failed to establish connection: OSError: AF_UNIX path too long This change resolves by reducing the size of the socket directory prefix and the suffix on the QMP and console socket names. The result is paths like this: pdel@pdel-mbp:/var/folders/d7/rz20f6hd709c1ty8f6_6y_z40000gn/T $ tree qemu* qemu_df4evjeq qemu_jbxel3gy qemu_ml9s_gg7 qemu_oc7h7f3u qemu_oqb1yf97 =E2=94=9C=E2=94=80=E2=94=80 10a004050.con =E2=94=94=E2=94=80=E2=94=80 10a004050.qmp [1] https://apple.stackexchange.com/questions/353832/why-is-mac-osx-temp-di= rectory-in-weird-path [2] /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include/sys= /un.h Signed-off-by: Peter Delevoryas Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20230110082930.42129-2-peter@pjd.dev Signed-off-by: John Snow (cherry picked from commit f9922937d173f50fe59fd1b20fadc445fb6b2564) (Mjt: pick this simple fix for 7.2.x so subsequent changes applies cleanly) Signed-off-by: Michael Tokarev diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index 37191f433b..5df210c810 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -157,7 +157,7 @@ def __init__(self, self._wrapper =3D wrapper self._qmp_timer =3D qmp_timer =20 - self._name =3D name or f"qemu-{os.getpid()}-{id(self):02x}" + self._name =3D name or f"{id(self):x}" self._temp_dir: Optional[str] =3D None self._base_temp_dir =3D base_temp_dir self._sock_dir =3D sock_dir @@ -167,7 +167,7 @@ def __init__(self, self._monitor_address =3D monitor_address else: self._monitor_address =3D os.path.join( - self.sock_dir, f"{self._name}-monitor.sock" + self.sock_dir, f"{self._name}.qmp" ) =20 self._console_log_path =3D console_log @@ -192,7 +192,7 @@ def __init__(self, self._console_set =3D False self._console_device_type: Optional[str] =3D None self._console_address =3D os.path.join( - self.sock_dir, f"{self._name}-console.sock" + self.sock_dir, f"{self._name}.con" ) self._console_socket: Optional[socket.socket] =3D None self._remove_files: List[str] =3D [] diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado= _qemu/__init__.py index 910f3ba1ea..25a546842f 100644 --- a/tests/avocado/avocado_qemu/__init__.py +++ b/tests/avocado/avocado_qemu/__init__.py @@ -306,7 +306,7 @@ def require_netdev(self, netdevname): self.cancel('no support for user networking') =20 def _new_vm(self, name, *args): - self._sd =3D tempfile.TemporaryDirectory(prefix=3D"avo_qemu_sock_") + self._sd =3D tempfile.TemporaryDirectory(prefix=3D"qemu_") vm =3D QEMUMachine(self.qemu_bin, base_temp_dir=3Dself.workdir, sock_dir=3Dself._sd.name, log_dir=3Dself.logdir) self.log.debug('QEMUMachine "%s" created', name) --=20 2.47.3