]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: port over to /supervisor/ subcgroup being delegated to nspawn
authorLennart Poettering <lennart@poettering.net>
Mon, 24 Apr 2023 08:19:28 +0000 (10:19 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 27 Apr 2023 10:18:32 +0000 (12:18 +0200)
Let's make use of the new DelegateSubgroup= feature and delegate the
/supervisor/ subcgroup already to nspawn, so that moving the supervisor
process there is unnecessary.

src/nspawn/nspawn-cgroup.c
units/systemd-nspawn@.service.in

index 0deb4ebb304b90285675babf46d5ed8423e47abe..a9d36627a86bed8eee47bf2e081425dc35c44c39 100644 (file)
@@ -141,9 +141,9 @@ finish:
 }
 
 int create_subcgroup(pid_t pid, bool keep_unit, CGroupUnified unified_requested) {
-        _cleanup_free_ char *cgroup = NULL;
+        _cleanup_free_ char *cgroup = NULL, *payload = NULL;
         CGroupMask supported;
-        const char *payload;
+        char *e;
         int r;
 
         assert(pid > 1);
@@ -174,15 +174,26 @@ int create_subcgroup(pid_t pid, bool keep_unit, CGroupUnified unified_requested)
         if (r < 0)
                 return log_error_errno(r, "Failed to get our control group: %m");
 
-        payload = strjoina(cgroup, "/payload");
+        /* If the service manager already placed us in the supervisor cgroup, let's handle that. */
+        e = endswith(cgroup, "/supervisor");
+        if (e)
+                *e = 0; /* chop off, we want the main path delegated to us */
+
+        payload = path_join(cgroup, "payload");
+        if (!payload)
+                return log_oom();
+
         r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, payload, pid);
         if (r < 0)
                 return log_error_errno(r, "Failed to create %s subcgroup: %m", payload);
 
         if (keep_unit) {
-                const char *supervisor;
+                _cleanup_free_ char *supervisor = NULL;
+
+                supervisor = path_join(cgroup, "supervisor");
+                if (!supervisor)
+                        return log_oom();
 
-                supervisor = strjoina(cgroup, "/supervisor");
                 r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, supervisor, 0);
                 if (r < 0)
                         return log_error_errno(r, "Failed to create %s subcgroup: %m", supervisor);
index e1626b9c872d976d613bfda1a4b647072797eb12..079d6064f631e69e2c37a60f610d5dae98ee8939 100644 (file)
@@ -25,6 +25,7 @@ RestartForceExitStatus=133
 SuccessExitStatus=133
 Slice=machine.slice
 Delegate=yes
+DelegateSubgroup=supervisor
 TasksMax=16384
 {{SERVICE_WATCHDOG}}