| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "bus-get-properties.h" |
| 4 |
#include "dbus-kill.h" |
| 5 |
#include "dbus-util.h" |
| 6 |
#include "kill.h" |
| 7 |
#include "signal-util.h" |
| 8 |
#include "string-util.h" |
| 9 |
|
| 10 |
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_kill_mode, kill_mode, KillMode); |
| 11 |
|
| 12 |
static int property_get_restart_kill_signal( |
| 13 |
sd_bus *bus, |
| 14 |
const char *path, |
| 15 |
const char *interface, |
| 16 |
const char *property, |
| 17 |
sd_bus_message *reply, |
| 18 |
void *userdata, |
| 19 |
sd_bus_error *reterr_error) { |
| 20 |
KillContext *c = ASSERT_PTR(userdata); |
| 21 |
int s; |
| 22 |
|
| 23 |
s = restart_kill_signal(c); |
| 24 |
return sd_bus_message_append_basic(reply, 'i', &s); |
| 25 |
} |
| 26 |
|
| 27 |
const sd_bus_vtable bus_kill_vtable[] = { |
| 28 |
SD_BUS_VTABLE_START(0), |
| 29 |
SD_BUS_PROPERTY("KillMode", "s", property_get_kill_mode, offsetof(KillContext, kill_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
| 30 |
SD_BUS_PROPERTY("KillSignal", "i", bus_property_get_int, offsetof(KillContext, kill_signal), SD_BUS_VTABLE_PROPERTY_CONST), |
| 31 |
SD_BUS_PROPERTY("RestartKillSignal", "i", property_get_restart_kill_signal, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
| 32 |
SD_BUS_PROPERTY("FinalKillSignal", "i", bus_property_get_int, offsetof(KillContext, final_kill_signal), SD_BUS_VTABLE_PROPERTY_CONST), |
| 33 |
SD_BUS_PROPERTY("SendSIGKILL", "b", bus_property_get_bool, offsetof(KillContext, send_sigkill), SD_BUS_VTABLE_PROPERTY_CONST), |
| 34 |
SD_BUS_PROPERTY("SendSIGHUP", "b", bus_property_get_bool, offsetof(KillContext, send_sighup), SD_BUS_VTABLE_PROPERTY_CONST), |
| 35 |
SD_BUS_PROPERTY("WatchdogSignal", "i", bus_property_get_int, offsetof(KillContext, watchdog_signal), SD_BUS_VTABLE_PROPERTY_CONST), |
| 36 |
SD_BUS_VTABLE_END |
| 37 |
}; |
| 38 |
|
| 39 |
static BUS_DEFINE_SET_TRANSIENT_PARSE(kill_mode, KillMode, kill_mode_from_string); |
| 40 |
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(kill_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check); |
| 41 |
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(restart_kill_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check); |
| 42 |
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(final_kill_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check); |
| 43 |
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(watchdog_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check); |
| 44 |
|
| 45 |
int bus_kill_context_set_transient_property( |
| 46 |
Unit *u, |
| 47 |
KillContext *c, |
| 48 |
const char *name, |
| 49 |
sd_bus_message *message, |
| 50 |
UnitWriteFlags flags, |
| 51 |
sd_bus_error *reterr_error) { |
| 52 |
|
| 53 |
assert(u); |
| 54 |
assert(c); |
| 55 |
assert(name); |
| 56 |
assert(message); |
| 57 |
|
| 58 |
flags |= UNIT_PRIVATE; |
| 59 |
|
| 60 |
if (streq(name, "KillMode")) |
| 61 |
return bus_set_transient_kill_mode(u, name, &c->kill_mode, message, flags, reterr_error); |
| 62 |
|
| 63 |
if (streq(name, "SendSIGHUP")) |
| 64 |
return bus_set_transient_bool(u, name, &c->send_sighup, message, flags, reterr_error); |
| 65 |
|
| 66 |
if (streq(name, "SendSIGKILL")) |
| 67 |
return bus_set_transient_bool(u, name, &c->send_sigkill, message, flags, reterr_error); |
| 68 |
|
| 69 |
if (streq(name, "KillSignal")) |
| 70 |
return bus_set_transient_kill_signal(u, name, &c->kill_signal, message, flags, reterr_error); |
| 71 |
|
| 72 |
if (streq(name, "RestartKillSignal")) |
| 73 |
return bus_set_transient_restart_kill_signal(u, name, &c->restart_kill_signal, message, flags, reterr_error); |
| 74 |
|
| 75 |
if (streq(name, "FinalKillSignal")) |
| 76 |
return bus_set_transient_final_kill_signal(u, name, &c->final_kill_signal, message, flags, reterr_error); |
| 77 |
|
| 78 |
if (streq(name, "WatchdogSignal")) |
| 79 |
return bus_set_transient_watchdog_signal(u, name, &c->watchdog_signal, message, flags, reterr_error); |
| 80 |
|
| 81 |
return 0; |
| 82 |
} |