Fix confusion between killer and prey
"who" is the entity doing the killing, "whom" is the target.
Follow-up for 4ccde410a3.
This commit is contained in:
@@ -504,9 +504,9 @@ int bus_unit_method_enqueue_job(sd_bus_message *message, void *userdata, sd_bus_
|
||||
int bus_unit_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
Unit *u = ASSERT_PTR(userdata);
|
||||
int32_t value = 0;
|
||||
const char *swho;
|
||||
const char *swhom;
|
||||
int32_t signo;
|
||||
KillWho who;
|
||||
KillWhom whom;
|
||||
int r, code;
|
||||
|
||||
assert(message);
|
||||
@@ -515,7 +515,7 @@ int bus_unit_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_read(message, "si", &swho, &signo);
|
||||
r = sd_bus_message_read(message, "si", &swhom, &signo);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -528,12 +528,12 @@ int bus_unit_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *
|
||||
} else
|
||||
code = SI_USER;
|
||||
|
||||
if (isempty(swho))
|
||||
who = KILL_ALL;
|
||||
if (isempty(swhom))
|
||||
whom = KILL_ALL;
|
||||
else {
|
||||
who = kill_who_from_string(swho);
|
||||
if (who < 0)
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid who argument: %s", swho);
|
||||
whom = kill_whom_from_string(swhom);
|
||||
if (whom < 0)
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid whom argument: %s", swhom);
|
||||
}
|
||||
|
||||
if (!SIGNAL_VALID(signo))
|
||||
@@ -554,7 +554,7 @@ int bus_unit_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *
|
||||
if (r == 0)
|
||||
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
|
||||
|
||||
r = unit_kill(u, who, signo, code, value, error);
|
||||
r = unit_kill(u, whom, signo, code, value, error);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
+2
-2
@@ -44,7 +44,7 @@ static const char* const kill_mode_table[_KILL_MODE_MAX] = {
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(kill_mode, KillMode);
|
||||
|
||||
static const char* const kill_who_table[_KILL_WHO_MAX] = {
|
||||
static const char* const kill_whom_table[_KILL_WHOM_MAX] = {
|
||||
[KILL_MAIN] = "main",
|
||||
[KILL_CONTROL] = "control",
|
||||
[KILL_ALL] = "all",
|
||||
@@ -53,4 +53,4 @@ static const char* const kill_who_table[_KILL_WHO_MAX] = {
|
||||
[KILL_ALL_FAIL] = "all-fail",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(kill_who, KillWho);
|
||||
DEFINE_STRING_TABLE_LOOKUP(kill_whom, KillWhom);
|
||||
|
||||
+7
-7
@@ -28,17 +28,17 @@ struct KillContext {
|
||||
bool send_sighup;
|
||||
};
|
||||
|
||||
typedef enum KillWho {
|
||||
/* Kill who is a property of an operation */
|
||||
typedef enum KillWhom {
|
||||
/* Kill whom is a property of an operation */
|
||||
KILL_MAIN,
|
||||
KILL_CONTROL,
|
||||
KILL_ALL,
|
||||
KILL_MAIN_FAIL,
|
||||
KILL_CONTROL_FAIL,
|
||||
KILL_ALL_FAIL,
|
||||
_KILL_WHO_MAX,
|
||||
_KILL_WHO_INVALID = -EINVAL,
|
||||
} KillWho;
|
||||
_KILL_WHOM_MAX,
|
||||
_KILL_WHOM_INVALID = -EINVAL,
|
||||
} KillWhom;
|
||||
|
||||
void kill_context_init(KillContext *c);
|
||||
void kill_context_dump(KillContext *c, FILE *f, const char *prefix);
|
||||
@@ -46,8 +46,8 @@ void kill_context_dump(KillContext *c, FILE *f, const char *prefix);
|
||||
const char *kill_mode_to_string(KillMode k) _const_;
|
||||
KillMode kill_mode_from_string(const char *s) _pure_;
|
||||
|
||||
const char *kill_who_to_string(KillWho k) _const_;
|
||||
KillWho kill_who_from_string(const char *s) _pure_;
|
||||
const char *kill_whom_to_string(KillWhom k) _const_;
|
||||
KillWhom kill_whom_from_string(const char *s) _pure_;
|
||||
|
||||
static inline int restart_kill_signal(const KillContext *c) {
|
||||
if (c->restart_kill_signal != 0)
|
||||
|
||||
+9
-9
@@ -4011,7 +4011,7 @@ static int unit_kill_one(
|
||||
|
||||
int unit_kill(
|
||||
Unit *u,
|
||||
KillWho who,
|
||||
KillWhom whom,
|
||||
int signo,
|
||||
int code,
|
||||
int value,
|
||||
@@ -4026,8 +4026,8 @@ int unit_kill(
|
||||
* stop a service ourselves. */
|
||||
|
||||
assert(u);
|
||||
assert(who >= 0);
|
||||
assert(who < _KILL_WHO_MAX);
|
||||
assert(whom >= 0);
|
||||
assert(whom < _KILL_WHOM_MAX);
|
||||
assert(SIGNAL_VALID(signo));
|
||||
assert(IN_SET(code, SI_USER, SI_QUEUE));
|
||||
|
||||
@@ -4037,27 +4037,27 @@ int unit_kill(
|
||||
if (!UNIT_HAS_CGROUP_CONTEXT(u) && !main_pid && !control_pid)
|
||||
return sd_bus_error_setf(ret_error, SD_BUS_ERROR_NOT_SUPPORTED, "Unit type does not support process killing.");
|
||||
|
||||
if (IN_SET(who, KILL_MAIN, KILL_MAIN_FAIL)) {
|
||||
if (IN_SET(whom, KILL_MAIN, KILL_MAIN_FAIL)) {
|
||||
if (!main_pid)
|
||||
return sd_bus_error_setf(ret_error, BUS_ERROR_NO_SUCH_PROCESS, "%s units have no main processes", unit_type_to_string(u->type));
|
||||
if (!pidref_is_set(main_pid))
|
||||
return sd_bus_error_set_const(ret_error, BUS_ERROR_NO_SUCH_PROCESS, "No main process to kill");
|
||||
}
|
||||
|
||||
if (IN_SET(who, KILL_CONTROL, KILL_CONTROL_FAIL)) {
|
||||
if (IN_SET(whom, KILL_CONTROL, KILL_CONTROL_FAIL)) {
|
||||
if (!control_pid)
|
||||
return sd_bus_error_setf(ret_error, BUS_ERROR_NO_SUCH_PROCESS, "%s units have no control processes", unit_type_to_string(u->type));
|
||||
if (!pidref_is_set(control_pid))
|
||||
return sd_bus_error_set_const(ret_error, BUS_ERROR_NO_SUCH_PROCESS, "No control process to kill");
|
||||
}
|
||||
|
||||
if (IN_SET(who, KILL_CONTROL, KILL_CONTROL_FAIL, KILL_ALL, KILL_ALL_FAIL)) {
|
||||
if (IN_SET(whom, KILL_CONTROL, KILL_CONTROL_FAIL, KILL_ALL, KILL_ALL_FAIL)) {
|
||||
r = unit_kill_one(u, control_pid, "control", signo, code, value, ret_error);
|
||||
RET_GATHER(ret, r);
|
||||
killed = killed || r > 0;
|
||||
}
|
||||
|
||||
if (IN_SET(who, KILL_MAIN, KILL_MAIN_FAIL, KILL_ALL, KILL_ALL_FAIL)) {
|
||||
if (IN_SET(whom, KILL_MAIN, KILL_MAIN_FAIL, KILL_ALL, KILL_ALL_FAIL)) {
|
||||
r = unit_kill_one(u, main_pid, "main", signo, code, value, ret >= 0 ? ret_error : NULL);
|
||||
RET_GATHER(ret, r);
|
||||
killed = killed || r > 0;
|
||||
@@ -4066,7 +4066,7 @@ int unit_kill(
|
||||
/* Note: if we shall enqueue rather than kill we won't do this via the cgroup mechanism, since it
|
||||
* doesn't really make much sense (and given that enqueued values are a relatively expensive
|
||||
* resource, and we shouldn't allow us to be subjects for such allocation sprees) */
|
||||
if (IN_SET(who, KILL_ALL, KILL_ALL_FAIL) && code == SI_USER) {
|
||||
if (IN_SET(whom, KILL_ALL, KILL_ALL_FAIL) && code == SI_USER) {
|
||||
CGroupRuntime *crt = unit_get_cgroup_runtime(u);
|
||||
|
||||
if (crt && crt->cgroup_path) {
|
||||
@@ -4098,7 +4098,7 @@ int unit_kill(
|
||||
}
|
||||
|
||||
/* If the "fail" versions of the operation are requested, then complain if the set of processes we killed is empty */
|
||||
if (ret >= 0 && !killed && IN_SET(who, KILL_ALL_FAIL, KILL_CONTROL_FAIL, KILL_MAIN_FAIL))
|
||||
if (ret >= 0 && !killed && IN_SET(whom, KILL_ALL_FAIL, KILL_CONTROL_FAIL, KILL_MAIN_FAIL))
|
||||
return sd_bus_error_set_const(ret_error, BUS_ERROR_NO_SUCH_PROCESS, "No matching processes to kill");
|
||||
|
||||
return ret;
|
||||
|
||||
+1
-1
@@ -862,7 +862,7 @@ int unit_start(Unit *u, ActivationDetails *details);
|
||||
int unit_stop(Unit *u);
|
||||
int unit_reload(Unit *u);
|
||||
|
||||
int unit_kill(Unit *u, KillWho w, int signo, int code, int value, sd_bus_error *ret_error);
|
||||
int unit_kill(Unit *u, KillWhom w, int signo, int code, int value, sd_bus_error *ret_error);
|
||||
|
||||
void unit_notify_cgroup_oom(Unit *u, bool managed_oom);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user