]>
Commit | Line | Data |
---|---|---|
663996b3 MS |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2012 Lennart Poettering | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
86f210e9 | 22 | #include "bus-util.h" |
663996b3 | 23 | #include "dbus-kill.h" |
db2df898 MP |
24 | #include "kill.h" |
25 | #include "signal-util.h" | |
663996b3 | 26 | |
60f067b4 | 27 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_kill_mode, kill_mode, KillMode); |
663996b3 | 28 | |
60f067b4 JS |
29 | const sd_bus_vtable bus_kill_vtable[] = { |
30 | SD_BUS_VTABLE_START(0), | |
31 | SD_BUS_PROPERTY("KillMode", "s", property_get_kill_mode, offsetof(KillContext, kill_mode), SD_BUS_VTABLE_PROPERTY_CONST), | |
32 | SD_BUS_PROPERTY("KillSignal", "i", bus_property_get_int, offsetof(KillContext, 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_VTABLE_END | |
663996b3 | 36 | }; |
14228c0d MB |
37 | |
38 | int bus_kill_context_set_transient_property( | |
39 | Unit *u, | |
40 | KillContext *c, | |
41 | const char *name, | |
60f067b4 | 42 | sd_bus_message *message, |
14228c0d | 43 | UnitSetPropertiesMode mode, |
60f067b4 JS |
44 | sd_bus_error *error) { |
45 | ||
46 | int r; | |
14228c0d MB |
47 | |
48 | assert(u); | |
49 | assert(c); | |
50 | assert(name); | |
60f067b4 | 51 | assert(message); |
14228c0d MB |
52 | |
53 | if (streq(name, "KillMode")) { | |
54 | const char *m; | |
55 | KillMode k; | |
56 | ||
60f067b4 JS |
57 | r = sd_bus_message_read(message, "s", &m); |
58 | if (r < 0) | |
59 | return r; | |
14228c0d MB |
60 | |
61 | k = kill_mode_from_string(m); | |
62 | if (k < 0) | |
63 | return -EINVAL; | |
64 | ||
65 | if (mode != UNIT_CHECK) { | |
66 | c->kill_mode = k; | |
67 | ||
68 | unit_write_drop_in_private_format(u, mode, name, "KillMode=%s\n", kill_mode_to_string(k)); | |
69 | } | |
70 | ||
71 | return 1; | |
72 | ||
60f067b4 JS |
73 | } else if (streq(name, "KillSignal")) { |
74 | int sig; | |
14228c0d | 75 | |
60f067b4 JS |
76 | r = sd_bus_message_read(message, "i", &sig); |
77 | if (r < 0) | |
78 | return r; | |
79 | ||
80 | if (sig <= 0 || sig >= _NSIG) | |
81 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Signal %i out of range", sig); | |
14228c0d MB |
82 | |
83 | if (mode != UNIT_CHECK) { | |
60f067b4 JS |
84 | c->kill_signal = sig; |
85 | ||
86 | unit_write_drop_in_private_format(u, mode, name, "KillSignal=%s\n", signal_to_string(sig)); | |
87 | } | |
14228c0d | 88 | |
60f067b4 JS |
89 | return 1; |
90 | ||
91 | } else if (streq(name, "SendSIGHUP")) { | |
92 | int b; | |
93 | ||
94 | r = sd_bus_message_read(message, "b", &b); | |
95 | if (r < 0) | |
96 | return r; | |
97 | ||
98 | if (mode != UNIT_CHECK) { | |
14228c0d MB |
99 | c->send_sighup = b; |
100 | ||
101 | unit_write_drop_in_private_format(u, mode, name, "SendSIGHUP=%s\n", yes_no(b)); | |
102 | } | |
103 | ||
104 | return 1; | |
105 | ||
106 | } else if (streq(name, "SendSIGKILL")) { | |
60f067b4 | 107 | int b; |
14228c0d | 108 | |
60f067b4 JS |
109 | r = sd_bus_message_read(message, "b", &b); |
110 | if (r < 0) | |
111 | return r; | |
14228c0d MB |
112 | |
113 | if (mode != UNIT_CHECK) { | |
14228c0d MB |
114 | c->send_sigkill = b; |
115 | ||
116 | unit_write_drop_in_private_format(u, mode, name, "SendSIGKILL=%s\n", yes_no(b)); | |
117 | } | |
118 | ||
119 | return 1; | |
120 | ||
121 | } | |
122 | ||
123 | return 0; | |
124 | } |