From: Tom Hromatka Date: Fri, 19 May 2023 22:09:54 +0000 (-0600) Subject: python: Add support for NULL controllers[] in get_processes() X-Git-Tag: v3.1.0~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=411f56daf116032584f76f630eb9705fbf8ac67a;p=thirdparty%2Flibcgroup.git 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 --- 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)