]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
unit: make unit_can_start() more accurate
authorLennart Poettering <lennart@poettering.net>
Sat, 5 Sep 2015 18:21:46 +0000 (20:21 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 5 Sep 2015 18:27:52 +0000 (20:27 +0200)
This funciton is exposed via CanStart on the bus, and should be as
accurate as possible. Hence: make sure to return false for units of unit
types not supported on the system, and for unit types where
configuration failed to load.

Also see #1105.

src/core/unit.c

index a5714adf3850801026bdf6928fea28fc0fac7a60..45ce1b172df929213e2b024c531fc63093b2def5 100644 (file)
@@ -1416,9 +1416,14 @@ int unit_start(Unit *u) {
 
         assert(u);
 
+        /* Units that aren't loaded cannot be started */
         if (u->load_state != UNIT_LOADED)
                 return -EINVAL;
 
+        /* Units of types that aren't supported annot be started either */
+        if (!unit_supported(u))
+                return -EOPNOTSUPP;
+
         /* If this is already started, then this will succeed. Note
          * that this will even succeed if this unit is not startable
          * by the user. This is relied on to detect when we need to
@@ -1451,9 +1456,6 @@ int unit_start(Unit *u) {
                 return unit_start(following);
         }
 
-        if (!unit_supported(u))
-                return -EOPNOTSUPP;
-
         /* If it is stopped, but we cannot start it, then fail */
         if (!UNIT_VTABLE(u)->start)
                 return -EBADR;
@@ -1472,6 +1474,12 @@ int unit_start(Unit *u) {
 bool unit_can_start(Unit *u) {
         assert(u);
 
+        if (u->load_state != UNIT_LOADED)
+                return false;
+
+        if (!unit_supported(u))
+                return false;
+
         return !!UNIT_VTABLE(u)->start;
 }