2 This file is part of systemd.
4 Copyright 2012 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 #include "dbus-kill.h"
23 #include "signal-util.h"
25 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_kill_mode
, kill_mode
, KillMode
);
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("SendSIGKILL", "b", bus_property_get_bool
, offsetof(KillContext
, send_sigkill
), SD_BUS_VTABLE_PROPERTY_CONST
),
32 SD_BUS_PROPERTY("SendSIGHUP", "b", bus_property_get_bool
, offsetof(KillContext
, send_sighup
), SD_BUS_VTABLE_PROPERTY_CONST
),
36 int bus_kill_context_set_transient_property(
40 sd_bus_message
*message
,
41 UnitSetPropertiesMode mode
,
42 sd_bus_error
*error
) {
51 if (streq(name
, "KillMode")) {
55 r
= sd_bus_message_read(message
, "s", &m
);
59 k
= kill_mode_from_string(m
);
61 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Kill mode '%s' not known.", m
);
63 if (mode
!= UNIT_CHECK
) {
66 unit_write_drop_in_private_format(u
, mode
, name
, "KillMode=%s", kill_mode_to_string(k
));
71 } else if (streq(name
, "KillSignal")) {
74 r
= sd_bus_message_read(message
, "i", &sig
);
78 if (!SIGNAL_VALID(sig
))
79 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Signal %i out of range", sig
);
81 if (mode
!= UNIT_CHECK
) {
84 unit_write_drop_in_private_format(u
, mode
, name
, "KillSignal=%s", signal_to_string(sig
));
89 } else if (streq(name
, "SendSIGHUP")) {
92 r
= sd_bus_message_read(message
, "b", &b
);
96 if (mode
!= UNIT_CHECK
) {
99 unit_write_drop_in_private_format(u
, mode
, name
, "SendSIGHUP=%s", yes_no(b
));
104 } else if (streq(name
, "SendSIGKILL")) {
107 r
= sd_bus_message_read(message
, "b", &b
);
111 if (mode
!= UNIT_CHECK
) {
114 unit_write_drop_in_private_format(u
, mode
, name
, "SendSIGKILL=%s", yes_no(b
));