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
+36 -9
View File
@@ -3291,19 +3291,46 @@ int unit_add_dependency(
}
int unit_add_two_dependencies(Unit *u, UnitDependency d, UnitDependency e, Unit *other, bool add_reference, UnitDependencyMask mask) {
int r, s;
int r = 0, s = 0;
assert(u);
assert(d >= 0 || e >= 0);
if (d >= 0) {
r = unit_add_dependency(u, d, other, add_reference, mask);
if (r < 0)
return r;
}
if (e >= 0) {
s = unit_add_dependency(u, e, other, add_reference, mask);
if (s < 0)
return s;
}
return r > 0 || s > 0;
}
int unit_add_dependencies_on_real_shutdown_targets(Unit *u) {
int r;
assert(u);
r = unit_add_dependency(u, d, other, add_reference, mask);
if (r < 0)
return r;
STRV_FOREACH(target, STRV_MAKE(SPECIAL_REBOOT_TARGET,
SPECIAL_KEXEC_TARGET,
SPECIAL_HALT_TARGET,
SPECIAL_POWEROFF_TARGET)) {
r = unit_add_two_dependencies_by_name(u,
UNIT_BEFORE,
UNIT_CONFLICTS,
*target,
/* add_reference= */ true,
UNIT_DEPENDENCY_DEFAULT);
if (r < 0)
return r;
}
s = unit_add_dependency(u, e, other, add_reference, mask);
if (s < 0)
return s;
return r > 0 || s > 0;
return 0;
}
static int resolve_template(Unit *u, const char *name, char **buf, const char **ret) {