chiark / gitweb /
unit: add minimal condition checker for unit startup
[elogind.git] / src / unit.c
index d45fe91560513b1ea8988404cc29ca65554f2f5a..07978134de959889f213740bd55aaeffd80bb939 100644 (file)
@@ -375,8 +375,9 @@ void unit_free(Unit *u) {
 
         set_free_free(u->meta.names);
 
-        free(u->meta.instance);
+        condition_free_list(u->meta.conditions);
 
+        free(u->meta.instance);
         free(u);
 }
 
@@ -640,6 +641,8 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
         if (u->meta.job_timeout > 0)
                 fprintf(f, "%s\tJob Timeout: %s\n", prefix, format_timespan(timespan, sizeof(timespan), u->meta.job_timeout));
 
+        condition_dump_list(u->meta.conditions, f, prefix);
+
         for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++) {
                 Unit *other;
 
@@ -841,6 +844,12 @@ int unit_start(Unit *u) {
         if (!UNIT_VTABLE(u)->start)
                 return -EBADR;
 
+        /* If the conditions failed, don't do anything at all */
+        if (!condition_test_list(u->meta.conditions)) {
+                log_debug("Starting of %s requested but condition failed. Ignoring.", u->meta.id);
+                return -EALREADY;
+        }
+
         /* We don't suppress calls to ->start() here when we are
          * already starting, to allow this request to be used as a
          * "hurry up" call, for example when the unit is in some "auto
@@ -2237,7 +2246,7 @@ static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
         [UNIT_LOADED] = "loaded",
         [UNIT_ERROR] = "error",
         [UNIT_MERGED] = "merged",
-        [UNIT_BANNED] = "banned"
+        [UNIT_MASKED] = "masked"
 };
 
 DEFINE_STRING_TABLE_LOOKUP(unit_load_state, UnitLoadState);