core: do not set up cgroup runtime on coldplug

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.
This commit is contained in:
Mike Yuan 2024-06-05 20:45:12 +02:00
parent 8d178f702d
commit f26b2ec461
No known key found for this signature in database
GPG key ID: 417471C0A40F58B3
3 changed files with 2 additions and 7 deletions

View 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;

View 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))

View 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;