chiark / gitweb /
Fix RemainAfterExit services keeping a hold on console
authorOlivier Brunel <jjk@jjacky.com>
Thu, 14 Nov 2013 14:52:54 +0000 (15:52 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 16 Nov 2013 17:08:11 +0000 (12:08 -0500)
When a service exits succesfully and has RemainAfterExit set, its hold
on the console (in m->n_on_console) wasn't released since the unit state
didn't change.

TODO
src/core/service.c
src/core/unit.c

diff --git a/TODO b/TODO
index 57e1122288baf3d366c63b7467196ba3045e48dd..efc7e2a1eb7d1859cdb9c31302f6962f26ccbf16 100644 (file)
--- a/TODO
+++ b/TODO
@@ -21,8 +21,6 @@ Bugfixes:
 
   Cannot add dependency job for unit display-manager.service, ignoring: Unit display-manager.service failed to load: No such file or directory. See system logs and 'systemctl status display-manager.service' for details.
 
-* Substract units in SERVICE_EXITED substate from n_on_console.
-
 Fedora 20:
 
 * external: ps should gain colums for slice and machine
index 3da32a162172166ec3d64aac0985e81d734d283e..c0ee1140a8aeddfdfd8b685c0ac4f5376010894a 100644 (file)
@@ -1519,6 +1519,22 @@ static void service_set_state(Service *s, ServiceState state) {
         if (state == SERVICE_EXITED && UNIT(s)->manager->n_reloading <= 0)
                 unit_destroy_cgroup(UNIT(s));
 
+        /* For remain_after_exit services, let's see if we can "release" the
+         * hold on the console, since unit_notify() only does that in case of
+         * change of state */
+        if (state == SERVICE_EXITED && s->remain_after_exit &&
+            UNIT(s)->manager->n_on_console > 0) {
+                ExecContext *ec = unit_get_exec_context(UNIT(s));
+                if (ec && exec_context_may_touch_console(ec)) {
+                        Manager *m = UNIT(s)->manager;
+
+                        m->n_on_console --;
+                        if (m->n_on_console == 0)
+                                /* unset no_console_output flag, since the console is free */
+                                m->no_console_output = false;
+                }
+        }
+
         if (old_state != state)
                 log_debug_unit(UNIT(s)->id,
                                "%s changed %s -> %s", UNIT(s)->id,
index 84c43f721a4869dc288f7fbba11bfc679df37706..7f463f311ba5b189a1f27b363c66f5c04bcd9dce 100644 (file)
@@ -1490,6 +1490,9 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
         if (UNIT_IS_INACTIVE_OR_FAILED(ns))
                 unit_destroy_cgroup(u);
 
+        /* Note that this doesn't apply to RemainAfterExit services exiting
+         * sucessfully, since there's no change of state in that case. Which is
+         * why it is handled in service_set_state() */
         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)) {