]> err.no Git - systemd/commitdiff
job: also trigger on-failure dependencies when jobs faile due to dependencies, timeout
authorLennart Poettering <lennart@poettering.net>
Thu, 24 Feb 2011 02:24:23 +0000 (03:24 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 24 Feb 2011 02:24:23 +0000 (03:24 +0100)
src/job.c
src/unit.c
src/unit.h

index 54c204b650335ec9d35be6ff5db50d1e286c2c7b..46577fdf7a199384b50da6c19fd34e46c3feb4f1 100644 (file)
--- a/src/job.c
+++ b/src/job.c
@@ -549,6 +549,13 @@ int job_finish_and_invalidate(Job *j, JobResult result) {
                 }
         }
 
+        /* Trigger OnFailure dependencies that are not generated by
+         * the unit itself. We don't tread JOB_CANCELED as failure in
+         * this context. And JOB_FAILURE is already handled by the
+         * unit itself. */
+        if (result == JOB_TIMEOUT || result == JOB_DEPENDENCY)
+                unit_trigger_on_failure(u);
+
         /* Try to start the next jobs that can be started */
         SET_FOREACH(other, u->meta.dependencies[UNIT_AFTER], i)
                 if (other->meta.job)
index 1ca8e82af736b558f8bc753a6699b4f79a09d280..d75a06afc8ffd43edd40012ab42b5108fcb3beb5 100644 (file)
@@ -1071,6 +1071,16 @@ static void retroactively_stop_dependencies(Unit *u) {
                         unit_check_unneeded(other);
 }
 
+void unit_trigger_on_failure(Unit *u) {
+        Unit *other;
+        Iterator i;
+
+        assert(u);
+
+        SET_FOREACH(other, u->meta.dependencies[UNIT_ON_FAILURE], i)
+                manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL, NULL);
+}
+
 void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success) {
         dual_timestamp ts;
         bool unexpected;
@@ -1183,13 +1193,8 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
         }
 
         if (ns != os && ns == UNIT_FAILED) {
-                Iterator i;
-                Unit *other;
-
-                SET_FOREACH(other, u->meta.dependencies[UNIT_ON_FAILURE], i)
-                        manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL, NULL);
-
                 log_notice("Unit %s entered failed state.", u->meta.id);
+                unit_trigger_on_failure(u);
         }
 
         /* Some names are special */
index e81cffca3a00efa33e47e0ee09586565280f6b76..bd60dcb1153b4b6c44e5d3bce2d0b648639b953d 100644 (file)
@@ -511,6 +511,8 @@ int unit_following_set(Unit *u, Set **s);
 UnitType unit_name_to_type(const char *n);
 bool unit_name_is_valid(const char *n, bool template_ok);
 
+void unit_trigger_on_failure(Unit *u);
+
 const char *unit_load_state_to_string(UnitLoadState i);
 UnitLoadState unit_load_state_from_string(const char *s);