chiark / gitweb /
systemctl: fix 'systemctl enable getty@.service'
[elogind.git] / src / unit.c
index 0a8ee61900e206bcdbaad30e9ec84634c815263b..d45fe91560513b1ea8988404cc29ca65554f2f5a 100644 (file)
@@ -103,7 +103,7 @@ int unit_add_name(Unit *u, const char *text) {
         if (!s)
                 return -ENOMEM;
 
-        if (!unit_name_is_valid(s)) {
+        if (!unit_name_is_valid(s, false)) {
                 r = -EINVAL;
                 goto fail;
         }
@@ -1165,10 +1165,13 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
                 if (u->meta.type == UNIT_SERVICE &&
                     !UNIT_IS_ACTIVE_OR_RELOADING(os)) {
                         /* Write audit record if we have just finished starting up */
-                        manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_START, 1);
+                        manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_START, true);
                         u->meta.in_audit = true;
                 }
 
+                if (!UNIT_IS_ACTIVE_OR_RELOADING(os))
+                        manager_send_unit_plymouth(u->meta.manager, u);
+
         } else {
 
                 if (unit_has_name(u, SPECIAL_SYSLOG_SERVICE))
@@ -2190,11 +2193,51 @@ bool unit_pending_inactive(Unit *u) {
         return false;
 }
 
+bool unit_pending_active(Unit *u) {
+        assert(u);
+
+        /* Returns true if the unit is inactive or going down */
+
+        if (UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u)))
+                return true;
+
+        if (u->meta.job &&
+            (u->meta.job->type == JOB_START ||
+             u->meta.job->type == JOB_RELOAD_OR_START ||
+             u->meta.job->type == JOB_RESTART))
+                return true;
+
+        return false;
+}
+
+UnitType unit_name_to_type(const char *n) {
+        UnitType t;
+
+        assert(n);
+
+        for (t = 0; t < _UNIT_TYPE_MAX; t++)
+                if (endswith(n, unit_vtable[t]->suffix))
+                        return t;
+
+        return _UNIT_TYPE_INVALID;
+}
+
+bool unit_name_is_valid(const char *n, bool template_ok) {
+        UnitType t;
+
+        t = unit_name_to_type(n);
+        if (t < 0 || t >= _UNIT_TYPE_MAX)
+                return false;
+
+        return unit_name_is_valid_no_type(n, template_ok);
+}
+
 static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
         [UNIT_STUB] = "stub",
         [UNIT_LOADED] = "loaded",
         [UNIT_ERROR] = "error",
-        [UNIT_MERGED] = "merged"
+        [UNIT_MERGED] = "merged",
+        [UNIT_BANNED] = "banned"
 };
 
 DEFINE_STRING_TABLE_LOOKUP(unit_load_state, UnitLoadState);