]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
python: Add support for NULL controllers[] in get_processes()
authorTom Hromatka <tom.hromatka@oracle.com>
Fri, 19 May 2023 22:09:54 +0000 (16:09 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 3 Jul 2023 14:58:50 +0000 (08:58 -0600)
Add support for an empty controllers list in the Python bindings.
The python method, get_processes(), will then send in a NULL pointer
in the controllers field into the C function cgroup_get_procs().

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

index f23bd6c34b709f411e5bef4aa78b508d83ef96d4..763714430f5ba6eaffa438a65b46fa67fa5a4a90 100644 (file)
@@ -679,6 +679,14 @@ cdef class Cgroup:
         cdef pid_t *pids
         cdef int size
 
+        if len(self.controllers) == 0:
+            ret = cgroup.cgroup_get_procs(c_str(self.name), NULL, &pids, &size)
+            if ret is not 0:
+                raise RuntimeError("cgroup_get_procs failed: {}".format(ret))
+
+            for i in range(0, size):
+                pid_list.append(int(pids[i]))
+
         for ctrl_key in self.controllers:
             ret = cgroup.cgroup_get_procs(c_str(self.name),
                         c_str(self.controllers[ctrl_key].name), &pids, &size)