mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
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:
parent
07748c53df
commit
cd2fb04960
@ -113,7 +113,7 @@ node /org/freedesktop/login1 {
|
|||||||
LockSessions();
|
LockSessions();
|
||||||
UnlockSessions();
|
UnlockSessions();
|
||||||
KillSession(in s session_id,
|
KillSession(in s session_id,
|
||||||
in s who,
|
in s whom,
|
||||||
in i signal_number);
|
in i signal_number);
|
||||||
KillUser(in u uid,
|
KillUser(in u uid,
|
||||||
in i signal_number);
|
in i signal_number);
|
||||||
@ -1140,7 +1140,7 @@ node /org/freedesktop/login1/session/1 {
|
|||||||
Unlock();
|
Unlock();
|
||||||
SetIdleHint(in b idle);
|
SetIdleHint(in b idle);
|
||||||
SetLockedHint(in b locked);
|
SetLockedHint(in b locked);
|
||||||
Kill(in s who,
|
Kill(in s whom,
|
||||||
in i signal_number);
|
in i signal_number);
|
||||||
TakeControl(in b force);
|
TakeControl(in b force);
|
||||||
ReleaseControl();
|
ReleaseControl();
|
||||||
|
@ -465,7 +465,7 @@ node /org/freedesktop/machine1/machine/rawhide {
|
|||||||
interface org.freedesktop.machine1.Machine {
|
interface org.freedesktop.machine1.Machine {
|
||||||
methods:
|
methods:
|
||||||
Terminate();
|
Terminate();
|
||||||
Kill(in s who,
|
Kill(in s whom,
|
||||||
in i signal);
|
in i signal);
|
||||||
GetAddresses(out a(iay) addresses);
|
GetAddresses(out a(iay) addresses);
|
||||||
GetSSHInfo(out s ssh_address,
|
GetSSHInfo(out s ssh_address,
|
||||||
|
@ -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) {
|
int bus_unit_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||||
Unit *u = ASSERT_PTR(userdata);
|
Unit *u = ASSERT_PTR(userdata);
|
||||||
int32_t value = 0;
|
int32_t value = 0;
|
||||||
const char *swho;
|
const char *swhom;
|
||||||
int32_t signo;
|
int32_t signo;
|
||||||
KillWho who;
|
KillWhom whom;
|
||||||
int r, code;
|
int r, code;
|
||||||
|
|
||||||
assert(message);
|
assert(message);
|
||||||
@ -515,7 +515,7 @@ int bus_unit_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = sd_bus_message_read(message, "si", &swho, &signo);
|
r = sd_bus_message_read(message, "si", &swhom, &signo);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
@ -528,12 +528,12 @@ int bus_unit_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *
|
|||||||
} else
|
} else
|
||||||
code = SI_USER;
|
code = SI_USER;
|
||||||
|
|
||||||
if (isempty(swho))
|
if (isempty(swhom))
|
||||||
who = KILL_ALL;
|
whom = KILL_ALL;
|
||||||
else {
|
else {
|
||||||
who = kill_who_from_string(swho);
|
whom = kill_whom_from_string(swhom);
|
||||||
if (who < 0)
|
if (whom < 0)
|
||||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid who argument: %s", swho);
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid whom argument: %s", swhom);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SIGNAL_VALID(signo))
|
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)
|
if (r == 0)
|
||||||
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
|
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)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ static const char* const kill_mode_table[_KILL_MODE_MAX] = {
|
|||||||
|
|
||||||
DEFINE_STRING_TABLE_LOOKUP(kill_mode, KillMode);
|
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_MAIN] = "main",
|
||||||
[KILL_CONTROL] = "control",
|
[KILL_CONTROL] = "control",
|
||||||
[KILL_ALL] = "all",
|
[KILL_ALL] = "all",
|
||||||
@ -53,4 +53,4 @@ static const char* const kill_who_table[_KILL_WHO_MAX] = {
|
|||||||
[KILL_ALL_FAIL] = "all-fail",
|
[KILL_ALL_FAIL] = "all-fail",
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_STRING_TABLE_LOOKUP(kill_who, KillWho);
|
DEFINE_STRING_TABLE_LOOKUP(kill_whom, KillWhom);
|
||||||
|
@ -28,17 +28,17 @@ struct KillContext {
|
|||||||
bool send_sighup;
|
bool send_sighup;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum KillWho {
|
typedef enum KillWhom {
|
||||||
/* Kill who is a property of an operation */
|
/* Kill whom is a property of an operation */
|
||||||
KILL_MAIN,
|
KILL_MAIN,
|
||||||
KILL_CONTROL,
|
KILL_CONTROL,
|
||||||
KILL_ALL,
|
KILL_ALL,
|
||||||
KILL_MAIN_FAIL,
|
KILL_MAIN_FAIL,
|
||||||
KILL_CONTROL_FAIL,
|
KILL_CONTROL_FAIL,
|
||||||
KILL_ALL_FAIL,
|
KILL_ALL_FAIL,
|
||||||
_KILL_WHO_MAX,
|
_KILL_WHOM_MAX,
|
||||||
_KILL_WHO_INVALID = -EINVAL,
|
_KILL_WHOM_INVALID = -EINVAL,
|
||||||
} KillWho;
|
} KillWhom;
|
||||||
|
|
||||||
void kill_context_init(KillContext *c);
|
void kill_context_init(KillContext *c);
|
||||||
void kill_context_dump(KillContext *c, FILE *f, const char *prefix);
|
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_;
|
const char *kill_mode_to_string(KillMode k) _const_;
|
||||||
KillMode kill_mode_from_string(const char *s) _pure_;
|
KillMode kill_mode_from_string(const char *s) _pure_;
|
||||||
|
|
||||||
const char *kill_who_to_string(KillWho k) _const_;
|
const char *kill_whom_to_string(KillWhom k) _const_;
|
||||||
KillWho kill_who_from_string(const char *s) _pure_;
|
KillWhom kill_whom_from_string(const char *s) _pure_;
|
||||||
|
|
||||||
static inline int restart_kill_signal(const KillContext *c) {
|
static inline int restart_kill_signal(const KillContext *c) {
|
||||||
if (c->restart_kill_signal != 0)
|
if (c->restart_kill_signal != 0)
|
||||||
|
@ -4011,7 +4011,7 @@ static int unit_kill_one(
|
|||||||
|
|
||||||
int unit_kill(
|
int unit_kill(
|
||||||
Unit *u,
|
Unit *u,
|
||||||
KillWho who,
|
KillWhom whom,
|
||||||
int signo,
|
int signo,
|
||||||
int code,
|
int code,
|
||||||
int value,
|
int value,
|
||||||
@ -4026,8 +4026,8 @@ int unit_kill(
|
|||||||
* stop a service ourselves. */
|
* stop a service ourselves. */
|
||||||
|
|
||||||
assert(u);
|
assert(u);
|
||||||
assert(who >= 0);
|
assert(whom >= 0);
|
||||||
assert(who < _KILL_WHO_MAX);
|
assert(whom < _KILL_WHOM_MAX);
|
||||||
assert(SIGNAL_VALID(signo));
|
assert(SIGNAL_VALID(signo));
|
||||||
assert(IN_SET(code, SI_USER, SI_QUEUE));
|
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)
|
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.");
|
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)
|
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));
|
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))
|
if (!pidref_is_set(main_pid))
|
||||||
return sd_bus_error_set_const(ret_error, BUS_ERROR_NO_SUCH_PROCESS, "No main process to kill");
|
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)
|
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));
|
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))
|
if (!pidref_is_set(control_pid))
|
||||||
return sd_bus_error_set_const(ret_error, BUS_ERROR_NO_SUCH_PROCESS, "No control process to kill");
|
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);
|
r = unit_kill_one(u, control_pid, "control", signo, code, value, ret_error);
|
||||||
RET_GATHER(ret, r);
|
RET_GATHER(ret, r);
|
||||||
killed = killed || r > 0;
|
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);
|
r = unit_kill_one(u, main_pid, "main", signo, code, value, ret >= 0 ? ret_error : NULL);
|
||||||
RET_GATHER(ret, r);
|
RET_GATHER(ret, r);
|
||||||
killed = killed || r > 0;
|
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
|
/* 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
|
* 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) */
|
* 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);
|
CGroupRuntime *crt = unit_get_cgroup_runtime(u);
|
||||||
|
|
||||||
if (crt && crt->cgroup_path) {
|
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 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 sd_bus_error_set_const(ret_error, BUS_ERROR_NO_SUCH_PROCESS, "No matching processes to kill");
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -862,7 +862,7 @@ int unit_start(Unit *u, ActivationDetails *details);
|
|||||||
int unit_stop(Unit *u);
|
int unit_stop(Unit *u);
|
||||||
int unit_reload(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);
|
void unit_notify_cgroup_oom(Unit *u, bool managed_oom);
|
||||||
|
|
||||||
|
@ -3807,7 +3807,7 @@ static const sd_bus_vtable manager_vtable[] = {
|
|||||||
method_lock_sessions,
|
method_lock_sessions,
|
||||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
SD_BUS_METHOD_WITH_ARGS("KillSession",
|
SD_BUS_METHOD_WITH_ARGS("KillSession",
|
||||||
SD_BUS_ARGS("s", session_id, "s", who, "i", signal_number),
|
SD_BUS_ARGS("s", session_id, "s", whom, "i", signal_number),
|
||||||
SD_BUS_NO_RESULT,
|
SD_BUS_NO_RESULT,
|
||||||
method_kill_session,
|
method_kill_session,
|
||||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
@ -4473,7 +4473,7 @@ int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *ret
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error) {
|
int manager_kill_unit(Manager *manager, const char *unit, KillWhom whom, int signo, sd_bus_error *error) {
|
||||||
assert(manager);
|
assert(manager);
|
||||||
assert(unit);
|
assert(unit);
|
||||||
assert(SIGNAL_VALID(signo));
|
assert(SIGNAL_VALID(signo));
|
||||||
@ -4486,7 +4486,7 @@ int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo
|
|||||||
NULL,
|
NULL,
|
||||||
"ssi",
|
"ssi",
|
||||||
unit,
|
unit,
|
||||||
who == KILL_LEADER ? "main" : "all",
|
whom == KILL_LEADER ? "main" : "all",
|
||||||
signo);
|
signo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ int manager_start_scope(
|
|||||||
int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **ret_job);
|
int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **ret_job);
|
||||||
int manager_stop_unit(Manager *manager, const char *unit, const char *job_mode, sd_bus_error *error, char **ret_job);
|
int manager_stop_unit(Manager *manager, const char *unit, const char *job_mode, sd_bus_error *error, char **ret_job);
|
||||||
int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);
|
int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);
|
||||||
int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error);
|
int manager_kill_unit(Manager *manager, const char *unit, KillWhom whom, int signo, sd_bus_error *error);
|
||||||
int manager_unit_is_active(Manager *manager, const char *unit, sd_bus_error *error);
|
int manager_unit_is_active(Manager *manager, const char *unit, sd_bus_error *error);
|
||||||
int manager_job_is_active(Manager *manager, const char *path, sd_bus_error *error);
|
int manager_job_is_active(Manager *manager, const char *path, sd_bus_error *error);
|
||||||
|
|
||||||
|
@ -291,23 +291,23 @@ static int method_set_locked_hint(sd_bus_message *message, void *userdata, sd_bu
|
|||||||
|
|
||||||
int bus_session_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
int bus_session_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||||
Session *s = ASSERT_PTR(userdata);
|
Session *s = ASSERT_PTR(userdata);
|
||||||
const char *swho;
|
const char *swhom;
|
||||||
int32_t signo;
|
int32_t signo;
|
||||||
KillWho who;
|
KillWhom whom;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(message);
|
assert(message);
|
||||||
|
|
||||||
r = sd_bus_message_read(message, "si", &swho, &signo);
|
r = sd_bus_message_read(message, "si", &swhom, &signo);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (isempty(swho))
|
if (isempty(swhom))
|
||||||
who = KILL_ALL;
|
whom = KILL_ALL;
|
||||||
else {
|
else {
|
||||||
who = kill_who_from_string(swho);
|
whom = kill_whom_from_string(swhom);
|
||||||
if (who < 0)
|
if (whom < 0)
|
||||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swhom);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SIGNAL_VALID(signo))
|
if (!SIGNAL_VALID(signo))
|
||||||
@ -326,7 +326,7 @@ int bus_session_method_kill(sd_bus_message *message, void *userdata, sd_bus_erro
|
|||||||
if (r == 0)
|
if (r == 0)
|
||||||
return 1; /* Will call us back */
|
return 1; /* Will call us back */
|
||||||
|
|
||||||
r = session_kill(s, who, signo);
|
r = session_kill(s, whom, signo);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
@ -1016,7 +1016,7 @@ static const sd_bus_vtable session_vtable[] = {
|
|||||||
method_set_locked_hint,
|
method_set_locked_hint,
|
||||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
SD_BUS_METHOD_WITH_ARGS("Kill",
|
SD_BUS_METHOD_WITH_ARGS("Kill",
|
||||||
SD_BUS_ARGS("s", who, "i", signal_number),
|
SD_BUS_ARGS("s", whom, "i", signal_number),
|
||||||
SD_BUS_NO_RESULT,
|
SD_BUS_NO_RESULT,
|
||||||
bus_session_method_kill,
|
bus_session_method_kill,
|
||||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
|
@ -1384,13 +1384,13 @@ SessionState session_get_state(Session *s) {
|
|||||||
return SESSION_ONLINE;
|
return SESSION_ONLINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int session_kill(Session *s, KillWho who, int signo) {
|
int session_kill(Session *s, KillWhom whom, int signo) {
|
||||||
assert(s);
|
assert(s);
|
||||||
|
|
||||||
if (!s->scope)
|
if (!s->scope)
|
||||||
return -ESRCH;
|
return -ESRCH;
|
||||||
|
|
||||||
return manager_kill_unit(s->manager, s->scope, who, signo, NULL);
|
return manager_kill_unit(s->manager, s->scope, whom, signo, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int session_open_vt(Session *s, bool reopen) {
|
static int session_open_vt(Session *s, bool reopen) {
|
||||||
@ -1665,12 +1665,12 @@ static const char* const session_class_table[_SESSION_CLASS_MAX] = {
|
|||||||
|
|
||||||
DEFINE_STRING_TABLE_LOOKUP(session_class, SessionClass);
|
DEFINE_STRING_TABLE_LOOKUP(session_class, SessionClass);
|
||||||
|
|
||||||
static const char* const kill_who_table[_KILL_WHO_MAX] = {
|
static const char* const kill_whom_table[_KILL_WHOM_MAX] = {
|
||||||
[KILL_LEADER] = "leader",
|
[KILL_LEADER] = "leader",
|
||||||
[KILL_ALL] = "all",
|
[KILL_ALL] = "all",
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_STRING_TABLE_LOOKUP(kill_who, KillWho);
|
DEFINE_STRING_TABLE_LOOKUP(kill_whom, KillWhom);
|
||||||
|
|
||||||
static const char* const tty_validity_table[_TTY_VALIDITY_MAX] = {
|
static const char* const tty_validity_table[_TTY_VALIDITY_MAX] = {
|
||||||
[TTY_FROM_PAM] = "from-pam",
|
[TTY_FROM_PAM] = "from-pam",
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
typedef struct Session Session;
|
typedef struct Session Session;
|
||||||
typedef enum KillWho KillWho;
|
typedef enum KillWhom KillWhom;
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "login-util.h"
|
#include "login-util.h"
|
||||||
@ -77,11 +77,11 @@ typedef enum SessionType {
|
|||||||
|
|
||||||
#define SESSION_TYPE_IS_GRAPHICAL(type) IN_SET(type, SESSION_X11, SESSION_WAYLAND, SESSION_MIR)
|
#define SESSION_TYPE_IS_GRAPHICAL(type) IN_SET(type, SESSION_X11, SESSION_WAYLAND, SESSION_MIR)
|
||||||
|
|
||||||
enum KillWho {
|
enum KillWhom {
|
||||||
KILL_LEADER,
|
KILL_LEADER,
|
||||||
KILL_ALL,
|
KILL_ALL,
|
||||||
_KILL_WHO_MAX,
|
_KILL_WHOM_MAX,
|
||||||
_KILL_WHO_INVALID = -EINVAL,
|
_KILL_WHOM_INVALID = -EINVAL,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum TTYValidity {
|
typedef enum TTYValidity {
|
||||||
@ -191,7 +191,7 @@ int session_finalize(Session *s);
|
|||||||
int session_release(Session *s);
|
int session_release(Session *s);
|
||||||
int session_save(Session *s);
|
int session_save(Session *s);
|
||||||
int session_load(Session *s);
|
int session_load(Session *s);
|
||||||
int session_kill(Session *s, KillWho who, int signo);
|
int session_kill(Session *s, KillWhom whom, int signo);
|
||||||
|
|
||||||
SessionState session_get_state(Session *u);
|
SessionState session_get_state(Session *u);
|
||||||
|
|
||||||
@ -204,8 +204,8 @@ SessionType session_type_from_string(const char *s) _pure_;
|
|||||||
const char* session_class_to_string(SessionClass t) _const_;
|
const char* session_class_to_string(SessionClass t) _const_;
|
||||||
SessionClass session_class_from_string(const char *s) _pure_;
|
SessionClass session_class_from_string(const char *s) _pure_;
|
||||||
|
|
||||||
const char *kill_who_to_string(KillWho k) _const_;
|
const char *kill_whom_to_string(KillWhom k) _const_;
|
||||||
KillWho kill_who_from_string(const char *s) _pure_;
|
KillWhom kill_whom_from_string(const char *s) _pure_;
|
||||||
|
|
||||||
const char* tty_validity_to_string(TTYValidity t) _const_;
|
const char* tty_validity_to_string(TTYValidity t) _const_;
|
||||||
TTYValidity tty_validity_from_string(const char *s) _pure_;
|
TTYValidity tty_validity_from_string(const char *s) _pure_;
|
||||||
|
@ -25,7 +25,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
test_table(handle_action, HANDLE_ACTION);
|
test_table(handle_action, HANDLE_ACTION);
|
||||||
test_table(inhibit_mode, INHIBIT_MODE);
|
test_table(inhibit_mode, INHIBIT_MODE);
|
||||||
test_table(kill_who, KILL_WHO);
|
test_table(kill_whom, KILL_WHOM);
|
||||||
test_table(session_class, SESSION_CLASS);
|
test_table(session_class, SESSION_CLASS);
|
||||||
test_table(session_state, SESSION_STATE);
|
test_table(session_state, SESSION_STATE);
|
||||||
test_table(session_type, SESSION_TYPE);
|
test_table(session_type, SESSION_TYPE);
|
||||||
|
@ -123,7 +123,7 @@ int bus_machine_method_kill(sd_bus_message *message, void *userdata, sd_bus_erro
|
|||||||
Machine *m = ASSERT_PTR(userdata);
|
Machine *m = ASSERT_PTR(userdata);
|
||||||
const char *swho;
|
const char *swho;
|
||||||
int32_t signo;
|
int32_t signo;
|
||||||
KillWho who;
|
KillWhom whom;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(message);
|
assert(message);
|
||||||
@ -133,10 +133,10 @@ int bus_machine_method_kill(sd_bus_message *message, void *userdata, sd_bus_erro
|
|||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (isempty(swho))
|
if (isempty(swho))
|
||||||
who = KILL_ALL;
|
whom = KILL_ALL;
|
||||||
else {
|
else {
|
||||||
who = kill_who_from_string(swho);
|
whom = kill_whom_from_string(swho);
|
||||||
if (who < 0)
|
if (whom < 0)
|
||||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ int bus_machine_method_kill(sd_bus_message *message, void *userdata, sd_bus_erro
|
|||||||
if (r == 0)
|
if (r == 0)
|
||||||
return 1; /* Will call us back */
|
return 1; /* Will call us back */
|
||||||
|
|
||||||
r = machine_kill(m, who, signo);
|
r = machine_kill(m, whom, signo);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
@ -1293,7 +1293,7 @@ static const sd_bus_vtable machine_vtable[] = {
|
|||||||
bus_machine_method_terminate,
|
bus_machine_method_terminate,
|
||||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
SD_BUS_METHOD_WITH_ARGS("Kill",
|
SD_BUS_METHOD_WITH_ARGS("Kill",
|
||||||
SD_BUS_ARGS("s", who, "i", signal),
|
SD_BUS_ARGS("s", whom, "i", signal),
|
||||||
SD_BUS_NO_RESULT,
|
SD_BUS_NO_RESULT,
|
||||||
bus_machine_method_kill,
|
bus_machine_method_kill,
|
||||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
|
@ -609,7 +609,7 @@ MachineState machine_get_state(Machine *s) {
|
|||||||
return MACHINE_RUNNING;
|
return MACHINE_RUNNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_kill(Machine *m, KillWho who, int signo) {
|
int machine_kill(Machine *m, KillWhom whom, int signo) {
|
||||||
assert(m);
|
assert(m);
|
||||||
|
|
||||||
if (!IN_SET(m->class, MACHINE_VM, MACHINE_CONTAINER))
|
if (!IN_SET(m->class, MACHINE_VM, MACHINE_CONTAINER))
|
||||||
@ -618,7 +618,7 @@ int machine_kill(Machine *m, KillWho who, int signo) {
|
|||||||
if (!m->unit)
|
if (!m->unit)
|
||||||
return -ESRCH;
|
return -ESRCH;
|
||||||
|
|
||||||
if (who == KILL_LEADER) /* If we shall simply kill the leader, do so directly */
|
if (whom == KILL_LEADER) /* If we shall simply kill the leader, do so directly */
|
||||||
return pidref_kill(&m->leader, signo);
|
return pidref_kill(&m->leader, signo);
|
||||||
|
|
||||||
/* Otherwise, make PID 1 do it for us, for the entire cgroup */
|
/* Otherwise, make PID 1 do it for us, for the entire cgroup */
|
||||||
@ -920,9 +920,9 @@ static const char* const machine_state_table[_MACHINE_STATE_MAX] = {
|
|||||||
|
|
||||||
DEFINE_STRING_TABLE_LOOKUP(machine_state, MachineState);
|
DEFINE_STRING_TABLE_LOOKUP(machine_state, MachineState);
|
||||||
|
|
||||||
static const char* const kill_who_table[_KILL_WHO_MAX] = {
|
static const char* const kill_whom_table[_KILL_WHOM_MAX] = {
|
||||||
[KILL_LEADER] = "leader",
|
[KILL_LEADER] = "leader",
|
||||||
[KILL_ALL] = "all"
|
[KILL_ALL] = "all"
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_STRING_TABLE_LOOKUP(kill_who, KillWho);
|
DEFINE_STRING_TABLE_LOOKUP(kill_whom, KillWhom);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
typedef struct Machine Machine;
|
typedef struct Machine Machine;
|
||||||
typedef enum KillWho KillWho;
|
typedef enum KillWhom KillWhom;
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "machined.h"
|
#include "machined.h"
|
||||||
@ -26,11 +26,11 @@ typedef enum MachineClass {
|
|||||||
_MACHINE_CLASS_INVALID = -EINVAL,
|
_MACHINE_CLASS_INVALID = -EINVAL,
|
||||||
} MachineClass;
|
} MachineClass;
|
||||||
|
|
||||||
enum KillWho {
|
enum KillWhom {
|
||||||
KILL_LEADER,
|
KILL_LEADER,
|
||||||
KILL_ALL,
|
KILL_ALL,
|
||||||
_KILL_WHO_MAX,
|
_KILL_WHOM_MAX,
|
||||||
_KILL_WHO_INVALID = -EINVAL,
|
_KILL_WHOM_INVALID = -EINVAL,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Machine {
|
struct Machine {
|
||||||
@ -81,7 +81,7 @@ int machine_stop(Machine *m);
|
|||||||
int machine_finalize(Machine *m);
|
int machine_finalize(Machine *m);
|
||||||
int machine_save(Machine *m);
|
int machine_save(Machine *m);
|
||||||
int machine_load(Machine *m);
|
int machine_load(Machine *m);
|
||||||
int machine_kill(Machine *m, KillWho who, int signo);
|
int machine_kill(Machine *m, KillWhom whom, int signo);
|
||||||
|
|
||||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Machine*, machine_free);
|
DEFINE_TRIVIAL_CLEANUP_FUNC(Machine*, machine_free);
|
||||||
|
|
||||||
@ -95,8 +95,8 @@ MachineClass machine_class_from_string(const char *s) _pure_;
|
|||||||
const char* machine_state_to_string(MachineState t) _const_;
|
const char* machine_state_to_string(MachineState t) _const_;
|
||||||
MachineState machine_state_from_string(const char *s) _pure_;
|
MachineState machine_state_from_string(const char *s) _pure_;
|
||||||
|
|
||||||
const char *kill_who_to_string(KillWho k) _const_;
|
const char *kill_whom_to_string(KillWhom k) _const_;
|
||||||
KillWho kill_who_from_string(const char *s) _pure_;
|
KillWhom kill_whom_from_string(const char *s) _pure_;
|
||||||
|
|
||||||
int machine_openpt(Machine *m, int flags, char **ret_slave);
|
int machine_openpt(Machine *m, int flags, char **ret_slave);
|
||||||
int machine_open_terminal(Machine *m, const char *path, int mode);
|
int machine_open_terminal(Machine *m, const char *path, int mode);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
test_setup_logging(LOG_DEBUG);
|
test_setup_logging(LOG_DEBUG);
|
||||||
|
|
||||||
test_table(kill_who, KILL_WHO);
|
test_table(kill_whom, KILL_WHOM);
|
||||||
test_table(machine_class, MACHINE_CLASS);
|
test_table(machine_class, MACHINE_CLASS);
|
||||||
test_table(machine_state, MACHINE_STATE);
|
test_table(machine_state, MACHINE_STATE);
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ int main(int argc, char **argv) {
|
|||||||
test_table(job_state, JOB_STATE);
|
test_table(job_state, JOB_STATE);
|
||||||
test_table(job_type, JOB_TYPE);
|
test_table(job_type, JOB_TYPE);
|
||||||
test_table(kill_mode, KILL_MODE);
|
test_table(kill_mode, KILL_MODE);
|
||||||
test_table(kill_who, KILL_WHO);
|
test_table(kill_whom, KILL_WHOM);
|
||||||
test_table(locale_variable, VARIABLE_LC);
|
test_table(locale_variable, VARIABLE_LC);
|
||||||
test_table(log_target, LOG_TARGET);
|
test_table(log_target, LOG_TARGET);
|
||||||
test_table(managed_oom_mode, MANAGED_OOM_MODE);
|
test_table(managed_oom_mode, MANAGED_OOM_MODE);
|
||||||
|
Loading…
Reference in New Issue
Block a user