core: track scope controllers on the bus

This watches controllers on the bus, and unsets them automatically when
they disappear.

Note that this is primarily a cosmetical fix. Since unique bus names are not
recycled, there's strictly no need to forget about them, but it's a lot
nicer to do so.
This commit is contained in:
Lennart Poettering
2017-11-23 21:47:48 +01:00
parent f2c49c8658
commit 371c0b794e
4 changed files with 53 additions and 5 deletions
+11 -4
View File
@@ -59,7 +59,8 @@ static void scope_done(Unit *u) {
assert(u);
free(s->controller);
s->controller = mfree(s->controller);
s->controller_track = sd_bus_track_unref(s->controller_track);
s->timer_event_source = sd_event_source_unref(s->timer_event_source);
}
@@ -229,6 +230,8 @@ static int scope_coldplug(Unit *u) {
if (!IN_SET(s->deserialized_state, SCOPE_DEAD, SCOPE_FAILED))
unit_watch_all_pids(UNIT(s));
bus_scope_track_controller(s);
scope_set_state(s, s->deserialized_state);
return 0;
}
@@ -272,9 +275,8 @@ static void scope_enter_signal(Scope *s, ScopeState state, ScopeResult f) {
unit_watch_all_pids(UNIT(s));
/* If we have a controller set let's ask the controller nicely
* to terminate the scope, instead of us going directly into
* SIGTERM berserk mode */
/* If we have a controller set let's ask the controller nicely to terminate the scope, instead of us going
* directly into SIGTERM berserk mode */
if (state == SCOPE_STOP_SIGTERM)
skip_signal = bus_scope_send_request_stop(s) > 0;
@@ -332,6 +334,8 @@ static int scope_start(Unit *u) {
if (!u->transient && !MANAGER_IS_RELOADING(u->manager))
return -ENOENT;
(void) bus_scope_track_controller(s);
r = unit_acquire_invocation_id(u);
if (r < 0)
return r;
@@ -536,7 +540,10 @@ int scope_abandon(Scope *s) {
return -ESTALE;
s->was_abandoned = true;
s->controller = mfree(s->controller);
s->controller_track = sd_bus_track_unref(s->controller_track);
scope_set_state(s, SCOPE_ABANDONED);
/* The client is no longer watching the remaining processes,