chiark / gitweb /
systemctl: introduce reset-maintenance command
[elogind.git] / src / timer.c
index f0005f55ce364a9378f0e7d6800a5d39cb010e8d..cd6728a1864d880f0ad9661c456918b4cf42b749 100644 (file)
@@ -25,6 +25,8 @@
 #include "unit-name.h"
 #include "timer.h"
 #include "dbus-timer.h"
 #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,
 
 static const UnitActiveState state_translation_table[_TIMER_STATE_MAX] = {
         [TIMER_DEAD] = UNIT_INACTIVE,
@@ -71,6 +73,18 @@ static int timer_verify(Timer *t) {
         return 0;
 }
 
         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;
 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 ((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);
         }
 
         return timer_verify(t);
@@ -255,18 +273,27 @@ fail:
 }
 
 static void timer_enter_running(Timer *t) {
 }
 
 static void timer_enter_running(Timer *t) {
+        DBusError error;
         int r;
         int r;
+
         assert(t);
         assert(t);
+        dbus_error_init(&error);
 
 
-        if ((r = manager_add_job(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:
                 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);
         timer_enter_dead(t, false);
+
+        dbus_error_free(&error);
 }
 
 static int timer_start(Unit *u) {
 }
 
 static int timer_start(Unit *u) {
@@ -423,6 +450,17 @@ fail:
         log_error("Failed find timer unit: %s", strerror(-r));
 }
 
         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",
 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] = {
 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);
 };
 
 DEFINE_STRING_TABLE_LOOKUP(timer_base, TimerBase);
@@ -465,5 +503,7 @@ const UnitVTable timer_vtable = {
 
         .timer_event = timer_timer_event,
 
 
         .timer_event = timer_timer_event,
 
+        .reset_maintenance = timer_reset_maintenance,
+
         .bus_message_handler = bus_timer_message_handler
 };
         .bus_message_handler = bus_timer_message_handler
 };