filbranden / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone
a52f674
From 6a60d6b627d8bc8602b46c29bb89ddcb92f08efd Mon Sep 17 00:00:00 2001
930e1b8
From: Olivier Brunel <jjk@jjacky.com>
930e1b8
Date: Thu, 14 Nov 2013 15:52:54 +0100
930e1b8
Subject: [PATCH] Fix RemainAfterExit services keeping a hold on console
930e1b8
930e1b8
When a service exits succesfully and has RemainAfterExit set, its hold
930e1b8
on the console (in m->n_on_console) wasn't released since the unit state
930e1b8
didn't change.
930e1b8
---
930e1b8
 src/core/service.c | 16 ++++++++++++++++
930e1b8
 src/core/unit.c    |  3 +++
930e1b8
 2 files changed, 19 insertions(+)
930e1b8
930e1b8
diff --git a/src/core/service.c b/src/core/service.c
930e1b8
index 5662180..62ae8f0 100644
930e1b8
--- a/src/core/service.c
930e1b8
+++ b/src/core/service.c
930e1b8
@@ -1570,6 +1570,22 @@ static void service_set_state(Service *s, ServiceState state) {
930e1b8
         if (state == SERVICE_EXITED && UNIT(s)->manager->n_reloading <= 0)
930e1b8
                 unit_destroy_cgroup(UNIT(s));
930e1b8
 
930e1b8
+        /* For remain_after_exit services, let's see if we can "release" the
930e1b8
+         * hold on the console, since unit_notify() only does that in case of
930e1b8
+         * change of state */
930e1b8
+        if (state == SERVICE_EXITED && s->remain_after_exit &&
930e1b8
+            UNIT(s)->manager->n_on_console > 0) {
930e1b8
+                ExecContext *ec = unit_get_exec_context(UNIT(s));
930e1b8
+                if (ec && exec_context_may_touch_console(ec)) {
930e1b8
+                        Manager *m = UNIT(s)->manager;
930e1b8
+
930e1b8
+                        m->n_on_console --;
930e1b8
+                        if (m->n_on_console == 0)
930e1b8
+                                /* unset no_console_output flag, since the console is free */
930e1b8
+                                m->no_console_output = false;
930e1b8
+                }
930e1b8
+        }
930e1b8
+
930e1b8
         if (old_state != state)
930e1b8
                 log_debug_unit(UNIT(s)->id,
930e1b8
                                "%s changed %s -> %s", UNIT(s)->id,
930e1b8
diff --git a/src/core/unit.c b/src/core/unit.c
930e1b8
index 717ce84..b65e798 100644
930e1b8
--- a/src/core/unit.c
930e1b8
+++ b/src/core/unit.c
930e1b8
@@ -1446,6 +1446,9 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
930e1b8
         if (UNIT_IS_INACTIVE_OR_FAILED(ns))
930e1b8
                 unit_destroy_cgroup(u);
930e1b8
 
930e1b8
+        /* Note that this doesn't apply to RemainAfterExit services exiting
930e1b8
+         * sucessfully, since there's no change of state in that case. Which is
930e1b8
+         * why it is handled in service_set_state() */
930e1b8
         if (UNIT_IS_INACTIVE_OR_FAILED(os) != UNIT_IS_INACTIVE_OR_FAILED(ns)) {
930e1b8
                 ExecContext *ec = unit_get_exec_context(u);
930e1b8
                 if (ec && exec_context_may_touch_console(ec)) {