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
+9 -10
View File
@@ -131,23 +131,22 @@ static void scope_set_state(Scope *s, ScopeState state) {
}
static int scope_add_default_dependencies(Scope *s) {
int r;
assert(s);
if (!UNIT(s)->default_dependencies)
return 0;
/* Make sure scopes are unloaded on shutdown */
r = unit_add_two_dependencies_by_name(
UNIT(s),
UNIT_BEFORE, UNIT_CONFLICTS,
SPECIAL_SHUTDOWN_TARGET, true,
UNIT_DEPENDENCY_DEFAULT);
if (r < 0)
return r;
if (!UNIT(s)->ignore_on_soft_reboot)
return unit_add_two_dependencies_by_name(
UNIT(s),
UNIT_BEFORE, UNIT_CONFLICTS,
SPECIAL_SHUTDOWN_TARGET, true,
UNIT_DEPENDENCY_DEFAULT);
return 0;
/* Unless we are meant to survive soft reboot, in which case we need to conflict with
* non-soft-reboot targets. */
return unit_add_dependencies_on_real_shutdown_targets(UNIT(s));
}
static int scope_verify(Scope *s) {