From: Kamalesh Babulal Date: Mon, 11 Mar 2024 03:37:19 +0000 (+0530) Subject: src/python: add attach_threads option to attach() X-Git-Tag: v3.2.0~126 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c378847be688a6a2af6bb0e8e074db10dded0ea3;p=thirdparty%2Flibcgroup.git src/python: add attach_threads option to attach() Add support to move all threads by writing a tid into cgroups cgroup.procs for the cgroup v1 controller, when attach_threads option in the attach() is set, by default its false. When set, it calls cgroup_attach_thread_tid(). Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/python/cgroup.pxd.m4 b/src/python/cgroup.pxd.m4 index 29ace69a..0ab34c6d 100644 --- a/src/python/cgroup.pxd.m4 +++ b/src/python/cgroup.pxd.m4 @@ -133,4 +133,6 @@ cdef extern from "libcgroup.h": bool cgroup_is_systemd_enabled() + int cgroup_attach_thread_tid(cgroup * cgroup, pid_t tid) + # vim: set et ts=4 sw=4: diff --git a/src/python/libcgroup.pyx.m4 b/src/python/libcgroup.pyx.m4 index 6b5da587..faf9c94e 100644 --- a/src/python/libcgroup.pyx.m4 +++ b/src/python/libcgroup.pyx.m4 @@ -470,12 +470,14 @@ cdef class Cgroup: if ret is not 0: raise RuntimeError("cgroup_delete_cgroup failed: {}".`format'(ret)) - def attach(self, pid=None, root_cgroup=False): + def attach(self, pid=None, root_cgroup=False, attach_threads=False): """Attach a process to a cgroup Arguments: pid - pid to be attached. If none, then the current pid is attached root_cgroup - if True, then the pid will be attached to the root cgroup + attach_threads - if True, pid will be written in cgroup.procs (v1) + Description: Attach a process to a cgroup @@ -486,10 +488,16 @@ cdef class Cgroup: else: ret = cgroup.cgroup_attach_task(self._cgp) else: - if root_cgroup: - ret = cgroup.cgroup_attach_task_pid(NULL, pid) + if attach_threads: + if root_cgroup: + ret = cgroup.cgroup_attach_thread_tid(NULL, pid) + else: + ret = cgroup.cgroup_attach_thread_tid(self._cgp, pid) else: - ret = cgroup.cgroup_attach_task_pid(self._cgp, pid) + if root_cgroup: + ret = cgroup.cgroup_attach_task_pid(NULL, pid) + else: + ret = cgroup.cgroup_attach_task_pid(self._cgp, pid) if ret is not 0: raise RuntimeError("cgroup_attach_task failed: {}".`format'(ret))