From 411f56daf116032584f76f630eb9705fbf8ac67a Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Fri, 19 May 2023 16:09:54 -0600 Subject: [PATCH] python: Add support for NULL controllers[] in get_processes() 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 Reviewed-by: Kamalesh Babulal --- src/python/libcgroup.pyx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/python/libcgroup.pyx b/src/python/libcgroup.pyx index f23bd6c3..76371443 100644 --- a/src/python/libcgroup.pyx +++ b/src/python/libcgroup.pyx @@ -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) -- 2.47.2