udev: String substitutions can be done in ENV, too
[systemd_ALT.git] / src / core / dbus-kill.c
blob19e439f79ee2f8d673002db6702ff9a3321dde35
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
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"
9 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_kill_mode, kill_mode, KillMode);
11 static int property_get_restart_kill_signal(
12 sd_bus *bus,
13 const char *path,
14 const char *interface,
15 const char *property,
16 sd_bus_message *reply,
17 void *userdata,
18 sd_bus_error *error) {
19 KillContext *c = ASSERT_PTR(userdata);
20 int s;
22 s = restart_kill_signal(c);
23 return sd_bus_message_append_basic(reply, 'i', &s);
26 const sd_bus_vtable bus_kill_vtable[] = {
27 SD_BUS_VTABLE_START(0),
28 SD_BUS_PROPERTY("KillMode", "s", property_get_kill_mode, offsetof(KillContext, kill_mode), SD_BUS_VTABLE_PROPERTY_CONST),
29 SD_BUS_PROPERTY("KillSignal", "i", bus_property_get_int, offsetof(KillContext, kill_signal), SD_BUS_VTABLE_PROPERTY_CONST),
30 SD_BUS_PROPERTY("RestartKillSignal", "i", property_get_restart_kill_signal, 0, SD_BUS_VTABLE_PROPERTY_CONST),
31 SD_BUS_PROPERTY("FinalKillSignal", "i", bus_property_get_int, offsetof(KillContext, final_kill_signal), SD_BUS_VTABLE_PROPERTY_CONST),
32 SD_BUS_PROPERTY("SendSIGKILL", "b", bus_property_get_bool, offsetof(KillContext, send_sigkill), SD_BUS_VTABLE_PROPERTY_CONST),
33 SD_BUS_PROPERTY("SendSIGHUP", "b", bus_property_get_bool, offsetof(KillContext, send_sighup), SD_BUS_VTABLE_PROPERTY_CONST),
34 SD_BUS_PROPERTY("WatchdogSignal", "i", bus_property_get_int, offsetof(KillContext, watchdog_signal), SD_BUS_VTABLE_PROPERTY_CONST),
35 SD_BUS_VTABLE_END
38 static BUS_DEFINE_SET_TRANSIENT_PARSE(kill_mode, KillMode, kill_mode_from_string);
39 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(kill_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check);
40 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(restart_kill_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check);
41 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(final_kill_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check);
42 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(watchdog_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check);
44 int bus_kill_context_set_transient_property(
45 Unit *u,
46 KillContext *c,
47 const char *name,
48 sd_bus_message *message,
49 UnitWriteFlags flags,
50 sd_bus_error *error) {
52 assert(u);
53 assert(c);
54 assert(name);
55 assert(message);
57 flags |= UNIT_PRIVATE;
59 if (streq(name, "KillMode"))
60 return bus_set_transient_kill_mode(u, name, &c->kill_mode, message, flags, error);
62 if (streq(name, "SendSIGHUP"))
63 return bus_set_transient_bool(u, name, &c->send_sighup, message, flags, error);
65 if (streq(name, "SendSIGKILL"))
66 return bus_set_transient_bool(u, name, &c->send_sigkill, message, flags, error);
68 if (streq(name, "KillSignal"))
69 return bus_set_transient_kill_signal(u, name, &c->kill_signal, message, flags, error);
71 if (streq(name, "RestartKillSignal"))
72 return bus_set_transient_restart_kill_signal(u, name, &c->restart_kill_signal, message, flags, error);
74 if (streq(name, "FinalKillSignal"))
75 return bus_set_transient_final_kill_signal(u, name, &c->final_kill_signal, message, flags, error);
77 if (streq(name, "WatchdogSignal"))
78 return bus_set_transient_watchdog_signal(u, name, &c->watchdog_signal, message, flags, error);
80 return 0;