chiark / gitweb /
execute: talk directly to the journald, instead to the stdout-syslog-bridge
[elogind.git] / src / unit.c
index 903a8e4da4a4ae6731ad2c7b6d3839fa506448a1..b31b92fc24ebb054ae1f898f097aec81e2821db2 100644 (file)
@@ -564,8 +564,8 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) {
             c->std_output != EXEC_OUTPUT_KMSG_AND_CONSOLE &&
             c->std_output != EXEC_OUTPUT_SYSLOG_AND_CONSOLE &&
             c->std_error != EXEC_OUTPUT_KMSG &&
-            c->std_error != EXEC_OUTPUT_SYSLOG_AND_CONSOLE &&
-            c->std_error != EXEC_OUTPUT_KMSG &&
+            c->std_error != EXEC_OUTPUT_SYSLOG &&
+            c->std_error != EXEC_OUTPUT_KMSG_AND_CONSOLE &&
             c->std_error != EXEC_OUTPUT_SYSLOG_AND_CONSOLE)
                 return 0;
 
@@ -573,7 +573,7 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) {
          * logging daemon is run first. */
 
         if (u->meta.manager->running_as == MANAGER_SYSTEM)
-                if ((r = unit_add_two_dependencies_by_name(u, UNIT_REQUIRES, UNIT_AFTER, SPECIAL_STDOUT_SYSLOG_BRIDGE_SOCKET, NULL, true)) < 0)
+                if ((r = unit_add_two_dependencies_by_name(u, UNIT_REQUIRES, UNIT_AFTER, SPECIAL_JOURNALD_SOCKET, NULL, true)) < 0)
                         return r;
 
         return 0;
@@ -858,6 +858,7 @@ fail:
         u->meta.load_state = UNIT_ERROR;
         u->meta.load_error = r;
         unit_add_to_dbus_queue(u);
+        unit_add_to_gc_queue(u);
 
         log_debug("Failed to load configuration for %s: %s", u->meta.id, strerror(-r));
 
@@ -924,7 +925,7 @@ int unit_start(Unit *u) {
 
         unit_add_to_dbus_queue(u);
 
-        unit_status_printf(u, "Starting %s...\n", unit_description(u));
+        unit_status_printf(u, NULL, "Starting %s...", unit_description(u));
         return UNIT_VTABLE(u)->start(u);
 }
 
@@ -966,7 +967,7 @@ int unit_stop(Unit *u) {
 
         unit_add_to_dbus_queue(u);
 
-        unit_status_printf(u, "Stopping %s...\n", unit_description(u));
+        unit_status_printf(u, NULL, "Stopping %s...", unit_description(u));
         return UNIT_VTABLE(u)->stop(u);
 }
 
@@ -1031,19 +1032,19 @@ static void unit_check_unneeded(Unit *u) {
                 return;
 
         SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i)
-                if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
+                if (unit_pending_active(other))
                         return;
 
         SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY_OVERRIDABLE], i)
-                if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
+                if (unit_pending_active(other))
                         return;
 
         SET_FOREACH(other, u->meta.dependencies[UNIT_WANTED_BY], i)
-                if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
+                if (unit_pending_active(other))
                         return;
 
         SET_FOREACH(other, u->meta.dependencies[UNIT_BOUND_BY], i)
-                if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
+                if (unit_pending_active(other))
                         return;
 
         log_info("Service %s is not needed anymore. Stopping.", u->meta.id);
@@ -1104,6 +1105,14 @@ static void retroactively_stop_dependencies(Unit *u) {
         SET_FOREACH(other, u->meta.dependencies[UNIT_BOUND_BY], i)
                 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
                         manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL, NULL);
+}
+
+static void check_unneeded_dependencies(Unit *u) {
+        Iterator i;
+        Unit *other;
+
+        assert(u);
+        assert(UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(u)));
 
         /* Garbage collect services that might not be needed anymore, if enabled */
         SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES], i)
@@ -1262,6 +1271,10 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
                                 retroactively_stop_dependencies(u);
                 }
 
+                /* stop unneeded units regardless if going down was expected or not */
+                if (UNIT_IS_ACTIVE_OR_ACTIVATING(os) && UNIT_IS_INACTIVE_OR_DEACTIVATING(ns))
+                        check_unneeded_dependencies(u);
+
                 if (ns != os && ns == UNIT_FAILED) {
                         log_notice("Unit %s entered failed state.", u->meta.id);
                         unit_trigger_on_failure(u);
@@ -2426,7 +2439,7 @@ int unit_coldplug(Unit *u) {
         return 0;
 }
 
-void unit_status_printf(Unit *u, const char *format, ...) {
+void unit_status_printf(Unit *u, const char *status, const char *format, ...) {
         va_list ap;
 
         assert(u);
@@ -2442,7 +2455,7 @@ void unit_status_printf(Unit *u, const char *format, ...) {
                 return;
 
         va_start(ap, format);
-        status_vprintf(format, ap);
+        status_vprintf(status, true, format, ap);
         va_end(ap);
 }
 
@@ -2501,7 +2514,7 @@ bool unit_pending_inactive(Unit *u) {
 bool unit_pending_active(Unit *u) {
         assert(u);
 
-        /* Returns true if the unit is inactive or going down */
+        /* Returns true if the unit is active or going up */
 
         if (UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u)))
                 return true;