diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-01-27 00:57:34 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-01-27 01:23:16 -0500 |
commit | 68db7a3bd9b2f8640c7297382b6d20eb995f7e1e (patch) | |
tree | 1f06859edce75e8fa58d42cc20f4a4b3444c5190 /src/core/job.c | |
parent | d7353ef6095f5e7db63d9cc898c7134b64482550 (diff) |
core: add function to tell when job will time out
Things will continue when either the job timeout
or the unit timeout is reached. Add functionality to
access that info.
Diffstat (limited to 'src/core/job.c')
-rw-r--r-- | src/core/job.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/core/job.c b/src/core/job.c index 7faa8da0ed..e6529b61e9 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -1086,6 +1086,37 @@ 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); + + log_info("job_get_timeout %s %d/%"PRIu64" %d/%"PRIu64" -> 1/%"PRIu64, + j->unit->id, r, x, q, y, *timeout); + + return 1; +} + static const char* const job_state_table[_JOB_STATE_MAX] = { [JOB_WAITING] = "waiting", [JOB_RUNNING] = "running" |