]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: allow to pass EINVAL to unit_add_two_dependencies()
authorLuca Boccassi <bluca@debian.org>
Wed, 9 Aug 2023 12:59:22 +0000 (13:59 +0100)
committerLuca Boccassi <bluca@debian.org>
Fri, 11 Aug 2023 16:14:09 +0000 (17:14 +0100)
Useful to conditionally add two deps at a time

src/core/unit.c

index 6792bda9d01a6c22a659754e565a068e76e5acbd..0451a235099657dd0683f9ddf5366eae68e24115 100644 (file)
@@ -3291,17 +3291,22 @@ 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;
 }