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