]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
python: Add method to clear the default slice/scope
authorTom Hromatka <tom.hromatka@oracle.com>
Thu, 25 May 2023 02:35:35 +0000 (20:35 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 3 Jul 2023 14:50:48 +0000 (08:50 -0600)
Add a convenience method to clear the default slice/scope.  This may be
useful in cases where the user is done with the slice/scope and wants to
resume operating at the root cgroup level.

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

index e84df01f01b82466f39f4907819814ffb552b457..2014815fffb85ae384effb6f862785bdc3a11d40 100644 (file)
@@ -616,6 +616,25 @@ cdef class Cgroup:
         if set_default:
             Cgroup.__set_default_systemd_cgroup()
 
+    @staticmethod
+    def clear_default_systemd_scope():
+        """Clear/Remove the default slice/scope from libcgroup
+
+        Description:
+        Delete the default slice/scope from the libcgroup var/run file.
+        Also delete the internal global variable within libcgroup so that
+        the default path is restored back to the root cgroup
+        """
+        try:
+            Cgroup.write_default_systemd_scope('', '', set_default=False)
+        except RuntimeError:
+            pass
+
+        try:
+            Cgroup.__set_default_systemd_cgroup()
+        except RuntimeError:
+            pass
+
     cdef compare(self, Cgroup other):
         """Compare this cgroup instance with another cgroup instance