From: Michal Schmidt Date: Wed, 27 Feb 2013 23:01:10 +0000 (+0100) Subject: core: count active units that may mind our printing to /dev/console X-Git-Tag: v198~151 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=7ed9f6cd785634dd093e1b1550c3c6183177abf6 core: count active units that may mind our printing to /dev/console --- diff --git a/src/core/manager.h b/src/core/manager.h index 0d0255289..78e4bc640 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -226,6 +226,7 @@ struct Manager { unsigned n_failed_jobs; unsigned n_running_jobs; + unsigned n_on_console; /* Type=idle pipes */ int idle_pipe[2]; diff --git a/src/core/unit.c b/src/core/unit.c index f8a913e39..e2c06ae8b 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1357,6 +1357,21 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su if (UNIT_IS_INACTIVE_OR_FAILED(ns)) cgroup_bonding_trim_list(u->cgroup_bondings, true); + if (UNIT_IS_INACTIVE_OR_FAILED(os) != UNIT_IS_INACTIVE_OR_FAILED(ns)) { + ExecContext *ec = unit_get_exec_context(u); + if (ec && exec_context_may_touch_console(ec)) { + /* XXX The counter may get out of sync if the admin edits + * TTY-related unit file properties and issues a daemon-reload + * while the unit is active. No big deal though, because + * it influences only the printing of boot/shutdown + * status messages. */ + if (UNIT_IS_INACTIVE_OR_FAILED(ns)) + m->n_on_console--; + else + m->n_on_console++; + } + } + if (u->job) { unexpected = false;