From: Kamalesh Babulal Date: Mon, 13 Feb 2023 06:49:59 +0000 (+0000) Subject: python: binding to read and set systemd_default_cgroup X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0cf1f8fde9fb44eff1b6268418814c5cddd85515;p=thirdparty%2Flibcgroup.git python: binding to read and set systemd_default_cgroup Add an python binding that reads /run/libcgroup/systemd and if the file exists, sets the systemd_default_cgroup. Then on all the paths constructed, has the systemd_default_cgroup appended to it. This is used when cgroup sub-tree is constructed for systemd delegation. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka (cherry picked from commit 67805afc3f02495ab32fdc640f062c48b6e6b8f0) --- diff --git a/src/python/cgroup.pxd b/src/python/cgroup.pxd index 0f6e5502..b0106583 100644 --- a/src/python/cgroup.pxd +++ b/src/python/cgroup.pxd @@ -101,4 +101,5 @@ cdef extern from "libcgroup.h": int cgroup_create_scope2(cgroup *cgroup, int ignore_ownership, const cgroup_systemd_scope_opts * const opts) + void cgroup_set_default_systemd_cgroup() # vim: set et ts=4 sw=4: diff --git a/src/python/libcgroup.pyx b/src/python/libcgroup.pyx index ff4525c9..239ae168 100644 --- a/src/python/libcgroup.pyx +++ b/src/python/libcgroup.pyx @@ -505,6 +505,23 @@ cdef class Cgroup: if ret is not 0: raise RuntimeError("cgroup_create_scope2 failed: {}".format(ret)) + @staticmethod + def cgroup_set_default_systemd_cgroup(): + """Set systemd_default_cgroup + + Arguments: + None + + Description: + Reads /run/libcgroup/systemd and if the file exists, sets the + systemd_default_cgroup. Then on all the paths constructed, has + the systemd_default_cgroup appended to it. This is used when + cgroup sub-tree is constructed for systemd delegation. + """ + Cgroup.cgroup_init() + cgroup.cgroup_set_default_systemd_cgroup() + + def __dealloc__(self): cgroup.cgroup_free(&self._cgp);