]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
sandbox: Use os.eventfd() 4158/head
authorDaan De Meyer <daan@amutable.com>
Wed, 11 Feb 2026 22:24:12 +0000 (23:24 +0100)
committerDaan De Meyer <daan@amutable.com>
Wed, 11 Feb 2026 22:26:34 +0000 (23:26 +0100)
Available since Python 3.10.

mkosi/sandbox.py

index 4efc24ad244ac752460903bfb1fbe33b38b01344..c2a34e66c873d4b4fc56c7b2d118d8e98c8c22c7 100755 (executable)
@@ -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)