X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fscope.c;h=0c1d17e68c569a2fd5bcfaa1261db29a756875c3;hb=c7040b5d1c2c148f12b6a5eef3dfce1661805131;hp=87983f6b1746aa9537b01bb0689afa5252d49dd8;hpb=68db7a3bd9b2f8640c7297382b6d20eb995f7e1e;p=elogind.git diff --git a/src/core/scope.c b/src/core/scope.c index 87983f6b1..0c1d17e68 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -64,6 +64,8 @@ static void scope_done(Unit *u) { cgroup_context_done(&s->cgroup_context); + free(s->controller); + set_free(s->pids); s->pids = NULL; @@ -217,6 +219,7 @@ static void scope_enter_dead(Scope *s, ScopeResult f) { } static void scope_enter_signal(Scope *s, ScopeState state, ScopeResult f) { + bool skip_signal = false; int r; assert(s); @@ -224,13 +227,22 @@ static void scope_enter_signal(Scope *s, ScopeState state, ScopeResult f) { if (f != SCOPE_SUCCESS) s->result = f; - r = unit_kill_context( - UNIT(s), - &s->kill_context, - state != SCOPE_STOP_SIGTERM, - -1, -1, false); - if (r < 0) - goto fail; + /* If we have a controller set let's ask the controller nicely + * to terminate the scope, instead of us going directly into + * SIGTERM beserk mode */ + if (state == SCOPE_STOP_SIGTERM) + skip_signal = bus_scope_send_request_stop(s) > 0; + + if (!skip_signal) { + r = unit_kill_context( + UNIT(s), + &s->kill_context, + state != SCOPE_STOP_SIGTERM, + -1, -1, false); + if (r < 0) + goto fail; + } else + r = 1; if (r > 0) { r = scope_arm_timer(s); @@ -238,7 +250,9 @@ static void scope_enter_signal(Scope *s, ScopeState state, ScopeResult f) { goto fail; scope_set_state(s, state); - } else + } else if (state == SCOPE_STOP_SIGTERM) + scope_enter_signal(s, SCOPE_STOP_SIGKILL, SCOPE_SUCCESS); + else scope_enter_dead(s, SCOPE_SUCCESS); return;