From c74f17d96cccd4cc998fd037cb92046930188c91 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 20 Jul 2012 00:00:04 +0200 Subject: [PATCH] core: drop KillMode parameter from KillUnit() bus call It made no sense, and since we are documenting the bus calls now and want to include them in our stability promise we really should get it cleaned up sooner, not later. --- src/core/dbus-manager.c | 19 +++++-------------- src/core/dbus-unit.c | 18 +++++------------- src/core/dbus-unit.h | 1 - src/core/kill.h | 2 ++ src/core/mount.c | 18 ++++++++++-------- src/core/service.c | 25 +++++++++++++++---------- src/core/socket.c | 18 ++++++++++-------- src/core/swap.c | 18 ++++++++++-------- src/core/unit.c | 8 ++------ src/core/unit.h | 4 ++-- src/systemctl/systemctl.c | 11 ----------- 11 files changed, 61 insertions(+), 81 deletions(-) diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 925e87cc5..c341d36a6 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -94,7 +94,6 @@ " \n" \ " \n" \ " \n" \ - " \n" \ " \n" \ " \n" \ " \n" \ @@ -665,10 +664,9 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, reload_if_possible = true; job_type = JOB_TRY_RESTART; } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "KillUnit")) { - const char *name, *swho, *smode; + const char *name, *swho; int32_t signo; Unit *u; - KillMode mode; KillWho who; if (!dbus_message_get_args( @@ -676,7 +674,6 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &swho, - DBUS_TYPE_STRING, &smode, DBUS_TYPE_INT32, &signo, DBUS_TYPE_INVALID)) return bus_send_error_reply(connection, message, &error, -EINVAL); @@ -689,23 +686,17 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, return bus_send_error_reply(connection, message, &error, -EINVAL); } - if (isempty(smode)) - mode = KILL_CONTROL_GROUP; - else { - mode = kill_mode_from_string(smode); - if (mode < 0) - return bus_send_error_reply(connection, message, &error, -EINVAL); - } - if (signo <= 0 || signo >= _NSIG) return bus_send_error_reply(connection, message, &error, -EINVAL); - if (!(u = manager_get_unit(m, name))) { + u = manager_get_unit(m, name); + if (!u) { dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name); return bus_send_error_reply(connection, message, &error, -ENOENT); } - if ((r = unit_kill(u, who, mode, signo, &error)) < 0) + r = unit_kill(u, who, signo, &error); + if (r < 0) return bus_send_error_reply(connection, message, &error, r); if (!(reply = dbus_message_new_method_return(message))) diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 21145873e..2d2f378ba 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -431,9 +431,8 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn reload_if_possible = true; job_type = JOB_TRY_RESTART; } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "Kill")) { - const char *swho, *smode; + const char *swho; int32_t signo; - KillMode mode; KillWho who; int r; @@ -441,7 +440,6 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn message, &error, DBUS_TYPE_STRING, &swho, - DBUS_TYPE_STRING, &smode, DBUS_TYPE_INT32, &signo, DBUS_TYPE_INVALID)) return bus_send_error_reply(connection, message, &error, -EINVAL); @@ -454,21 +452,15 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn return bus_send_error_reply(connection, message, &error, -EINVAL); } - if (isempty(smode)) - mode = KILL_CONTROL_GROUP; - else { - mode = kill_mode_from_string(smode); - if (mode < 0) - return bus_send_error_reply(connection, message, &error, -EINVAL); - } - if (signo <= 0 || signo >= _NSIG) return bus_send_error_reply(connection, message, &error, -EINVAL); - if ((r = unit_kill(u, who, mode, signo, &error)) < 0) + r = unit_kill(u, who, signo, &error); + if (r < 0) return bus_send_error_reply(connection, message, &error, r); - if (!(reply = dbus_message_new_method_return(message))) + reply = dbus_message_new_method_return(message); + if (!reply) goto oom; } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "ResetFailed")) { diff --git a/src/core/dbus-unit.h b/src/core/dbus-unit.h index 5a3a9be53..7ab355c27 100644 --- a/src/core/dbus-unit.h +++ b/src/core/dbus-unit.h @@ -58,7 +58,6 @@ " \n" \ " \n" \ " \n" \ - " \n" \ " \n" \ " \n" \ " \n" \ diff --git a/src/core/kill.h b/src/core/kill.h index 4f8823927..3c9b0ab8d 100644 --- a/src/core/kill.h +++ b/src/core/kill.h @@ -27,6 +27,7 @@ typedef struct KillContext KillContext; #include typedef enum KillMode { + /* The kill mode is a property of a unit. */ KILL_CONTROL_GROUP = 0, KILL_PROCESS, KILL_NONE, @@ -41,6 +42,7 @@ struct KillContext { }; typedef enum KillWho { + /* Kill who is a property of an operation */ KILL_MAIN, KILL_CONTROL, KILL_ALL, diff --git a/src/core/mount.c b/src/core/mount.c index 82c64ff79..5709db226 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -1708,7 +1708,7 @@ static void mount_reset_failed(Unit *u) { m->reload_result = MOUNT_SUCCESS; } -static int mount_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) { +static int mount_kill(Unit *u, KillWho who, int signo, DBusError *error) { Mount *m = MOUNT(u); int r = 0; Set *pid_set = NULL; @@ -1730,23 +1730,25 @@ static int mount_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError if (kill(m->control_pid, signo) < 0) r = -errno; - if (who == KILL_ALL && mode == KILL_CONTROL_GROUP) { + if (who == KILL_ALL) { int q; - if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) + pid_set = set_new(trivial_hash_func, trivial_compare_func); + if (!pid_set) return -ENOMEM; /* Exclude the control pid from being killed via the cgroup */ - if (m->control_pid > 0) - if ((q = set_put(pid_set, LONG_TO_PTR(m->control_pid))) < 0) { + if (m->control_pid > 0) { + q = set_put(pid_set, LONG_TO_PTR(m->control_pid)); + if (q < 0) { r = q; goto finish; } + } q = cgroup_bonding_kill_list(UNIT(m)->cgroup_bondings, signo, false, false, pid_set, NULL); - if (q < 0) - if (q != -EAGAIN && q != -ESRCH && q != -ENOENT) - r = q; + if (q < 0 && q != -EAGAIN && q != -ESRCH && q != -ENOENT) + r = q; } finish: diff --git a/src/core/service.c b/src/core/service.c index 567e9a4eb..78f9a59c7 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -3673,7 +3673,7 @@ static void service_reset_failed(Unit *u) { RATELIMIT_RESET(s->start_limit); } -static int service_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) { +static int service_kill(Unit *u, KillWho who, int signo, DBusError *error) { Service *s = SERVICE(u); int r = 0; Set *pid_set = NULL; @@ -3700,28 +3700,33 @@ static int service_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusErro if (kill(s->main_pid, signo) < 0) r = -errno; - if (who == KILL_ALL && mode == KILL_CONTROL_GROUP) { + if (who == KILL_ALL) { int q; - if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) + pid_set = set_new(trivial_hash_func, trivial_compare_func); + if (!pid_set) return -ENOMEM; /* Exclude the control/main pid from being killed via the cgroup */ - if (s->control_pid > 0) - if ((q = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0) { + if (s->control_pid > 0) { + q = set_put(pid_set, LONG_TO_PTR(s->control_pid)); + if (q < 0) { r = q; goto finish; } + } - if (s->main_pid > 0) - if ((q = set_put(pid_set, LONG_TO_PTR(s->main_pid))) < 0) { + if (s->main_pid > 0) { + q = set_put(pid_set, LONG_TO_PTR(s->main_pid)); + if (q < 0) { r = q; goto finish; } + } + q = cgroup_bonding_kill_list(UNIT(s)->cgroup_bondings, signo, false, false, pid_set, NULL); - if (q < 0) - if (q != -EAGAIN && q != -ESRCH && q != -ENOENT) - r = q; + if (q < 0 && q != -EAGAIN && q != -ESRCH && q != -ENOENT) + r = q; } finish: diff --git a/src/core/socket.c b/src/core/socket.c index 6d417878b..19b463e6a 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -2104,7 +2104,7 @@ static void socket_reset_failed(Unit *u) { s->result = SOCKET_SUCCESS; } -static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) { +static int socket_kill(Unit *u, KillWho who, int signo, DBusError *error) { Socket *s = SOCKET(u); int r = 0; Set *pid_set = NULL; @@ -2126,23 +2126,25 @@ static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError if (kill(s->control_pid, signo) < 0) r = -errno; - if (who == KILL_ALL && mode == KILL_CONTROL_GROUP) { + if (who == KILL_ALL) { int q; - if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) + pid_set = set_new(trivial_hash_func, trivial_compare_func); + if (!pid_set) return -ENOMEM; /* Exclude the control pid from being killed via the cgroup */ - if (s->control_pid > 0) - if ((q = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0) { + if (s->control_pid > 0) { + q = set_put(pid_set, LONG_TO_PTR(s->control_pid)); + if (q < 0) { r = q; goto finish; } + } q = cgroup_bonding_kill_list(UNIT(s)->cgroup_bondings, signo, false, false, pid_set, NULL); - if (q < 0) - if (q != -EAGAIN && q != -ESRCH && q != -ENOENT) - r = q; + if (q < 0 && q != -EAGAIN && q != -ESRCH && q != -ENOENT) + r = q; } finish: diff --git a/src/core/swap.c b/src/core/swap.c index 03993b1e6..91bb0215b 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -1260,7 +1260,7 @@ static void swap_reset_failed(Unit *u) { s->result = SWAP_SUCCESS; } -static int swap_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) { +static int swap_kill(Unit *u, KillWho who, int signo, DBusError *error) { Swap *s = SWAP(u); int r = 0; Set *pid_set = NULL; @@ -1282,23 +1282,25 @@ static int swap_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError * if (kill(s->control_pid, signo) < 0) r = -errno; - if (who == KILL_ALL && mode == KILL_CONTROL_GROUP) { + if (who == KILL_ALL) { int q; - if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) + pid_set = set_new(trivial_hash_func, trivial_compare_func); + if (!pid_set) return -ENOMEM; /* Exclude the control pid from being killed via the cgroup */ - if (s->control_pid > 0) - if ((q = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0) { + if (s->control_pid > 0) { + q = set_put(pid_set, LONG_TO_PTR(s->control_pid)); + if (q < 0) { r = q; goto finish; } + } q = cgroup_bonding_kill_list(UNIT(s)->cgroup_bondings, signo, false, false, pid_set, NULL); - if (q < 0) - if (q != -EAGAIN && q != -ESRCH && q != -ENOENT) - r = q; + if (q < 0 && q != -EAGAIN && q != -ESRCH && q != -ENOENT) + r = q; } finish: diff --git a/src/core/unit.c b/src/core/unit.c index ae6f69183..3b416f945 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2721,20 +2721,16 @@ bool unit_pending_active(Unit *u) { return false; } -int unit_kill(Unit *u, KillWho w, KillMode m, int signo, DBusError *error) { +int unit_kill(Unit *u, KillWho w, int signo, DBusError *error) { assert(u); assert(w >= 0 && w < _KILL_WHO_MAX); - assert(m >= 0 && m < _KILL_MODE_MAX); assert(signo > 0); assert(signo < _NSIG); - if (m == KILL_NONE) - return 0; - if (!UNIT_VTABLE(u)->kill) return -ENOTSUP; - return UNIT_VTABLE(u)->kill(u, w, m, signo, error); + return UNIT_VTABLE(u)->kill(u, w, signo, error); } int unit_following_set(Unit *u, Set **s) { diff --git a/src/core/unit.h b/src/core/unit.h index 635293ffb..f00417989 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -293,7 +293,7 @@ struct UnitVTable { int (*stop)(Unit *u); int (*reload)(Unit *u); - int (*kill)(Unit *u, KillWho w, KillMode m, int signo, DBusError *error); + int (*kill)(Unit *u, KillWho w, int signo, DBusError *error); bool (*can_reload)(Unit *u); @@ -468,7 +468,7 @@ int unit_start(Unit *u); int unit_stop(Unit *u); int unit_reload(Unit *u); -int unit_kill(Unit *u, KillWho w, KillMode m, int signo, DBusError *error); +int unit_kill(Unit *u, KillWho w, int signo, DBusError *error); void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 344dcd3e7..e587cfbfa 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -86,7 +86,6 @@ static bool arg_failed = false; static bool arg_runtime = false; static char **arg_wall = NULL; static const char *arg_kill_who = NULL; -static const char *arg_kill_mode = NULL; static int arg_signal = SIGTERM; static const char *arg_root = NULL; static usec_t arg_when = 0; @@ -2140,9 +2139,6 @@ static int kill_unit(DBusConnection *bus, char **args) { if (!arg_kill_who) arg_kill_who = "all"; - if (!arg_kill_mode) - arg_kill_mode = streq(arg_kill_who, "all") ? "control-group" : "process"; - STRV_FOREACH(name, args+1) { DBusMessage *reply; char *n; @@ -2163,7 +2159,6 @@ static int kill_unit(DBusConnection *bus, char **args) { b = dbus_message_append_args(m, DBUS_TYPE_STRING, n ? &n : name, DBUS_TYPE_STRING, &arg_kill_who, - DBUS_TYPE_STRING, &arg_kill_mode, DBUS_TYPE_INT32, &arg_signal, DBUS_TYPE_INVALID); free(n); @@ -4593,7 +4588,6 @@ static int systemctl_parse_argv(int argc, char *argv[]) { ARG_ROOT, ARG_FULL, ARG_NO_RELOAD, - ARG_KILL_MODE, ARG_KILL_WHO, ARG_NO_ASK_PASSWORD, ARG_FAILED, @@ -4625,7 +4619,6 @@ static int systemctl_parse_argv(int argc, char *argv[]) { { "root", required_argument, NULL, ARG_ROOT }, { "force", no_argument, NULL, ARG_FORCE }, { "no-reload", no_argument, NULL, ARG_NO_RELOAD }, - { "kill-mode", required_argument, NULL, ARG_KILL_MODE }, /* undocumented on purpose */ { "kill-who", required_argument, NULL, ARG_KILL_WHO }, { "signal", required_argument, NULL, 's' }, { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD }, @@ -4771,10 +4764,6 @@ static int systemctl_parse_argv(int argc, char *argv[]) { arg_kill_who = optarg; break; - case ARG_KILL_MODE: - arg_kill_mode = optarg; - break; - case 's': if ((arg_signal = signal_from_string_try_harder(optarg)) < 0) { log_error("Failed to parse signal string %s.", optarg); -- 2.30.2