]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: do not set up cgroup runtime on coldplug 33258/head
authorMike Yuan <me@yhndnzj.com>
Wed, 5 Jun 2024 18:45:12 +0000 (20:45 +0200)
committerMike Yuan <me@yhndnzj.com>
Fri, 28 Jun 2024 13:43:21 +0000 (15:43 +0200)
Currently, unit_setup_cgroup_runtime() is called in
various _coldplug() functions if the unit is not inactive.
That seems unnecessary though, and kinda defeats the purpose
of CGroupRuntime. If we need to fork off a process for the unit
or got something during deserialization, the CGroupRuntime
would be automatically set up by unit_prepare_exec() /
cgroup_runtime_deserialize_one(). Otherwise it would mean
the cgroup doesn't exist and we don't need to allocate
that in the first place.

Plus, note that socket units might also carry a cgroup with
ExecStartPre=/ExecStartPost=/... Hence the existing code
is really inconsistent.

src/core/mount.c
src/core/service.c
src/core/swap.c

index c6100b0b0a0ed9e33b00e688f36163dd65371593..e040f151f42b8c86c511818d5473c0397338ba26 100644 (file)
@@ -764,10 +764,8 @@ static int mount_coldplug(Unit *u) {
                         return r;
         }
 
-        if (!IN_SET(m->deserialized_state, MOUNT_DEAD, MOUNT_FAILED)) {
+        if (!IN_SET(m->deserialized_state, MOUNT_DEAD, MOUNT_FAILED))
                 (void) unit_setup_exec_runtime(u);
-                (void) unit_setup_cgroup_runtime(u);
-        }
 
         mount_set_state(m, m->deserialized_state);
         return 0;
index 937729cd068740bc99201f749af5f08b433937a9..9af10df0cd80a6b6a33fb951cd81cbac3155884d 100644 (file)
@@ -1366,7 +1366,6 @@ static int service_coldplug(Unit *u) {
                     SERVICE_DEAD_RESOURCES_PINNED)) {
                 (void) unit_enqueue_rewatch_pids(u);
                 (void) unit_setup_exec_runtime(u);
-                (void) unit_setup_cgroup_runtime(u);
         }
 
         if (IN_SET(s->deserialized_state, SERVICE_START_POST, SERVICE_RUNNING, SERVICE_RELOAD, SERVICE_RELOAD_SIGNAL, SERVICE_RELOAD_NOTIFY))
index c4d2ba8f3acb5aa7395105f966cf95ae7008212d..e6f6f78dc9c355046da7c8d4aea5839a2fd78c15 100644 (file)
@@ -548,10 +548,8 @@ static int swap_coldplug(Unit *u) {
                         return r;
         }
 
-        if (!IN_SET(new_state, SWAP_DEAD, SWAP_FAILED)) {
+        if (!IN_SET(new_state, SWAP_DEAD, SWAP_FAILED))
                 (void) unit_setup_exec_runtime(u);
-                (void) unit_setup_cgroup_runtime(u);
-        }
 
         swap_set_state(s, new_state);
         return 0;