]>
Commit | Line | Data |
---|---|---|
4819ff03 LP |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2012 Lennart Poettering | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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/>. | |
18 | ***/ | |
19 | ||
24882e06 | 20 | #include "bus-util.h" |
4819ff03 | 21 | #include "dbus-kill.h" |
cf0fbc49 TA |
22 | #include "kill.h" |
23 | #include "signal-util.h" | |
4819ff03 | 24 | |
718db961 | 25 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_kill_mode, kill_mode, KillMode); |
4819ff03 | 26 | |
718db961 LP |
27 | const sd_bus_vtable bus_kill_vtable[] = { |
28 | SD_BUS_VTABLE_START(0), | |
556089dc LP |
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), | |
718db961 | 33 | SD_BUS_VTABLE_END |
4819ff03 | 34 | }; |
a6c0353b LP |
35 | |
36 | int bus_kill_context_set_transient_property( | |
37 | Unit *u, | |
38 | KillContext *c, | |
39 | const char *name, | |
718db961 | 40 | sd_bus_message *message, |
a6c0353b | 41 | UnitSetPropertiesMode mode, |
718db961 LP |
42 | sd_bus_error *error) { |
43 | ||
44 | int r; | |
a6c0353b LP |
45 | |
46 | assert(u); | |
47 | assert(c); | |
48 | assert(name); | |
718db961 | 49 | assert(message); |
a6c0353b | 50 | |
405e0255 LP |
51 | if (streq(name, "KillMode")) { |
52 | const char *m; | |
53 | KillMode k; | |
54 | ||
718db961 LP |
55 | r = sd_bus_message_read(message, "s", &m); |
56 | if (r < 0) | |
57 | return r; | |
405e0255 LP |
58 | |
59 | k = kill_mode_from_string(m); | |
60 | if (k < 0) | |
61 | return -EINVAL; | |
62 | ||
63 | if (mode != UNIT_CHECK) { | |
64 | c->kill_mode = k; | |
65 | ||
66 | unit_write_drop_in_private_format(u, mode, name, "KillMode=%s\n", kill_mode_to_string(k)); | |
67 | } | |
68 | ||
69 | return 1; | |
70 | ||
c7040b5d LP |
71 | } else if (streq(name, "KillSignal")) { |
72 | int sig; | |
73 | ||
74 | r = sd_bus_message_read(message, "i", &sig); | |
75 | if (r < 0) | |
76 | return r; | |
77 | ||
78 | if (sig <= 0 || sig >= _NSIG) | |
b4f052a0 | 79 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Signal %i out of range", sig); |
c7040b5d LP |
80 | |
81 | if (mode != UNIT_CHECK) { | |
82 | c->kill_signal = sig; | |
83 | ||
84 | unit_write_drop_in_private_format(u, mode, name, "KillSignal=%s\n", signal_to_string(sig)); | |
85 | } | |
86 | ||
87 | return 1; | |
88 | ||
405e0255 | 89 | } else if (streq(name, "SendSIGHUP")) { |
718db961 | 90 | int b; |
a6c0353b | 91 | |
718db961 LP |
92 | r = sd_bus_message_read(message, "b", &b); |
93 | if (r < 0) | |
94 | return r; | |
a6c0353b LP |
95 | |
96 | if (mode != UNIT_CHECK) { | |
a6c0353b | 97 | c->send_sighup = b; |
c3df8d3d | 98 | |
405e0255 | 99 | unit_write_drop_in_private_format(u, mode, name, "SendSIGHUP=%s\n", yes_no(b)); |
a6c0353b LP |
100 | } |
101 | ||
102 | return 1; | |
103 | ||
104 | } else if (streq(name, "SendSIGKILL")) { | |
718db961 | 105 | int b; |
a6c0353b | 106 | |
718db961 LP |
107 | r = sd_bus_message_read(message, "b", &b); |
108 | if (r < 0) | |
109 | return r; | |
a6c0353b LP |
110 | |
111 | if (mode != UNIT_CHECK) { | |
a6c0353b | 112 | c->send_sigkill = b; |
c3df8d3d | 113 | |
405e0255 | 114 | unit_write_drop_in_private_format(u, mode, name, "SendSIGKILL=%s\n", yes_no(b)); |
a6c0353b LP |
115 | } |
116 | ||
117 | return 1; | |
118 | ||
119 | } | |
120 | ||
121 | return 0; | |
122 | } |