aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/nstools/nstools.pyx
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@ydb.tech>2023-11-30 13:26:22 +0300
committervitalyisaev <vitalyisaev@ydb.tech>2023-11-30 15:44:45 +0300
commit0a98fece5a9b54f16afeb3a94b3eb3105e9c3962 (patch)
tree291d72dbd7e9865399f668c84d11ed86fb190bbf /library/python/nstools/nstools.pyx
parentcb2c8d75065e5b3c47094067cb4aa407d4813298 (diff)
downloadydb-0a98fece5a9b54f16afeb3a94b3eb3105e9c3962.tar.gz
YQ Connector:Use docker-compose in integrational tests
Diffstat (limited to 'library/python/nstools/nstools.pyx')
-rw-r--r--library/python/nstools/nstools.pyx28
1 files changed, 28 insertions, 0 deletions
diff --git a/library/python/nstools/nstools.pyx b/library/python/nstools/nstools.pyx
new file mode 100644
index 0000000000..5ef30373ff
--- /dev/null
+++ b/library/python/nstools/nstools.pyx
@@ -0,0 +1,28 @@
+from cpython.exc cimport PyErr_SetFromErrno
+
+cdef extern from "<sched.h>" nogil:
+ int setns(int fd, int mode)
+ int unshare(int flags)
+
+ cpdef enum:
+ Fs "CLONE_FS"
+ # Cgroup "CLONE_NEWCGROUP"
+ Ipc "CLONE_NEWIPC"
+ Network "CLONE_NEWNET"
+ Mount "CLONE_NEWNS"
+ Pid "CLONE_NEWPID"
+ User "CLONE_NEWUSER"
+ Uts "CLONE_NEWUTS"
+
+def unshare_ns(int flags):
+ cdef int ret = unshare(flags)
+ if ret != 0:
+ PyErr_SetFromErrno(OSError)
+
+def move_to_ns(object fileobject, int mode):
+ if not isinstance(fileobject, int):
+ fileobject = fileobject.fileno()
+
+ cdef int ret = setns(fileobject, mode)
+ if ret != 0:
+ PyErr_SetFromErrno(OSError)