summaryrefslogtreecommitdiff
path: root/src/core/service.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-01-26 05:53:30 +0100
committerLennart Poettering <lennart@poettering.net>2013-01-26 05:53:30 +0100
commitcd2086fe6573df923dc53ef33998c9fff8c2bda5 (patch)
tree35d5f1777dc4752dbe2b8d1ca5d0d16363c6d368 /src/core/service.c
parentf2956e80c99cd41ca6bbbe41b09e01b234ca8778 (diff)
core: unify kill code of mount, service, socket, swap units
Diffstat (limited to 'src/core/service.c')
-rw-r--r--src/core/service.c64
1 files changed, 10 insertions, 54 deletions
diff --git a/src/core/service.c b/src/core/service.c
index baddc5ade4..914146383c 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -1955,64 +1955,23 @@ fail:
static void service_enter_signal(Service *s, ServiceState state, ServiceResult f) {
int r;
- Set *pid_set = NULL;
- bool wait_for_exit = false;
assert(s);
if (f != SERVICE_SUCCESS)
s->result = f;
- if (s->kill_context.kill_mode != KILL_NONE) {
- int sig = (state == SERVICE_STOP_SIGTERM || state == SERVICE_FINAL_SIGTERM) ? s->kill_context.kill_signal : SIGKILL;
-
- if (s->main_pid > 0) {
- if (kill_and_sigcont(s->main_pid, sig) < 0 && errno != ESRCH)
- log_warning_unit(UNIT(s)->id,
- "Failed to kill main process %li: %m", (long) s->main_pid);
- else
- wait_for_exit = !s->main_pid_alien;
- }
-
- if (s->control_pid > 0) {
- if (kill_and_sigcont(s->control_pid, sig) < 0 && errno != ESRCH)
- log_warning_unit(UNIT(s)->id,
- "Failed to kill control process %li: %m", (long) s->control_pid);
- else
- wait_for_exit = true;
- }
-
- if (s->kill_context.kill_mode == KILL_CONTROL_GROUP) {
-
- pid_set = set_new(trivial_hash_func, trivial_compare_func);
- if (!pid_set) {
- r = -ENOMEM;
- goto fail;
- }
-
- /* Exclude the main/control pids from being killed via the cgroup */
- if (s->main_pid > 0)
- if ((r = set_put(pid_set, LONG_TO_PTR(s->main_pid))) < 0)
- goto fail;
-
- if (s->control_pid > 0)
- if ((r = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0)
- goto fail;
-
- r = cgroup_bonding_kill_list(UNIT(s)->cgroup_bondings, sig, true, false, pid_set, NULL);
- if (r < 0) {
- if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
- log_warning_unit(UNIT(s)->id,
- "Failed to kill control group: %s", strerror(-r));
- } else if (r > 0)
- wait_for_exit = true;
-
- set_free(pid_set);
- pid_set = NULL;
- }
- }
+ r = unit_kill_context(
+ UNIT(s),
+ &s->kill_context,
+ state != SERVICE_STOP_SIGTERM && state != SERVICE_FINAL_SIGTERM,
+ s->main_pid,
+ s->control_pid,
+ s->main_pid_alien);
+ if (r < 0)
+ goto fail;
- if (wait_for_exit) {
+ if (r > 0) {
if (s->timeout_stop_usec > 0) {
r = unit_watch_timer(UNIT(s), CLOCK_MONOTONIC, true, s->timeout_stop_usec, &s->timer_watch);
if (r < 0)
@@ -2035,9 +1994,6 @@ fail:
service_enter_stop_post(s, SERVICE_FAILURE_RESOURCES);
else
service_enter_dead(s, SERVICE_FAILURE_RESOURCES, true);
-
- if (pid_set)
- set_free(pid_set);
}
static void service_enter_stop(Service *s, ServiceResult f) {