X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fjob.c;h=feeb563177e39351d1e05f512cde70403151797c;hb=336c6e4690ea017a11799aa331ffedd4c59a31ad;hp=491c73d47b47dbfa7a02d6f05f31c254757d3705;hpb=9091e686f43184065381aa71929e3df36a4ea2e1;p=elogind.git diff --git a/src/core/job.c b/src/core/job.c index 491c73d47..feeb56317 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -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; @@ -906,7 +913,7 @@ char *job_dbus_path(Job *j) { assert(j); - if (asprintf(&p, "/org/freedesktop/systemd1/job/%lu", (unsigned long) j->id) < 0) + if (asprintf(&p, "/org/freedesktop/systemd1/job/%"PRIu32, j->id) < 0) return NULL; return p; @@ -922,7 +929,7 @@ int job_serialize(Job *j, FILE *f, FDSet *fds) { fprintf(f, "job-ignore-order=%s\n", yes_no(j->ignore_order)); if (j->begin_usec > 0) - fprintf(f, "job-begin=%llu\n", (unsigned long long) j->begin_usec); + fprintf(f, "job-begin="USEC_FMT"\n", j->begin_usec); bus_client_track_serialize(j->manager, f, j->subscribed); @@ -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"