chiark / gitweb /
systemctl: show sub state along active state
[elogind.git] / service.c
index a7af4fdeea175ad35bfc96310020153e964fabda..74e8019bd194eddd804bd7aa143bf416c7e5bfec 100644 (file)
--- a/service.c
+++ b/service.c
@@ -623,6 +623,10 @@ static int service_load_sysv_path(Service *s, const char *path) {
         /* Special setting for all SysV services */
         s->valid_no_process = true;
 
+        /* Don't timeout special services during boot (like fsck) */
+        if (s->sysv_runlevels && !chars_intersect("12345", s->sysv_runlevels))
+                s->timeout_usec = -1;
+
         u->meta.load_state = UNIT_LOADED;
         r = 0;
 
@@ -726,6 +730,20 @@ static void service_init(Unit *u) {
         RATELIMIT_INIT(s->ratelimit, 10*USEC_PER_SEC, 5);
 }
 
+static int service_verify(Service *s) {
+        assert(s);
+
+        if (UNIT(s)->meta.load_state != UNIT_LOADED)
+                return 0;
+
+        if (!s->exec_command[SERVICE_EXEC_START]) {
+                log_error("%s lacks ExecStart setting. Refusing.", unit_id(UNIT(s)));
+                return -EINVAL;
+        }
+
+        return 0;
+}
+
 static int service_load(Unit *u) {
         int r;
         Service *s = SERVICE(u);
@@ -762,7 +780,7 @@ static int service_load(Unit *u) {
                         return r;
         }
 
-        return 0;
+        return service_verify(s);
 }
 
 static void service_dump(Unit *u, FILE *f, const char *prefix) {
@@ -1447,11 +1465,12 @@ static void service_enter_restart(Service *s) {
         int r;
         assert(s);
 
+        service_enter_dead(s, true, false);
+
         if ((r = manager_add_job(UNIT(s)->meta.manager, JOB_START, UNIT(s), JOB_FAIL, false, NULL)) < 0)
                 goto fail;
 
         log_debug("%s scheduled restart job.", unit_id(UNIT(s)));
-        service_enter_dead(s, true, false);
         return;
 
 fail:
@@ -1619,6 +1638,12 @@ static UnitActiveState service_active_state(Unit *u) {
         return state_translation_table[SERVICE(u)->state];
 }
 
+static const char *service_sub_state_to_string(Unit *u) {
+        assert(u);
+
+        return service_state_to_string(SERVICE(u)->state);
+}
+
 static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
         Service *s = SERVICE(u);
         bool success;
@@ -2046,6 +2071,7 @@ const UnitVTable service_vtable = {
         .can_reload = service_can_reload,
 
         .active_state = service_active_state,
+        .sub_state_to_string = service_sub_state_to_string,
 
         .sigchld_event = service_sigchld_event,
         .timer_event = service_timer_event,