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
9 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_kill_mode, kill_mode, KillMode);
10
property_get_restart_kill_signal(sd_bus * bus,const char * path,const char * interface,const char * property,sd_bus_message * reply,void * userdata,sd_bus_error * error)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 = userdata;
20 int s;
21
22 assert(c);
23
24 s = restart_kill_signal(c);
25 return sd_bus_message_append_basic(reply, 'i', &s);
26 }
27
28 const sd_bus_vtable bus_kill_vtable[] = {
29 SD_BUS_VTABLE_START(0),
30 SD_BUS_PROPERTY("KillMode", "s", property_get_kill_mode, offsetof(KillContext, kill_mode), SD_BUS_VTABLE_PROPERTY_CONST),
31 SD_BUS_PROPERTY("KillSignal", "i", bus_property_get_int, offsetof(KillContext, kill_signal), SD_BUS_VTABLE_PROPERTY_CONST),
32 SD_BUS_PROPERTY("RestartKillSignal", "i", property_get_restart_kill_signal, 0, SD_BUS_VTABLE_PROPERTY_CONST),
33 SD_BUS_PROPERTY("FinalKillSignal", "i", bus_property_get_int, offsetof(KillContext, final_kill_signal), SD_BUS_VTABLE_PROPERTY_CONST),
34 SD_BUS_PROPERTY("SendSIGKILL", "b", bus_property_get_bool, offsetof(KillContext, send_sigkill), SD_BUS_VTABLE_PROPERTY_CONST),
35 SD_BUS_PROPERTY("SendSIGHUP", "b", bus_property_get_bool, offsetof(KillContext, send_sighup), SD_BUS_VTABLE_PROPERTY_CONST),
36 SD_BUS_PROPERTY("WatchdogSignal", "i", bus_property_get_int, offsetof(KillContext, watchdog_signal), SD_BUS_VTABLE_PROPERTY_CONST),
37 SD_BUS_VTABLE_END
38 };
39
40 static BUS_DEFINE_SET_TRANSIENT_PARSE(kill_mode, KillMode, kill_mode_from_string);
41 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(kill_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check);
42 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(restart_kill_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check);
43 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(final_kill_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check);
44 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(watchdog_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check);
45
bus_kill_context_set_transient_property(Unit * u,KillContext * c,const char * name,sd_bus_message * message,UnitWriteFlags flags,sd_bus_error * error)46 int bus_kill_context_set_transient_property(
47 Unit *u,
48 KillContext *c,
49 const char *name,
50 sd_bus_message *message,
51 UnitWriteFlags flags,
52 sd_bus_error *error) {
53
54 assert(u);
55 assert(c);
56 assert(name);
57 assert(message);
58
59 flags |= UNIT_PRIVATE;
60
61 if (streq(name, "KillMode"))
62 return bus_set_transient_kill_mode(u, name, &c->kill_mode, message, flags, error);
63
64 if (streq(name, "SendSIGHUP"))
65 return bus_set_transient_bool(u, name, &c->send_sighup, message, flags, error);
66
67 if (streq(name, "SendSIGKILL"))
68 return bus_set_transient_bool(u, name, &c->send_sigkill, message, flags, error);
69
70 if (streq(name, "KillSignal"))
71 return bus_set_transient_kill_signal(u, name, &c->kill_signal, message, flags, error);
72
73 if (streq(name, "RestartKillSignal"))
74 return bus_set_transient_restart_kill_signal(u, name, &c->restart_kill_signal, message, flags, error);
75
76 if (streq(name, "FinalKillSignal"))
77 return bus_set_transient_final_kill_signal(u, name, &c->final_kill_signal, message, flags, error);
78
79 if (streq(name, "WatchdogSignal"))
80 return bus_set_transient_watchdog_signal(u, name, &c->watchdog_signal, message, flags, error);
81
82 return 0;
83 }
84