X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Funit.c;h=b31b92fc24ebb054ae1f898f097aec81e2821db2;hb=54fe0cdbe313558a712a15dc3bc516a46c1f7b6e;hp=56137d7bd14c60ae423c80884d0cb48a5dd536aa;hpb=f60c2665f9ba1dd4a6b4a36b2e8195482ada9957;p=elogind.git diff --git a/src/unit.c b/src/unit.c index 56137d7bd..b31b92fc2 100644 --- a/src/unit.c +++ b/src/unit.c @@ -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; @@ -1105,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) @@ -1263,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); @@ -2429,9 +2441,6 @@ int unit_coldplug(Unit *u) { void unit_status_printf(Unit *u, const char *status, const char *format, ...) { va_list ap; - char *s, *e; - int err; - const unsigned emax = status ? 80 - (sizeof("[ OK ]")-1) : 80; assert(u); assert(format); @@ -2446,21 +2455,8 @@ void unit_status_printf(Unit *u, const char *status, const char *format, ...) { return; va_start(ap, format); - err = vasprintf(&s, format, ap); + status_vprintf(status, true, format, ap); va_end(ap); - if (err < 0) - return; - - e = ellipsize(s, emax, 100); - free(s); - if (!e) - return; - - if (status) - status_printf("%s%*s[%s]\n", e, emax - strlen(e), "", status); - else - status_printf("%s\n", e); - free(e); } bool unit_need_daemon_reload(Unit *u) {