chiark / gitweb /
core: replace OnFailureIsolate= setting by a more generic OnFailureJobMode= setting...
[elogind.git] / src / core / service.c
index d9e525e48545c4a7b35f6a15cc65d10e194b5c1b..28b1465c19918f331969b0f13449bf76f83371a4 100644 (file)
@@ -346,11 +346,6 @@ static int service_arm_timer(Service *s, usec_t usec) {
 
         assert(s);
 
-        if (usec <= 0) {
-                s->timer_event_source = sd_event_source_unref(s->timer_event_source);
-                return 0;
-        }
-
         if (s->timer_event_source) {
                 r = sd_event_source_set_time(s->timer_event_source, now(CLOCK_MONOTONIC) + usec);
                 if (r < 0)
@@ -1597,21 +1592,30 @@ static int service_coldplug(Unit *u) {
                     s->deserialized_state == SERVICE_STOP_SIGKILL ||
                     s->deserialized_state == SERVICE_STOP_POST ||
                     s->deserialized_state == SERVICE_FINAL_SIGTERM ||
-                    s->deserialized_state == SERVICE_FINAL_SIGKILL ||
-                    s->deserialized_state == SERVICE_AUTO_RESTART) {
+                    s->deserialized_state == SERVICE_FINAL_SIGKILL) {
+
+                        usec_t k;
 
-                        if (s->deserialized_state == SERVICE_AUTO_RESTART || s->timeout_start_usec > 0) {
+                        k = s->deserialized_state == SERVICE_START_PRE || s->deserialized_state == SERVICE_START ||
+                                s->deserialized_state == SERVICE_START_POST || s->deserialized_state == SERVICE_RELOAD ?
+                                s->timeout_start_usec : s->timeout_stop_usec;
 
-                                r = service_arm_timer(s,
-                                                      s->deserialized_state == SERVICE_AUTO_RESTART ? s->restart_usec :
-                                                      s->deserialized_state == SERVICE_START_PRE || s->deserialized_state == SERVICE_START ||
-                                                      s->deserialized_state == SERVICE_START_POST || s->deserialized_state == SERVICE_RELOAD ? s->timeout_start_usec :
-                                                      s->timeout_stop_usec);
+                        /* For the start/stop timeouts 0 means off */
+                        if (k > 0) {
+                                r = service_arm_timer(s, k);
                                 if (r < 0)
                                         return r;
                         }
                 }
 
+                if (s->deserialized_state == SERVICE_AUTO_RESTART) {
+
+                        /* The restart timeouts 0 means immediately */
+                        r = service_arm_timer(s, s->restart_usec);
+                        if (r < 0)
+                                return r;
+                }
+
                 if ((s->deserialized_state == SERVICE_START &&
                      (s->type == SERVICE_FORKING ||
                       s->type == SERVICE_DBUS ||
@@ -1651,6 +1655,7 @@ static int service_coldplug(Unit *u) {
 
                 service_set_state(s, s->deserialized_state);
         }
+
         return 0;
 }
 
@@ -1763,9 +1768,12 @@ static int service_spawn(
                 }
         }
 
-        r = service_arm_timer(s, timeout ? s->timeout_start_usec : 0);
-        if (r < 0)
-                goto fail;
+        if (timeout && s->timeout_start_usec > 0) {
+                r = service_arm_timer(s, s->timeout_start_usec);
+                if (r < 0)
+                        goto fail;
+        } else
+                s->timer_event_source = sd_event_source_unref(s->timer_event_source);
 
         r = unit_full_printf_strv(UNIT(s), c->argv, &argv);
         if (r < 0)
@@ -2908,7 +2916,12 @@ static int service_demand_pid_file(Service *s) {
 }
 
 static int service_dispatch_io(sd_event_source *source, int fd, uint32_t events, void *userdata) {
-        Service *s = SERVICE(userdata);
+        PathSpec *p = userdata;
+        Service *s;
+
+        assert(p);
+
+        s = SERVICE(p->unit);
 
         assert(s);
         assert(fd >= 0);
@@ -2918,7 +2931,7 @@ static int service_dispatch_io(sd_event_source *source, int fd, uint32_t events,
 
         log_debug_unit(UNIT(s)->id, "inotify event for %s", UNIT(s)->id);
 
-        if (path_spec_fd_event(s->pid_file_pathspec, events) < 0)
+        if (path_spec_fd_event(p, events) < 0)
                 goto fail;
 
         if (service_retry_pid_file(s) == 0)