aboutsummaryrefslogtreecommitdiff
path: root/python/qemu/qmp
diff options
context:
space:
mode:
Diffstat (limited to 'python/qemu/qmp')
-rw-r--r--python/qemu/qmp/__init__.py21
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))]
+ )