From 1505d67efe3457a041a29e7a6516d1d0173833ef Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 11 Feb 2026 23:24:12 +0100 Subject: [PATCH] sandbox: Use os.eventfd() Available since Python 3.10. --- mkosi/sandbox.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mkosi/sandbox.py b/mkosi/sandbox.py index 4efc24ad2..c2a34e66c 100755 --- a/mkosi/sandbox.py +++ b/mkosi/sandbox.py @@ -132,7 +132,6 @@ libc = ctypes.CDLL(None, use_errno=True) libc.syscall.restype = ctypes.c_long libc.unshare.argtypes = (ctypes.c_int,) libc.statfs.argtypes = (ctypes.c_char_p, ctypes.c_void_p) -libc.eventfd.argtypes = (ctypes.c_int, ctypes.c_int) libc.mount.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_char_p) libc.pivot_root.argtypes = (ctypes.c_char_p, ctypes.c_char_p) libc.umount2.argtypes = (ctypes.c_char_p, ctypes.c_int) @@ -575,15 +574,13 @@ def become_user(uid: int, gid: int) -> None: ppid = os.getpid() - event = libc.eventfd(0, 0) - if event < 0: - oserror("eventfd") + event = os.eventfd(0, os.EFD_CLOEXEC) with close(event): pid = os.fork() if pid == 0: try: - os.read(event, ctypes.sizeof(ctypes.c_uint64)) + os.eventfd_read(event) os.close(event) with open(f"/proc/{ppid}/setgroups", "wb") as f: f.write(b"deny\n") @@ -605,7 +602,7 @@ def become_user(uid: int, gid: int) -> None: print(UNSHARE_EPERM_MSG, file=sys.stderr) raise finally: - os.write(event, ctypes.c_uint64(1)) + os.eventfd_write(event, 1) _, status = os.waitpid(pid, 0) rc = os.waitstatus_to_exitcode(status) -- 2.47.3