chiark / gitweb /
journald: log provenience of signals
[elogind.git] / src / core / job.c
index 7faa8da0ed7cf1bb13a738172574f3fc718c8230..feeb563177e39351d1e05f512cde70403151797c 100644 (file)
@@ -632,15 +632,18 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) {
                         break;
 
                 case JOB_FAILED:
+                        manager_flip_auto_status(u->manager, true);
                         unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON "FAILED" ANSI_HIGHLIGHT_OFF, format);
                         manager_status_printf(u->manager, false, NULL, "See 'systemctl status %s' for details.", u->id);
                         break;
 
                 case JOB_DEPENDENCY:
+                        manager_flip_auto_status(u->manager, true);
                         unit_status_printf(u, ANSI_HIGHLIGHT_YELLOW_ON "DEPEND" ANSI_HIGHLIGHT_OFF, format);
                         break;
 
                 case JOB_TIMEOUT:
+                        manager_flip_auto_status(u->manager, true);
                         unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON " TIME " ANSI_HIGHLIGHT_OFF, format);
                         break;
 
@@ -657,6 +660,7 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) {
                 switch (result) {
 
                 case JOB_TIMEOUT:
+                        manager_flip_auto_status(u->manager, true);
                         unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON " TIME " ANSI_HIGHLIGHT_OFF, format);
                         break;
 
@@ -860,11 +864,14 @@ static int job_dispatch_timer(sd_event_source *s, uint64_t monotonic, void *user
 int job_start_timer(Job *j) {
         int r;
 
-        if (j->unit->job_timeout <= 0 || j->timer_event_source)
+        if (j->timer_event_source)
                 return 0;
 
         j->begin_usec = now(CLOCK_MONOTONIC);
 
+        if (j->unit->job_timeout <= 0)
+                return 0;
+
         r = sd_event_add_monotonic(j->manager->event, j->begin_usec + j->unit->job_timeout, 0, job_dispatch_timer, j, &j->timer_event_source);
         if (r < 0)
                 return r;
@@ -1044,7 +1051,7 @@ int job_coldplug(Job *j) {
 
         assert(j);
 
-        if (j->begin_usec <= 0)
+        if (j->begin_usec == 0 || j->unit->job_timeout == 0)
                 return 0;
 
         if (j->timer_event_source)
@@ -1086,6 +1093,34 @@ void job_shutdown_magic(Job *j) {
         asynchronous_sync();
 }
 
+int job_get_timeout(Job *j, uint64_t *timeout) {
+        Unit *u = j->unit;
+        uint64_t x = -1, y = -1;
+        int r = 0, q = 0;
+
+        assert(u);
+
+        if (j->timer_event_source) {
+                r = sd_event_source_get_time(j->timer_event_source, &x);
+                if (r < 0)
+                        return r;
+                r = 1;
+        }
+
+        if (UNIT_VTABLE(u)->get_timeout) {
+                q = UNIT_VTABLE(u)->get_timeout(u, &y);
+                if (q < 0)
+                        return q;
+        }
+
+        if (r == 0 && q == 0)
+                return 0;
+
+        *timeout = MIN(x, y);
+
+        return 1;
+}
+
 static const char* const job_state_table[_JOB_STATE_MAX] = {
         [JOB_WAITING] = "waiting",
         [JOB_RUNNING] = "running"