ryantimwilson / rpms / systemd

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