]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
python: Add bindings for cgroup_change_cgroup_path()
authorTom Hromatka <tom.hromatka@oracle.com>
Wed, 17 May 2023 20:49:31 +0000 (14:49 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 23 May 2023 21:43:08 +0000 (15:43 -0600)
Add python bindings for cgroup_change_cgroup_path().  Note
that the bindings currently only support cgroup v2 (unified)
systems.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
src/python/cgroup.pxd
src/python/libcgroup.pyx

index 7f011de26ec2687e2b215d1f46fcacc40f9d2df7..ec32603291b98c8d0fc490e9f520748e288c9676 100644 (file)
@@ -117,4 +117,6 @@ cdef extern from "libcgroup.h":
 
     int cgroup_get_current_controller_path(pid_t pid, const char *controller,
                                            char **current_path)
+
+    int cgroup_change_cgroup_path(const char *dest, pid_t pid, const char * const controllers[])
 # vim: set et ts=4 sw=4:
index bab157e295d274dff58676cd8903a3bb8fd4f81f..aa5484b8828a8aec4304a842166c94e2d7a4f288 100644 (file)
@@ -689,6 +689,27 @@ cdef class Cgroup:
 
         return current_path.decode('ascii')
 
+    @staticmethod
+    def move_process(pid, dest_cgname):
+        """Move a process to the specified cgroup
+
+        Return:
+        None
+
+        Description:
+        Invokes the libcgroup C function, cgroup_change_cgroup_path().
+        It moves a process to the specified cgroup dest_cgname.
+
+        Note:
+        * Writes to the cgroup sysfs
+        * Only works on cgroup v2 (unified) hierarchies
+        """
+        ret = cgroup.cgroup_change_cgroup_path(c_str(dest_cgname), pid, NULL)
+
+        if ret is not 0:
+            raise RuntimeError("cgroup_change_cgroup_path failed :"
+                               "{}".format(ret))
+
     def __dealloc__(self):
         cgroup.cgroup_free(&self._cgp);