cgroup_context_done(&s->cgroup_context);
+ free(s->controller);
+
set_free(s->pids);
s->pids = NULL;
}
static void scope_enter_signal(Scope *s, ScopeState state, ScopeResult f) {
+ bool skip_signal = false;
int r;
assert(s);
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);
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;
return unit_kill_common(u, who, signo, -1, -1, error);
}
+static int scope_get_timeout(Unit *u, uint64_t *timeout) {
+ Scope *s = SCOPE(u);
+ int r;
+
+ if (!s->timer_event_source)
+ return 0;
+
+ r = sd_event_source_get_time(s->timer_event_source, timeout);
+ if (r < 0)
+ return r;
+
+ return 1;
+}
+
static int scope_serialize(Unit *u, FILE *f, FDSet *fds) {
Scope *s = SCOPE(u);
.kill = scope_kill,
+ .get_timeout = scope_get_timeout,
+
.serialize = scope_serialize,
.deserialize_item = scope_deserialize_item,