core: add IgnoreOnSoftReboot= unit option

As it says on the tin, configures the unit to survive a soft reboot.
Currently all the following options have to be set by hand:

Conflicts=reboot.target kexec.target poweroff.target halt.target
Before=reboot.target kexec.target poweroff.target halt.target
After=sysinit.target basic.target
DefaultDependencies=no
IgnoreOnIsolate=yes

This is not very user friendly. If new default dependencies are added,
or new shutdown/reboot types, they also have to be added manually.

The new option is much simpler, easy to find, and does the right thing
by default.
This commit is contained in:
Luca Boccassi
2023-07-21 18:05:41 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent 03d298e1e5
commit b80fc61e89
18 changed files with 166 additions and 52 deletions
+14 -2
View File
@@ -94,7 +94,12 @@ static int timer_add_default_dependencies(Timer *t) {
return r;
if (MANAGER_IS_SYSTEM(UNIT(t)->manager)) {
r = unit_add_two_dependencies_by_name(UNIT(t), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
r = unit_add_two_dependencies_by_name(UNIT(t),
UNIT_AFTER,
UNIT(t)->ignore_on_soft_reboot ? -EINVAL : UNIT_REQUIRES,
SPECIAL_SYSINIT_TARGET,
true,
UNIT_DEPENDENCY_DEFAULT);
if (r < 0)
return r;
@@ -112,7 +117,14 @@ static int timer_add_default_dependencies(Timer *t) {
}
}
return unit_add_two_dependencies_by_name(UNIT(t), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
if (!UNIT(t)->ignore_on_soft_reboot)
return unit_add_two_dependencies_by_name(
UNIT(t),
UNIT_BEFORE, UNIT_CONFLICTS,
SPECIAL_SHUTDOWN_TARGET, true,
UNIT_DEPENDENCY_DEFAULT);
return unit_add_dependencies_on_real_shutdown_targets(UNIT(t));
}
static int timer_add_trigger_dependencies(Timer *t) {