KillUnit(in s name,
in s whom,
in i signal);
+ QueueSignalUnit(in s name,
+ in s whom,
+ in i signal,
+ in i value);
CleanUnit(in s name,
in as mask);
FreezeUnit(in s name);
<variablelist class="dbus-method" generated="True" extra-ref="KillUnit()"/>
+ <variablelist class="dbus-method" generated="True" extra-ref="QueueSignalUnit()"/>
+
<variablelist class="dbus-method" generated="True" extra-ref="CleanUnit()"/>
<variablelist class="dbus-method" generated="True" extra-ref="FreezeUnit()"/>
<varname>ExecStop=</varname> and is spawned in parallel to the main daemon process in order to shut it
down.</para>
+ <para><function>QueueSignalUnit()</function> is similar to <function>KillUnit()</function> but may be
+ used to enqueue a POSIX Realtime Signal (i.e. <constant>SIGRTMIN+…</constant> and
+ <constant>SIGRTMAX-…</constant>) to the selected process(es). Takes the same paramaters as
+ <function>KillUnit()</function> with one additional argument: an integer that is passed in the
+ <varname>sival_int</varname> value accompanying the queued signal. See <citerefentry project="man-pages"><refentrytitle>sigqueue</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
+ details.</para>
+
<para><function>GetJob()</function> returns the job object path for a specific job, identified by its
id.</para>
<para>Read access is generally granted to all clients. Additionally, for unprivileged clients, some
operations are allowed through the polkit privilege system. Operations which modify unit state
(<function>StartUnit()</function>, <function>StopUnit()</function>, <function>KillUnit()</function>,
- <function>RestartUnit()</function> and similar, <function>SetProperty()</function>) require
+ <function>QueueSignalUnit()</function>, <function>RestartUnit()</function> and similar,
+ <function>SetProperty()</function>) require
<interfacename>org.freedesktop.systemd1.manage-units</interfacename>. Operations which modify unit file
enablement state (<function>EnableUnitFiles()</function>, <function>DisableUnitFiles()</function>,
<function>EnableUnitFilesWithFlags()</function>, <function>DisableUnitFilesWithFlags()</function>,
out a(uosos) affected_jobs);
Kill(in s whom,
in i signal);
+ QueueSignal(in s whom,
+ in i signal,
+ in i value);
ResetFailed();
SetProperties(in b runtime,
in a(sv) properties);
<variablelist class="dbus-method" generated="True" extra-ref="Kill()"/>
+ <variablelist class="dbus-method" generated="True" extra-ref="QueueSignal()"/>
+
<variablelist class="dbus-method" generated="True" extra-ref="ResetFailed()"/>
<variablelist class="dbus-method" generated="True" extra-ref="SetProperties()"/>
<para><function>Start()</function>, <function>Stop()</function>, <function>Reload()</function>,
<function>Restart()</function>, <function>TryRestart()</function>,
<function>ReloadOrRestart()</function>, <function>ReloadOrTryRestart()</function>,
- <function>Kill()</function>, <function>ResetFailed()</function>, and
- <function>SetProperties()</function> implement the same operation as the respective methods on the
+ <function>Kill()</function>, <function>QueueSignal()</function>, <function>ResetFailed()</function>,
+ and <function>SetProperties()</function> implement the same operation as the respective methods on the
<interfacename>Manager</interfacename> object (see above). However, these methods operate on the unit
- object and hence do not take a unit name parameter. Invoking the methods directly on the Manager
- object has the advantage of not requiring a <function>GetUnit()</function> call to get the unit object
- for a specific unit name. Calling the methods on the Manager object is hence a round trip
+ object and hence do not take a unit name parameter. Invoking the methods directly on the Manager object
+ has the advantage of not requiring a <function>GetUnit()</function> call to get the unit object for a
+ specific unit name. Calling the methods on the Manager object is hence a round trip
optimization.</para>
</refsect2>
SD_BUS_NO_RESULT,
method_kill_unit,
SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_ARGS("QueueSignalUnit",
+ SD_BUS_ARGS("s", name, "s", whom, "i", signal, "i", value),
+ SD_BUS_NO_RESULT,
+ method_kill_unit,
+ SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD_WITH_ARGS("CleanUnit",
SD_BUS_ARGS("s", name, "as", mask),
SD_BUS_NO_RESULT,
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;
int32_t signo;
KillWho who;
- int r;
+ int r, code;
assert(message);
if (r < 0)
return r;
+ if (startswith(sd_bus_message_get_member(message), "QueueSignal")) {
+ r = sd_bus_message_read(message, "i", &value);
+ if (r < 0)
+ return r;
+
+ code = SI_QUEUE;
+ } else
+ code = SI_USER;
+
if (isempty(swho))
who = 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);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid who argument: %s", swho);
}
if (!SIGNAL_VALID(signo))
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Signal number out of range.");
+ if (code == SI_QUEUE && !((signo >= SIGRTMIN) && (signo <= SIGRTMAX)))
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
+ "Value parameter only accepted for realtime signals (SIGRTMIN…SIGRTMAX), refusing for signal SIG%s.", signal_to_string(signo));
+
r = bus_verify_manage_units_async_full(
u,
"kill",
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, error);
+ r = unit_kill(u, who, signo, code, value, error);
if (r < 0)
return r;
SD_BUS_NO_RESULT,
bus_unit_method_kill,
SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_ARGS("QueueSignal",
+ SD_BUS_ARGS("s", whom, "i", signal, "i", value),
+ SD_BUS_NO_RESULT,
+ bus_unit_method_kill,
+ SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("ResetFailed",
NULL,
NULL,
m->clean_result = MOUNT_SUCCESS;
}
-static int mount_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
+static int mount_kill(Unit *u, KillWho who, int signo, int code, int value, sd_bus_error *error) {
Mount *m = MOUNT(u);
assert(m);
- return unit_kill_common(u, who, signo, -1, m->control_pid, error);
+ return unit_kill_common(u, who, signo, code, value, -1, m->control_pid, error);
}
static int mount_control_pid(Unit *u) {
send_interface="org.freedesktop.systemd1.Manager"
send_member="KillUnit"/>
+ <allow send_destination="org.freedesktop.systemd1"
+ send_interface="org.freedesktop.systemd1.Manager"
+ send_member="QueueSignalUnit"/>
+
<allow send_destination="org.freedesktop.systemd1"
send_interface="org.freedesktop.systemd1.Manager"
send_member="ResetFailedUnit"/>
send_interface="org.freedesktop.systemd1.Unit"
send_member="Kill"/>
+ <allow send_destination="org.freedesktop.systemd1"
+ send_interface="org.freedesktop.systemd1.Unit"
+ send_member="QueueSignal"/>
+
<allow send_destination="org.freedesktop.systemd1"
send_interface="org.freedesktop.systemd1.Unit"
send_member="ResetFailed"/>
s->result = SCOPE_SUCCESS;
}
-static int scope_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
- return unit_kill_common(u, who, signo, -1, -1, error);
+static int scope_kill(Unit *u, KillWho who, int signo, int code, int value, sd_bus_error *error) {
+ return unit_kill_common(u, who, signo, code, value, -1, -1, error);
}
static int scope_get_timeout(Unit *u, usec_t *timeout) {
s->flush_n_restarts = false;
}
-static int service_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
+static int service_kill(Unit *u, KillWho who, int signo, int code, int value, sd_bus_error *error) {
Service *s = SERVICE(u);
assert(s);
- return unit_kill_common(u, who, signo, s->main_pid, s->control_pid, error);
+ return unit_kill_common(u, who, signo, code, value, s->main_pid, s->control_pid, error);
}
static int service_main_pid(Unit *u) {
return 1;
}
-static int slice_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
- return unit_kill_common(u, who, signo, -1, -1, error);
+static int slice_kill(Unit *u, KillWho who, int signo, int code, int value, sd_bus_error *error) {
+ return unit_kill_common(u, who, signo, code, value, -1, -1, error);
}
static int slice_serialize(Unit *u, FILE *f, FDSet *fds) {
socket_set_state(s, SOCKET_RUNNING);
}
-static int socket_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
- return unit_kill_common(u, who, signo, -1, SOCKET(u)->control_pid, error);
+static int socket_kill(Unit *u, KillWho who, int signo, int code, int value, sd_bus_error *error) {
+ return unit_kill_common(u, who, signo, code, value, -1, SOCKET(u)->control_pid, error);
}
static int socket_get_timeout(Unit *u, usec_t *timeout) {
s->clean_result = SWAP_SUCCESS;
}
-static int swap_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
- return unit_kill_common(u, who, signo, -1, SWAP(u)->control_pid, error);
+static int swap_kill(Unit *u, KillWho who, int signo, int code, int value, sd_bus_error *error) {
+ return unit_kill_common(u, who, signo, code, value, -1, SWAP(u)->control_pid, error);
}
static int swap_get_timeout(Unit *u, usec_t *timeout) {
return UNIT_VTABLE(u)->will_restart(u);
}
-int unit_kill(Unit *u, KillWho w, int signo, sd_bus_error *error) {
+int unit_kill(Unit *u, KillWho w, int signo, int code, int value, sd_bus_error *error) {
assert(u);
assert(w >= 0 && w < _KILL_WHO_MAX);
assert(SIGNAL_VALID(signo));
+ assert(IN_SET(code, SI_USER, SI_QUEUE));
if (!UNIT_VTABLE(u)->kill)
return -EOPNOTSUPP;
- return UNIT_VTABLE(u)->kill(u, w, signo, error);
+ return UNIT_VTABLE(u)->kill(u, w, signo, code, value, error);
}
void unit_notify_cgroup_oom(Unit *u, bool managed_oom) {
return 1;
}
+static int kill_or_sigqueue(pid_t pid, int signo, int code, int value) {
+ assert(pid > 0);
+ assert(SIGNAL_VALID(signo));
+
+ switch (code) {
+
+ case SI_USER:
+ log_debug("Killing " PID_FMT " with signal SIG%s.", pid, signal_to_string(signo));
+ return RET_NERRNO(kill(pid, signo));
+
+ case SI_QUEUE:
+ log_debug("Enqueuing value %i to " PID_FMT " on signal SIG%s.", value, pid, signal_to_string(signo));
+ return RET_NERRNO(sigqueue(pid, signo, (const union sigval) { .sival_int = value }));
+
+ default:
+ assert_not_reached();
+ }
+}
+
int unit_kill_common(
Unit *u,
KillWho who,
int signo,
+ int code,
+ int value,
pid_t main_pid,
pid_t control_pid,
sd_bus_error *error) {
- int r = 0;
bool killed = false;
+ int ret = 0, r;
/* This is the common implementation for explicit user-requested killing of unit processes, shared by
* various unit types. Do not confuse with unit_kill_context(), which is what we use when we want to
* stop a service ourselves. */
+ assert(u);
+ assert(who >= 0);
+ assert(who < _KILL_WHO_MAX);
+ assert(SIGNAL_VALID(signo));
+ assert(IN_SET(code, SI_USER, SI_QUEUE));
+
if (IN_SET(who, KILL_MAIN, KILL_MAIN_FAIL)) {
if (main_pid < 0)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_PROCESS, "%s units have no main processes", unit_type_to_string(u->type));
return sd_bus_error_set_const(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 (control_pid > 0) {
- _cleanup_free_ char *comm = NULL;
- (void) get_process_comm(control_pid, &comm);
+ if (control_pid > 0 &&
+ IN_SET(who, KILL_CONTROL, KILL_CONTROL_FAIL, KILL_ALL, KILL_ALL_FAIL)) {
+ _cleanup_free_ char *comm = NULL;
+ (void) get_process_comm(control_pid, &comm);
- if (kill(control_pid, signo) < 0) {
- /* Report this failure both to the logs and to the client */
- sd_bus_error_set_errnof(
- error, errno,
- "Failed to send signal SIG%s to control process " PID_FMT " (%s): %m",
- signal_to_string(signo), control_pid, strna(comm));
- r = log_unit_warning_errno(
- u, errno,
- "Failed to send signal SIG%s to control process " PID_FMT " (%s) on client request: %m",
- signal_to_string(signo), control_pid, strna(comm));
- } else {
- log_unit_info(u, "Sent signal SIG%s to control process " PID_FMT " (%s) on client request.",
- signal_to_string(signo), control_pid, strna(comm));
- killed = true;
- }
+ r = kill_or_sigqueue(control_pid, signo, code, value);
+ if (r < 0) {
+ ret = r;
+
+ /* Report this failure both to the logs and to the client */
+ sd_bus_error_set_errnof(
+ error, r,
+ "Failed to send signal SIG%s to control process " PID_FMT " (%s): %m",
+ signal_to_string(signo), control_pid, strna(comm));
+ log_unit_warning_errno(
+ u, r,
+ "Failed to send signal SIG%s to control process " PID_FMT " (%s) on client request: %m",
+ signal_to_string(signo), control_pid, strna(comm));
+ } else {
+ log_unit_info(u, "Sent signal SIG%s to control process " PID_FMT " (%s) on client request.",
+ signal_to_string(signo), control_pid, strna(comm));
+ killed = true;
}
+ }
- if (IN_SET(who, KILL_MAIN, KILL_MAIN_FAIL, KILL_ALL, KILL_ALL_FAIL))
- if (main_pid > 0) {
- _cleanup_free_ char *comm = NULL;
- (void) get_process_comm(main_pid, &comm);
+ if (main_pid > 0 &&
+ IN_SET(who, KILL_MAIN, KILL_MAIN_FAIL, KILL_ALL, KILL_ALL_FAIL)) {
- if (kill(main_pid, signo) < 0) {
- if (r == 0)
- sd_bus_error_set_errnof(
- error, errno,
- "Failed to send signal SIG%s to main process " PID_FMT " (%s): %m",
- signal_to_string(signo), main_pid, strna(comm));
+ _cleanup_free_ char *comm = NULL;
+ (void) get_process_comm(main_pid, &comm);
+
+ r = kill_or_sigqueue(main_pid, signo, code, value);
+ if (r < 0) {
+ if (ret == 0) {
+ ret = r;
- r = log_unit_warning_errno(
- u, errno,
- "Failed to send signal SIG%s to main process " PID_FMT " (%s) on client request: %m",
+ sd_bus_error_set_errnof(
+ error, r,
+ "Failed to send signal SIG%s to main process " PID_FMT " (%s): %m",
signal_to_string(signo), main_pid, strna(comm));
- } else {
- log_unit_info(u, "Sent signal SIG%s to main process " PID_FMT " (%s) on client request.",
- signal_to_string(signo), main_pid, strna(comm));
- killed = true;
}
+
+ log_unit_warning_errno(
+ u, r,
+ "Failed to send signal SIG%s to main process " PID_FMT " (%s) on client request: %m",
+ signal_to_string(signo), main_pid, strna(comm));
+
+ } else {
+ log_unit_info(u, "Sent signal SIG%s to main process " PID_FMT " (%s) on client request.",
+ signal_to_string(signo), main_pid, strna(comm));
+ killed = true;
}
+ }
- if (IN_SET(who, KILL_ALL, KILL_ALL_FAIL) && u->cgroup_path) {
+ /* 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) && u->cgroup_path && code == SI_USER) {
_cleanup_set_free_ Set *pid_set = NULL;
- int q;
/* Exclude the main/control pids from being killed via the cgroup */
pid_set = unit_pid_set(main_pid, control_pid);
if (!pid_set)
return log_oom();
- q = cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path, signo, 0, pid_set, kill_common_log, u);
- if (q < 0) {
- if (!IN_SET(q, -ESRCH, -ENOENT)) {
- if (r == 0)
+ r = cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path, signo, 0, pid_set, kill_common_log, u);
+ if (r < 0) {
+ if (!IN_SET(r, -ESRCH, -ENOENT)) {
+ if (ret == 0) {
+ ret = r;
+
sd_bus_error_set_errnof(
- error, q,
+ error, r,
"Failed to send signal SIG%s to auxiliary processes: %m",
signal_to_string(signo));
+ }
- r = log_unit_warning_errno(
- u, q,
+ log_unit_warning_errno(
+ u, r,
"Failed to send signal SIG%s to auxiliary processes on client request: %m",
signal_to_string(signo));
}
}
/* If the "fail" versions of the operation are requested, then complain if the set of processes we killed is empty */
- if (r == 0 && !killed && IN_SET(who, KILL_ALL_FAIL, KILL_CONTROL_FAIL, KILL_MAIN_FAIL))
+ if (ret == 0 && !killed && IN_SET(who, KILL_ALL_FAIL, KILL_CONTROL_FAIL, KILL_MAIN_FAIL))
return sd_bus_error_set_const(error, BUS_ERROR_NO_SUCH_PROCESS, "No matching processes to kill");
- return r;
+ return ret;
}
int unit_following_set(Unit *u, Set **s) {
int (*stop)(Unit *u);
int (*reload)(Unit *u);
- int (*kill)(Unit *u, KillWho w, int signo, sd_bus_error *error);
+ int (*kill)(Unit *u, KillWho w, int signo, int code, int value, sd_bus_error *error);
/* Clear out the various runtime/state/cache/logs/configuration data */
int (*clean)(Unit *u, ExecCleanMask m);
int unit_stop(Unit *u);
int unit_reload(Unit *u);
-int unit_kill(Unit *u, KillWho w, int signo, sd_bus_error *error);
-int unit_kill_common(Unit *u, KillWho who, int signo, pid_t main_pid, pid_t control_pid, sd_bus_error *error);
+int unit_kill(Unit *u, KillWho w, int signo, int code, int value, sd_bus_error *error);
+int unit_kill_common(Unit *u, KillWho who, int signo, int code, int value, pid_t main_pid, pid_t control_pid, sd_bus_error *error);
void unit_notify_cgroup_oom(Unit *u, bool managed_oom);
n = now(CLOCK_MONOTONIC);
if (ts + timeout < n) {
log_error("Test timeout when testing %s", unit->id);
- r = unit_kill(unit, KILL_ALL, SIGKILL, NULL);
+ r = unit_kill(unit, KILL_ALL, SIGKILL, SI_USER, 0, NULL);
if (r < 0)
log_error_errno(r, "Failed to kill %s: %m", unit->id);
exit(EXIT_FAILURE);