chiark / gitweb /
core: count active units that may mind our printing to /dev/console
authorMichal Schmidt <mschmidt@redhat.com>
Wed, 27 Feb 2013 23:01:10 +0000 (00:01 +0100)
committerMichal Schmidt <mschmidt@redhat.com>
Thu, 28 Feb 2013 01:24:01 +0000 (02:24 +0100)
src/core/manager.h
src/core/unit.c

index 0d0255289a4b9325da1a4365b6b367491ba7bc7d..78e4bc64040a3a86bc4e07f9a43e51cbbdc069c1 100644 (file)
@@ -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];
index f8a913e39a5dbb466bba6fc06ac0ecfffc85cee1..e2c06ae8b638123fe2df8d90908fb3f408ea2f75 100644 (file)
@@ -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;