diff options
author | John Snow <jsnow@redhat.com> | 2021-09-22 20:49:30 -0400 |
---|---|---|
committer | John Snow <jsnow@redhat.com> | 2021-10-12 12:22:11 -0400 |
commit | 514d00df5f44f220d0b97cc71323275067d3e60e (patch) | |
tree | 92c31e0578fa5cf69793fb9b5db2870f9233786a /python/qemu/qmp | |
parent | d911accf0a88070120f7cc71c065fb797484d9b7 (diff) | |
download | qemu-514d00df5f44f220d0b97cc71323275067d3e60e.zip qemu-514d00df5f44f220d0b97cc71323275067d3e60e.tar.gz qemu-514d00df5f44f220d0b97cc71323275067d3e60e.tar.bz2 |
python/qmp: add send_fd_scm directly to QEMUMonitorProtocol
It turns out you can do this directly from Python ... and because of
this, you don't need to worry about setting the inheritability of the
fds or spawning another process.
Doing this is helpful because it allows QEMUMonitorProtocol to keep its
file descriptor and socket object as private implementation
details. /that/ is helpful in turn because it allows me to write a
compatible, alternative implementation.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 20210923004938.3999963-10-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
Diffstat (limited to 'python/qemu/qmp')
-rw-r--r-- | python/qemu/qmp/__init__.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/python/qemu/qmp/__init__.py b/python/qemu/qmp/__init__.py index c27594b..358c097 100644 --- a/python/qemu/qmp/__init__.py +++ b/python/qemu/qmp/__init__.py @@ -21,6 +21,7 @@ import errno import json import logging import socket +import struct from types import TracebackType from typing import ( Any, @@ -408,18 +409,14 @@ class QEMUMonitorProtocol: raise ValueError(msg) self.__sock.settimeout(timeout) - def get_sock_fd(self) -> int: + def send_fd_scm(self, fd: int) -> None: """ - Get the socket file descriptor. - - @return The file descriptor number. - """ - return self.__sock.fileno() - - def is_scm_available(self) -> bool: + Send a file descriptor to the remote via SCM_RIGHTS. """ - Check if the socket allows for SCM_RIGHTS. + if self.__sock.family != socket.AF_UNIX: + raise RuntimeError("Can't use SCM_RIGHTS on non-AF_UNIX socket.") - @return True if SCM_RIGHTS is available, otherwise False. - """ - return self.__sock.family == socket.AF_UNIX + self.__sock.sendmsg( + [b' '], + [(socket.SOL_SOCKET, socket.SCM_RIGHTS, struct.pack('@i', fd))] + ) |