]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
python: binding to read and set systemd_default_cgroup
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Mon, 13 Feb 2023 06:49:59 +0000 (06:49 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 16 Feb 2023 19:25:11 +0000 (12:25 -0700)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 67805afc3f02495ab32fdc640f062c48b6e6b8f0)

src/python/cgroup.pxd
src/python/libcgroup.pyx

index 0f6e5502f9961f4cd55c42e55b27f9449522dd27..b010658381c813a6a6dbea341dc47930add48c53 100644 (file)
@@ -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:
index ff4525c9f32601703b8348bfe98c4ad464ad62f3..239ae16830d8e21b085e63d4986248ad03768815 100644 (file)
@@ -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);