chiark / gitweb /
gc: remove a lot of unused code
[elogind.git] / src / unit.c
index b93777bec68dac245d3d3a87b5d7a036c43278dc..59776c33e48e7a4def9382c68ff3175e72e162ee 100644 (file)
@@ -722,16 +722,6 @@ int unit_load_fragment_and_dropin_optional(Unit *u) {
         return 0;
 }
 
-/* Common implementation for multiple backends */
-int unit_load_nop(Unit *u) {
-        assert(u);
-
-        if (u->meta.load_state == UNIT_STUB)
-                u->meta.load_state = UNIT_LOADED;
-
-        return 0;
-}
-
 int unit_load(Unit *u) {
         int r;
 
@@ -859,10 +849,10 @@ int unit_reload(Unit *u) {
                 return -EBADR;
 
         state = unit_active_state(u);
-        if (unit_active_state(u) == UNIT_RELOADING)
+        if (state == UNIT_RELOADING)
                 return -EALREADY;
 
-        if (unit_active_state(u) != UNIT_ACTIVE)
+        if (state != UNIT_ACTIVE)
                 return -ENOEXEC;
 
         unit_add_to_dbus_queue(u);
@@ -990,8 +980,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
          * even if they might map to the same high-level
          * UnitActiveState! That means that ns == os is OK an expected
          * behaviour here. For example: if a mount point is remounted
-         * this function will be called too and the utmp code below
-         * relies on that! */
+         * this function will be called too! */
 
         dual_timestamp_get(&ts);
 
@@ -1115,9 +1104,11 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
                         log_open();
 
                 if (u->meta.type == UNIT_SERVICE &&
-                    !UNIT_IS_ACTIVE_OR_RELOADING(os))
+                    !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);
+                        u->meta.in_audit = true;
+                }
 
         } else {
 
@@ -1132,10 +1123,22 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
 
                 if (u->meta.type == UNIT_SERVICE &&
                     UNIT_IS_INACTIVE_OR_MAINTENANCE(ns) &&
-                    !UNIT_IS_INACTIVE_OR_MAINTENANCE(os))
+                    !UNIT_IS_INACTIVE_OR_MAINTENANCE(os)) {
+
+                        /* Hmm, if there was no start record written
+                         * write it now, so that we always have a nice
+                         * pair */
+                        if (!u->meta.in_audit) {
+                                manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_START, ns == UNIT_INACTIVE);
+
+                                if (ns == UNIT_INACTIVE)
+                                        manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_STOP, true);
+                        } else
+                                /* Write audit record if we have just finished shutting down */
+                                manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_STOP, ns == UNIT_INACTIVE);
 
-                        /* Write audit record if we have just finished shutting down */
-                        manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_STOP, ns == UNIT_INACTIVE);
+                        u->meta.in_audit = false;
+                }
         }
 
         /* Maybe we finished startup and are now ready for being
@@ -1970,6 +1973,7 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
                         return -errno;
                 }
 
+                char_array_0(line);
                 l = strstrip(line);
 
                 /* End marker */
@@ -2110,20 +2114,6 @@ Unit *unit_following(Unit *u) {
         return NULL;
 }
 
-static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
-        [UNIT_SERVICE] = "service",
-        [UNIT_TIMER] = "timer",
-        [UNIT_SOCKET] = "socket",
-        [UNIT_TARGET] = "target",
-        [UNIT_DEVICE] = "device",
-        [UNIT_MOUNT] = "mount",
-        [UNIT_AUTOMOUNT] = "automount",
-        [UNIT_SNAPSHOT] = "snapshot",
-        [UNIT_SWAP] = "swap"
-};
-
-DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
-
 static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
         [UNIT_STUB] = "stub",
         [UNIT_LOADED] = "loaded",