anitazha / rpms / systemd

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