X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Ftimer.c;h=61bd85c7ef2b5324188c3c3478a6ec5562b13a9d;hp=1c7010d120829ddada9accf9c5bb217228e8ec42;hb=16061c20ddd8eba9b9e1ef89149c51114a8084ce;hpb=398ef8ba0266cca453d90a90b3a2aa1caa44189f diff --git a/src/timer.c b/src/timer.c index 1c7010d12..61bd85c7e 100644 --- a/src/timer.c +++ b/src/timer.c @@ -1,4 +1,4 @@ -/*-*- Mode: C; c-basic-offset: 8 -*-*/ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ /*** This file is part of systemd. @@ -73,6 +73,18 @@ static int timer_verify(Timer *t) { return 0; } +static int timer_add_default_dependencies(Timer *t) { + int r; + + assert(t); + + if (t->meta.manager->running_as == MANAGER_SYSTEM) + if ((r = unit_add_two_dependencies_by_name(UNIT(t), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true)) < 0) + return r; + + return unit_add_two_dependencies_by_name(UNIT(t), UNIT_BEFORE, UNIT_CONFLICTED_BY, SPECIAL_SHUTDOWN_TARGET, NULL, true); +} + static int timer_load(Unit *u) { Timer *t = TIMER(u); int r; @@ -92,9 +104,8 @@ static int timer_load(Unit *u) { if ((r = unit_add_dependency(u, UNIT_BEFORE, t->unit, true)) < 0) return r; - /* Timers shouldn't stay around on shutdown */ if (t->meta.default_dependencies) - if ((r = unit_add_two_dependencies_by_name(u, UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true)) < 0) + if ((r = timer_add_default_dependencies(t)) < 0) return r; } @@ -103,15 +114,10 @@ static int timer_load(Unit *u) { static void timer_dump(Unit *u, FILE *f, const char *prefix) { Timer *t = TIMER(u); - const char *prefix2; - char *p2; TimerValue *v; char timespan1[FORMAT_TIMESPAN_MAX]; - p2 = strappend(prefix, "\t"); - prefix2 = p2 ? p2 : prefix; - fprintf(f, "%sTimer State: %s\n" "%sUnit: %s\n", @@ -124,8 +130,6 @@ static void timer_dump(Unit *u, FILE *f, const char *prefix) { prefix, timer_base_to_string(v->base), strna(format_timespan(timespan1, sizeof(timespan1), v->value))); - - free(p2); } static void timer_set_state(Timer *t, TimerState state) { @@ -268,6 +272,10 @@ static void timer_enter_running(Timer *t) { assert(t); dbus_error_init(&error); + /* Don't start job if we are supposed to go down */ + if (t->meta.job && t->meta.job->type == JOB_STOP) + return; + if ((r = manager_add_job(t->meta.manager, JOB_START, t->unit, JOB_REPLACE, true, &error, NULL)) < 0) goto fail; @@ -435,6 +443,17 @@ fail: log_error("Failed find timer unit: %s", strerror(-r)); } +static void timer_reset_maintenance(Unit *u) { + Timer *t = TIMER(u); + + assert(t); + + if (t->state == TIMER_MAINTENANCE) + timer_set_state(t, TIMER_DEAD); + + t->failure = false; +} + static const char* const timer_state_table[_TIMER_STATE_MAX] = { [TIMER_DEAD] = "dead", [TIMER_WAITING] = "waiting", @@ -477,5 +496,7 @@ const UnitVTable timer_vtable = { .timer_event = timer_timer_event, + .reset_maintenance = timer_reset_maintenance, + .bus_message_handler = bus_timer_message_handler };