daandemeyer / rpms / systemd

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