Fix RemainAfterExit services keeping a hold on console

When a service exits succesfully and has RemainAfterExit set, its hold
on the console (in m->n_on_console) wasn't released since the unit state
didn't change.
This commit is contained in:
Olivier Brunel
2014-02-23 12:41:51 +00:00
committed by Colin Guthrie
parent f84f575e8b
commit 6a60d6b627
2 changed files with 19 additions and 0 deletions
+16
View File
@@ -1570,6 +1570,22 @@ static void service_set_state(Service *s, ServiceState state) {
if (state == SERVICE_EXITED && UNIT(s)->manager->n_reloading <= 0)
unit_destroy_cgroup(UNIT(s));
/* For remain_after_exit services, let's see if we can "release" the
* hold on the console, since unit_notify() only does that in case of
* change of state */
if (state == SERVICE_EXITED && s->remain_after_exit &&
UNIT(s)->manager->n_on_console > 0) {
ExecContext *ec = unit_get_exec_context(UNIT(s));
if (ec && exec_context_may_touch_console(ec)) {
Manager *m = UNIT(s)->manager;
m->n_on_console --;
if (m->n_on_console == 0)
/* unset no_console_output flag, since the console is free */
m->no_console_output = false;
}
}
if (old_state != state)
log_debug_unit(UNIT(s)->id,
"%s changed %s -> %s", UNIT(s)->id,
+3
View File
@@ -1446,6 +1446,9 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
if (UNIT_IS_INACTIVE_OR_FAILED(ns))
unit_destroy_cgroup(u);
/* Note that this doesn't apply to RemainAfterExit services exiting
* sucessfully, since there's no change of state in that case. Which is
* why it is handled in service_set_state() */
if (UNIT_IS_INACTIVE_OR_FAILED(os) != UNIT_IS_INACTIVE_OR_FAILED(ns)) {
ExecContext *ec = unit_get_exec_context(u);
if (ec && exec_context_may_touch_console(ec)) {