chiark / gitweb /
manager: run ctrl-alt-del/kbrequest targets on SIGINT/SIGWINCH when run in init mode
[elogind.git] / unit.c
diff --git a/unit.c b/unit.c
index c27e4ec902c74ed793b5f9fbaf1837900ad75c1c..b8a1d8bb338259a1edac08b5199f4db409831013 100644 (file)
--- a/unit.c
+++ b/unit.c
@@ -478,13 +478,18 @@ int unit_start(Unit *u) {
 
         assert(u);
 
-        if (!UNIT_VTABLE(u)->start)
-                return -EBADR;
-
+        /* If this is already (being) 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 wait for units and when waiting is finished. */
         state = unit_active_state(u);
         if (UNIT_IS_ACTIVE_OR_RELOADING(state))
                 return -EALREADY;
 
+        /* If it is stopped, but we cannot start it, then fail */
+        if (!UNIT_VTABLE(u)->start)
+                return -EBADR;
+
         /* We don't suppress calls to ->start() here when we are
          * already starting, to allow this request to be used as a
          * "hurry up" call, for example when the unit is in some "auto
@@ -511,13 +516,13 @@ int unit_stop(Unit *u) {
 
         assert(u);
 
-        if (!UNIT_VTABLE(u)->stop)
-                return -EBADR;
-
         state = unit_active_state(u);
         if (state == UNIT_INACTIVE)
                 return -EALREADY;
 
+        if (!UNIT_VTABLE(u)->stop)
+                return -EBADR;
+
         if (state == UNIT_DEACTIVATING)
                 return 0;
 
@@ -967,16 +972,6 @@ int unit_add_dependency_by_name(Unit *u, UnitDependency d, const char *name) {
         return 0;
 }
 
-const char *unit_path(void) {
-        char *e;
-
-        if ((e = getenv("UNIT_PATH")))
-                if (path_is_absolute(e))
-                    return e;
-
-        return UNIT_PATH;
-}
-
 int set_unit_path(const char *p) {
         char *cwd, *c;
         int r;
@@ -997,7 +992,7 @@ int set_unit_path(const char *p) {
                         return -ENOMEM;
         }
 
-        if (setenv("UNIT_PATH", c, 0) < 0) {
+        if (setenv("SYSTEMD_UNIT_PATH", c, 0) < 0) {
                 r = -errno;
                 free(c);
                 return r;