python/aqmp: fix send_fd_scm for python 3.6.x
authorJohn Snow <jsnow@redhat.com>
Thu, 18 Nov 2021 20:46:20 +0000 (15:46 -0500)
committerJohn Snow <jsnow@redhat.com>
Mon, 22 Nov 2021 23:41:21 +0000 (18:41 -0500)
3.6 doesn't play keepaway with the socket object, so we don't need to go
fishing for it on this version. In fact, so long as 'sendmsg' is still
available, it's probably preferable to just use that method and only go
fishing for forbidden details when we absolutely have to.

Reported-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Willian Rampazzo <willianr@redhat.com>
Message-id: 20211118204620.1897674-8-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
python/qemu/aqmp/qmp_client.py

index f987da02eb0a3aa73b09b08ea76108bc0f0f1f91..8105e29fa8f04297ec9390ec25ea518298e76639 100644 (file)
@@ -639,9 +639,12 @@ class QMPClient(AsyncProtocol[Message], Events):
         if sock.family != socket.AF_UNIX:
             raise AQMPError("Sending file descriptors requires a UNIX socket.")
 
-        # Void the warranty sticker.
-        # Access to sendmsg in asyncio is scheduled for removal in Python 3.11.
-        sock = sock._sock  # pylint: disable=protected-access
+        if not hasattr(sock, 'sendmsg'):
+            # We need to void the warranty sticker.
+            # Access to sendmsg is scheduled for removal in Python 3.11.
+            # Find the real backing socket to use it anyway.
+            sock = sock._sock  # pylint: disable=protected-access
+
         sock.sendmsg(
             [b' '],
             [(socket.SOL_SOCKET, socket.SCM_RIGHTS, struct.pack('@i', fd))]