X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Ftimer.c;h=cd6728a1864d880f0ad9661c456918b4cf42b749;hp=7bf2d1023892338488261ea23399d6a8dd385ded;hb=5632e3743db350a67478acc107d76cdf648a1f99;hpb=18c78fb1af5415bb6f87d9c7cae1f9c60e14ae24 diff --git a/src/timer.c b/src/timer.c index 7bf2d1023..cd6728a18 100644 --- a/src/timer.c +++ b/src/timer.c @@ -25,13 +25,15 @@ #include "unit-name.h" #include "timer.h" #include "dbus-timer.h" +#include "special.h" +#include "bus-errors.h" static const UnitActiveState state_translation_table[_TIMER_STATE_MAX] = { [TIMER_DEAD] = UNIT_INACTIVE, [TIMER_WAITING] = UNIT_ACTIVE, [TIMER_RUNNING] = UNIT_ACTIVE, [TIMER_ELAPSED] = UNIT_ACTIVE, - [TIMER_MAINTENANCE] = UNIT_INACTIVE + [TIMER_MAINTENANCE] = UNIT_MAINTENANCE }; static void timer_init(Unit *u) { @@ -60,7 +62,7 @@ static void timer_done(Unit *u) { static int timer_verify(Timer *t) { assert(t); - if (UNIT(t)->meta.load_state != UNIT_LOADED) + if (t->meta.load_state != UNIT_LOADED) return 0; if (!t->values) { @@ -71,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_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true); +} + static int timer_load(Unit *u) { Timer *t = TIMER(u); int r; @@ -89,6 +103,10 @@ static int timer_load(Unit *u) { if ((r = unit_add_dependency(u, UNIT_BEFORE, t->unit, true)) < 0) return r; + + if (t->meta.default_dependencies) + if ((r = timer_add_default_dependencies(t)) < 0) + return r; } return timer_verify(t); @@ -255,18 +273,27 @@ fail: } static void timer_enter_running(Timer *t) { + DBusError error; int r; + assert(t); + dbus_error_init(&error); - if ((r = manager_add_job(UNIT(t)->meta.manager, JOB_START, t->unit, JOB_REPLACE, true, NULL)) < 0) + /* 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; timer_set_state(t, TIMER_RUNNING); return; fail: - log_warning("%s failed to queue unit startup job: %s", t->meta.id, strerror(-r)); + log_warning("%s failed to queue unit startup job: %s", t->meta.id, bus_error(&error, r)); timer_enter_dead(t, false); + + dbus_error_free(&error); } static int timer_start(Unit *u) { @@ -401,7 +428,7 @@ void timer_unit_notify(Unit *u, UnitActiveState new_state) { case TIMER_RUNNING: - if (new_state == UNIT_INACTIVE) { + if (UNIT_IS_INACTIVE_OR_MAINTENANCE(new_state)) { log_debug("%s got notified about unit deactivation.", t->meta.id); timer_enter_waiting(t, false); } @@ -423,6 +450,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", @@ -434,11 +472,11 @@ static const char* const timer_state_table[_TIMER_STATE_MAX] = { DEFINE_STRING_TABLE_LOOKUP(timer_state, TimerState); static const char* const timer_base_table[_TIMER_BASE_MAX] = { - [TIMER_ACTIVE] = "OnActive", - [TIMER_BOOT] = "OnBoot", - [TIMER_STARTUP] = "OnStartup", - [TIMER_UNIT_ACTIVE] = "OnUnitActive", - [TIMER_UNIT_INACTIVE] = "OnUnitInactive" + [TIMER_ACTIVE] = "OnActiveSec", + [TIMER_BOOT] = "OnBootSec", + [TIMER_STARTUP] = "OnStartupSec", + [TIMER_UNIT_ACTIVE] = "OnUnitActiveSec", + [TIMER_UNIT_INACTIVE] = "OnUnitInactiveSec" }; DEFINE_STRING_TABLE_LOOKUP(timer_base, TimerBase); @@ -465,5 +503,7 @@ const UnitVTable timer_vtable = { .timer_event = timer_timer_event, + .reset_maintenance = timer_reset_maintenance, + .bus_message_handler = bus_timer_message_handler };