chiark / gitweb /
analyze: beautify output a bit
[elogind.git] / src / unit.c
index 10de40affc40fb3ba3fdd184d00c0a7b7a818845..895e40178abec92cf8d2b179f96302e1c8917595 100644 (file)
@@ -1101,7 +1101,6 @@ void unit_trigger_on_failure(Unit *u) {
 }
 
 void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success) {
-        dual_timestamp ts;
         bool unexpected;
 
         assert(u);
@@ -1114,24 +1113,28 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
          * behaviour here. For example: if a mount point is remounted
          * this function will be called too! */
 
-        dual_timestamp_get(&ts);
+        if (u->meta.manager->n_deserializing <= 0) {
+                dual_timestamp ts;
 
-        if (UNIT_IS_INACTIVE_OR_FAILED(os) && !UNIT_IS_INACTIVE_OR_FAILED(ns))
-                u->meta.inactive_exit_timestamp = ts;
-        else if (!UNIT_IS_INACTIVE_OR_FAILED(os) && UNIT_IS_INACTIVE_OR_FAILED(ns))
-                u->meta.inactive_enter_timestamp = ts;
+                dual_timestamp_get(&ts);
 
-        if (!UNIT_IS_ACTIVE_OR_RELOADING(os) && UNIT_IS_ACTIVE_OR_RELOADING(ns))
-                u->meta.active_enter_timestamp = ts;
-        else if (UNIT_IS_ACTIVE_OR_RELOADING(os) && !UNIT_IS_ACTIVE_OR_RELOADING(ns))
-                u->meta.active_exit_timestamp = ts;
+                if (UNIT_IS_INACTIVE_OR_FAILED(os) && !UNIT_IS_INACTIVE_OR_FAILED(ns))
+                        u->meta.inactive_exit_timestamp = ts;
+                else if (!UNIT_IS_INACTIVE_OR_FAILED(os) && UNIT_IS_INACTIVE_OR_FAILED(ns))
+                        u->meta.inactive_enter_timestamp = ts;
+
+                if (!UNIT_IS_ACTIVE_OR_RELOADING(os) && UNIT_IS_ACTIVE_OR_RELOADING(ns))
+                        u->meta.active_enter_timestamp = ts;
+                else if (UNIT_IS_ACTIVE_OR_RELOADING(os) && !UNIT_IS_ACTIVE_OR_RELOADING(ns))
+                        u->meta.active_exit_timestamp = ts;
+
+                timer_unit_notify(u, ns);
+                path_unit_notify(u, ns);
+        }
 
         if (UNIT_IS_INACTIVE_OR_FAILED(ns))
                 cgroup_bonding_trim_list(u->meta.cgroup_bondings, true);
 
-        timer_unit_notify(u, ns);
-        path_unit_notify(u, ns);
-
         if (u->meta.job) {
                 unexpected = false;
 
@@ -1198,77 +1201,73 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
         } else
                 unexpected = true;
 
-        /* If this state change happened without being requested by a
-         * job, then let's retroactively start or stop
-         * dependencies. We skip that step when deserializing, since
-         * we don't want to create any additional jobs just because
-         * something is already activated. */
-
-        if (unexpected && u->meta.manager->n_deserializing <= 0) {
-                if (UNIT_IS_INACTIVE_OR_FAILED(os) && UNIT_IS_ACTIVE_OR_ACTIVATING(ns))
-                        retroactively_start_dependencies(u);
-                else if (UNIT_IS_ACTIVE_OR_ACTIVATING(os) && UNIT_IS_INACTIVE_OR_DEACTIVATING(ns))
-                        retroactively_stop_dependencies(u);
-        }
+        if (u->meta.manager->n_deserializing <= 0) {
 
-        if (ns != os && ns == UNIT_FAILED) {
-                log_notice("Unit %s entered failed state.", u->meta.id);
-                unit_trigger_on_failure(u);
-        }
+                /* If this state change happened without being
+                 * requested by a job, then let's retroactively start
+                 * or stop dependencies. We skip that step when
+                 * deserializing, since we don't want to create any
+                 * additional jobs just because something is already
+                 * activated. */
+
+                if (unexpected) {
+                        if (UNIT_IS_INACTIVE_OR_FAILED(os) && UNIT_IS_ACTIVE_OR_ACTIVATING(ns))
+                                retroactively_start_dependencies(u);
+                        else if (UNIT_IS_ACTIVE_OR_ACTIVATING(os) && UNIT_IS_INACTIVE_OR_DEACTIVATING(ns))
+                                retroactively_stop_dependencies(u);
+                }
 
-        /* Some names are special */
-        if (UNIT_IS_ACTIVE_OR_RELOADING(ns)) {
-                if (unit_has_name(u, SPECIAL_DBUS_SERVICE))
-                        /* The bus just might have become available,
-                         * hence try to connect to it, if we aren't
-                         * yet connected. */
-                        bus_init(u->meta.manager, true);
-
-                if (unit_has_name(u, SPECIAL_SYSLOG_SERVICE))
-                        /* The syslog daemon just might have become
-                         * available, hence try to connect to it, if
-                         * we aren't yet connected. */
-                        log_open();
-
-                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, true);
-                        u->meta.in_audit = true;
+                if (ns != os && ns == UNIT_FAILED) {
+                        log_notice("Unit %s entered failed state.", u->meta.id);
+                        unit_trigger_on_failure(u);
                 }
 
-                if (!UNIT_IS_ACTIVE_OR_RELOADING(os))
-                        manager_send_unit_plymouth(u->meta.manager, u);
 
-        } else {
+                /* Some names are special */
+                if (UNIT_IS_ACTIVE_OR_RELOADING(ns)) {
 
-                if (unit_has_name(u, SPECIAL_SYSLOG_SERVICE))
-                        /* The syslog daemon might just have
-                         * terminated, hence try to disconnect from
-                         * it. */
-                        log_close_syslog();
+                        if (unit_has_name(u, SPECIAL_DBUS_SERVICE))
+                                /* The bus just might have become available,
+                                 * hence try to connect to it, if we aren't
+                                 * yet connected. */
+                                bus_init(u->meta.manager, true);
 
-                /* We don't care about D-Bus here, since we'll get an
-                 * asynchronous notification for it anyway. */
+                        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, true);
+                                u->meta.in_audit = true;
+                        }
+
+                        if (!UNIT_IS_ACTIVE_OR_RELOADING(os))
+                                manager_send_unit_plymouth(u->meta.manager, u);
+
+                } else {
 
-                if (u->meta.type == UNIT_SERVICE &&
-                    UNIT_IS_INACTIVE_OR_FAILED(ns) &&
-                    !UNIT_IS_INACTIVE_OR_FAILED(os)) {
+                        /* We don't care about D-Bus here, since we'll get an
+                         * asynchronous notification for it anyway. */
 
-                        /* 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 (u->meta.type == UNIT_SERVICE &&
+                            UNIT_IS_INACTIVE_OR_FAILED(ns) &&
+                            !UNIT_IS_INACTIVE_OR_FAILED(os)) {
 
-                                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);
+                                /* 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);
 
-                        u->meta.in_audit = false;
+                                        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);
+
+                                u->meta.in_audit = false;
+                        }
                 }
+
+                manager_recheck_syslog(u->meta.manager);
         }
 
         /* Maybe we finished startup and are now ready for being
@@ -2190,6 +2189,8 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
                                 log_debug("Failed to parse condition result value %s", v);
                         else
                                 u->meta.condition_result = b;
+
+                        continue;
                 }
 
                 if ((r = UNIT_VTABLE(u)->deserialize_item(u, l, v, fds)) < 0)
@@ -2241,7 +2242,7 @@ int unit_coldplug(Unit *u) {
                         return r;
 
         if (u->meta.deserialized_job >= 0) {
-                if ((r = manager_add_job(u->meta.manager, u->meta.deserialized_job, u, JOB_FAIL, false, NULL, NULL)) < 0)
+                if ((r = manager_add_job(u->meta.manager, u->meta.deserialized_job, u, JOB_IGNORE_DEPENDENCIES, false, NULL, NULL)) < 0)
                         return r;
 
                 u->meta.deserialized_job = _JOB_TYPE_INVALID;
@@ -2262,7 +2263,10 @@ void unit_status_printf(Unit *u, const char *format, ...) {
         if (u->meta.manager->running_as != MANAGER_SYSTEM)
                 return;
 
-        if (!u->meta.manager->show_status)
+        /* If Plymouth is running make sure we show the status, so
+         * that there's something nice to see when people press Esc */
+
+        if (!u->meta.manager->show_status && !plymouth_running())
                 return;
 
         if (!manager_is_booting_or_shutting_down(u->meta.manager))