summaryrefslogtreecommitdiff
path: root/linuxnamespaces/syscalls.py
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2024-05-20 06:30:19 +0200
committerHelmut Grohne <helmut@subdivi.de>2024-05-20 06:32:03 +0200
commit77383a70d81b91d5e0134941028e56a15d0a902c (patch)
tree6afd992b1053b77f38c65e7dc008d2be8906a0b5 /linuxnamespaces/syscalls.py
parent2d52326035411ed8e280e858bf2ece001a6d0cce (diff)
downloadpython-linuxnamespaces-77383a70d81b91d5e0134941028e56a15d0a902c.tar.gz
syscalls: use >= 3.10 support for eventfds in os module
Diffstat (limited to 'linuxnamespaces/syscalls.py')
-rw-r--r--linuxnamespaces/syscalls.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/linuxnamespaces/syscalls.py b/linuxnamespaces/syscalls.py
index 11800c6..9d2b1ba 100644
--- a/linuxnamespaces/syscalls.py
+++ b/linuxnamespaces/syscalls.py
@@ -73,9 +73,9 @@ class EventFDFlags(enum.IntFlag):
"""This value may be supplied as flags to eventfd(2)."""
NONE = 0
- CLOEXEC = 0o2000000
- NONBLOCK = 0o4000
- SEMAPHORE = 0o1
+ CLOEXEC = os.EFD_CLOEXEC
+ NONBLOCK = os.EFD_NONBLOCK
+ SEMAPHORE = os.EFD_SEMAPHORE
ALL_FLAGS = CLOEXEC | NONBLOCK | SEMAPHORE
@@ -438,15 +438,13 @@ class EventFD:
) -> None:
if flags & ~EventFDFlags.ALL_FLAGS:
raise ValueError("invalid flags for eventfd")
- self.fd = call_libc("eventfd", initval, int(flags))
+ self.fd = os.eventfd(initval, int(flags))
def read(self) -> int:
"""Decrease the value of the eventfd using eventfd_read."""
if self.fd < 0:
raise ValueError("attempt to read from closed eventfd")
- cvalue = ctypes.c_ulonglong()
- call_libc("eventfd_read", self.fd, ctypes.byref(cvalue))
- return cvalue.value
+ return os.eventfd_read(self.fd)
def __handle_readable(self, fd: int, fut: asyncio.Future[int]) -> None:
"""Internal helper of aread."""
@@ -481,9 +479,7 @@ class EventFD:
"""Add the given value to the eventfd using eventfd_write."""
if self.fd < 0:
raise ValueError("attempt to read from closed eventfd")
- if value < 0 or (value >> 64):
- raise ValueError("value for eventfd_write out of range")
- call_libc("eventfd_write", self.fd, ctypes.c_ulonglong(value))
+ os.eventfd_write(self.fd, value)
def fileno(self) -> int:
"""Return the underlying file descriptor."""