unshare: Add bindings for unshare(2)
This commit is contained in:
35
src/linuxapi/unshare.py
Normal file
35
src/linuxapi/unshare.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import ctypes.util
|
||||
import os
|
||||
|
||||
|
||||
_libc = ctypes.CDLL(ctypes.util.find_library('c'))
|
||||
|
||||
_errno = _libc.__errno_location
|
||||
_errno.restype = ctypes.POINTER(ctypes.c_int)
|
||||
|
||||
_libc.unshare.argtypes = (ctypes.c_int,)
|
||||
_libc.unshare_restype = ctypes.c_int
|
||||
|
||||
|
||||
CLONE_FILES = 0x00000400
|
||||
CLONE_FS = 0x00000200
|
||||
CLONE_NEWIPC = 0x08000000
|
||||
CLONE_NEWNET = 0x40000000
|
||||
CLONE_NEWNS = 0x00020000
|
||||
CLONE_NEWPID = 0x20000000
|
||||
CLONE_NEWUSER = 0x10000000
|
||||
CLONE_NEWUTS = 0x04000000
|
||||
CLONE_SYSVSEM = 0x00040000
|
||||
|
||||
|
||||
class UnshareError(OSError):
|
||||
|
||||
@classmethod
|
||||
def from_c_err(cls):
|
||||
errno = _errno().contents.value
|
||||
return cls(errno, os.strerror(errno))
|
||||
|
||||
|
||||
def unshare(flags):
|
||||
if _libc.unshare(flags) != 0:
|
||||
raise UnshareError.from_c_err()
|
||||
Reference in New Issue
Block a user