chiark / gitweb /
dbus: make errors reported via D-Bus more useful
[elogind.git] / src / timer.c
index ead8ab92a4b0881de1120cfe78b93775f6e44e00..1c7010d120829ddada9accf9c5bb217228e8ec42 100644 (file)
 #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) {
@@ -89,6 +91,11 @@ 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)
+                                return r;
         }
 
         return timer_verify(t);
@@ -255,18 +262,23 @@ fail:
 }
 
 static void timer_enter_running(Timer *t) {
+        DBusError error;
         int r;
+
         assert(t);
+        dbus_error_init(&error);
 
-        if ((r = manager_add_job(t->meta.manager, JOB_START, t->unit, JOB_REPLACE, true, NULL)) < 0)
+        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 +413,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);
                         }
@@ -434,11 +446,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);