From 3611581ebdabbe3a1d6a9b5310a0b59792279d7d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 12 Jul 2011 04:05:33 +0200 Subject: [PATCH] service: properly handle who argument on D-Bus kill calls --- src/mount.c | 11 ++++++----- src/service.c | 18 ++++++++++-------- src/socket.c | 11 ++++++----- src/swap.c | 11 ++++++----- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/mount.c b/src/mount.c index 660af131..d8370414 100644 --- a/src/mount.c +++ b/src/mount.c @@ -1777,11 +1777,12 @@ static int mount_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError return -ENOENT; } - if (m->control_pid > 0) - if (kill(m->control_pid, signo) < 0) - r = -errno; + if (who == KILL_CONTROL || who == KILL_ALL) + if (m->control_pid > 0) + if (kill(m->control_pid, signo) < 0) + r = -errno; - if (mode == KILL_CONTROL_GROUP) { + if (who == KILL_ALL && mode == KILL_CONTROL_GROUP) { int q; if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) @@ -1795,7 +1796,7 @@ static int mount_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError } if ((q = cgroup_bonding_kill_list(m->meta.cgroup_bondings, signo, false, pid_set)) < 0) - if (r != -EAGAIN && r != -ESRCH && r != -ENOENT) + if (q != -EAGAIN && q != -ESRCH && q != -ENOENT) r = q; } diff --git a/src/service.c b/src/service.c index b684a37c..0b657679 100644 --- a/src/service.c +++ b/src/service.c @@ -3270,15 +3270,17 @@ static int service_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusErro return -ENOENT; } - if (s->control_pid > 0) - if (kill(s->control_pid, signo) < 0) - r = -errno; + if (who == KILL_CONTROL || who == KILL_ALL) + if (s->control_pid > 0) + if (kill(s->control_pid, signo) < 0) + r = -errno; - if (s->main_pid > 0) - if (kill(s->main_pid, signo) < 0) - r = -errno; + if (who == KILL_MAIN || who == KILL_ALL) + if (s->main_pid > 0) + if (kill(s->main_pid, signo) < 0) + r = -errno; - if (mode == KILL_CONTROL_GROUP) { + if (who == KILL_ALL && mode == KILL_CONTROL_GROUP) { int q; if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) @@ -3298,7 +3300,7 @@ static int service_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusErro } if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, false, pid_set)) < 0) - if (r != -EAGAIN && r != -ESRCH && r != -ENOENT) + if (q != -EAGAIN && q != -ESRCH && q != -ENOENT) r = q; } diff --git a/src/socket.c b/src/socket.c index 8b78a3fd..3a7aa940 100644 --- a/src/socket.c +++ b/src/socket.c @@ -2030,11 +2030,12 @@ static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError return -ENOENT; } - if (s->control_pid > 0) - if (kill(s->control_pid, signo) < 0) - r = -errno; + if (who == KILL_CONTROL || who == KILL_ALL) + if (s->control_pid > 0) + if (kill(s->control_pid, signo) < 0) + r = -errno; - if (mode == KILL_CONTROL_GROUP) { + if (who == KILL_ALL && mode == KILL_CONTROL_GROUP) { int q; if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) @@ -2048,7 +2049,7 @@ static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError } if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, false, pid_set)) < 0) - if (r != -EAGAIN && r != -ESRCH && r != -ENOENT) + if (q != -EAGAIN && q != -ESRCH && q != -ENOENT) r = q; } diff --git a/src/swap.c b/src/swap.c index 7675e6af..a0b16776 100644 --- a/src/swap.c +++ b/src/swap.c @@ -1286,11 +1286,12 @@ static int swap_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError * return -ENOENT; } - if (s->control_pid > 0) - if (kill(s->control_pid, signo) < 0) - r = -errno; + if (who == KILL_CONTROL || who == KILL_ALL) + if (s->control_pid > 0) + if (kill(s->control_pid, signo) < 0) + r = -errno; - if (mode == KILL_CONTROL_GROUP) { + if (who == KILL_ALL && mode == KILL_CONTROL_GROUP) { int q; if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) @@ -1304,7 +1305,7 @@ static int swap_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError * } if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, false, pid_set)) < 0) - if (r != -EAGAIN && r != -ESRCH && r != -ENOENT) + if (q != -EAGAIN && q != -ESRCH && q != -ENOENT) r = q; } -- 2.39.5