From: Tom Hromatka Date: Thu, 25 May 2023 02:35:35 +0000 (-0600) Subject: python: Add method to clear the default slice/scope X-Git-Tag: v3.1.0~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8134c2ecd3351cfa035b9196c338a1832aceeef7;p=thirdparty%2Flibcgroup.git python: Add method to clear the default slice/scope 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 Reviewed-by: Kamalesh Babulal --- diff --git a/src/python/libcgroup.pyx b/src/python/libcgroup.pyx index e84df01f..2014815f 100644 --- a/src/python/libcgroup.pyx +++ b/src/python/libcgroup.pyx @@ -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