]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: set "trusted.delegate" xattr on cgroups that are delegation boundaries
authorLennart Poettering <lennart@poettering.net>
Wed, 20 Nov 2019 16:42:02 +0000 (17:42 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 20 Nov 2019 16:50:12 +0000 (17:50 +0100)
Let's mark cgroups that are delegation boundaries to us. This can then
be used by tools such as "systemd-cgls" to show where the next manager
takes over.

src/core/cgroup.c

index b7718e19667c0b4a5b98f3527ec0a82d08b8ffb9..abcd057d6a3d656dd6b77d4d13abddaabcf5cbf5 100644 (file)
@@ -617,15 +617,27 @@ static void cgroup_xattr_apply(Unit *u) {
         if (!MANAGER_IS_SYSTEM(u->manager))
                 return;
 
-        if (sd_id128_is_null(u->invocation_id))
-                return;
+        if (!sd_id128_is_null(u->invocation_id)) {
+                r = cg_set_xattr(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path,
+                                 "trusted.invocation_id",
+                                 sd_id128_to_string(u->invocation_id, ids), 32,
+                                 0);
+                if (r < 0)
+                        log_unit_debug_errno(u, r, "Failed to set invocation ID on control group %s, ignoring: %m", u->cgroup_path);
+        }
 
-        r = cg_set_xattr(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path,
-                         "trusted.invocation_id",
-                         sd_id128_to_string(u->invocation_id, ids), 32,
-                         0);
-        if (r < 0)
-                log_unit_debug_errno(u, r, "Failed to set invocation ID on control group %s, ignoring: %m", u->cgroup_path);
+        if (unit_cgroup_delegate(u)) {
+                r = cg_set_xattr(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path,
+                                 "trusted.delegate",
+                                 "1", 1,
+                                 0);
+                if (r < 0)
+                        log_unit_debug_errno(u, r, "Failed to set delegate flag on control group %s, ignoring: %m", u->cgroup_path);
+        } else {
+                r = cg_remove_xattr(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path, "trusted.delegate");
+                if (r != -ENODATA)
+                        log_unit_debug_errno(u, r, "Failed to remove delegate flag on control group %s, ignoring: %m", u->cgroup_path);
+        }
 }
 
 static int lookup_block_device(const char *p, dev_t *ret) {