]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/core/unit.c
core: add IgnoreOnSoftReboot= unit option
[thirdparty/systemd.git] / src / core / unit.c
index 6792bda9d01a6c22a659754e565a068e76e5acbd..468b193acd57fca1b67955270e31a34ce390c31d 100644 (file)
@@ -3291,21 +3291,48 @@ 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);
 
-        r = unit_add_dependency(u, d, other, add_reference, mask);
-        if (r < 0)
-                return r;
+        if (d >= 0) {
+                r = unit_add_dependency(u, d, other, add_reference, mask);
+                if (r < 0)
+                        return r;
+        }
 
-        s = unit_add_dependency(u, e, other, add_reference, mask);
-        if (s < 0)
-                return s;
+        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);
+
+        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;
+        }
+
+        return 0;
+}
+
 static int resolve_template(Unit *u, const char *name, char **buf, const char **ret) {
         int r;