]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/dbus-kill.c
Merge pull request #7388 from keszybz/doc-tweak
[thirdparty/systemd.git] / src / core / dbus-kill.c
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
20 #include "bus-util.h"
21 #include "dbus-kill.h"
22 #include "kill.h"
23 #include "signal-util.h"
24
25 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_kill_mode, kill_mode, KillMode);
26
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),
33 SD_BUS_VTABLE_END
34 };
35
36 int bus_kill_context_set_transient_property(
37 Unit *u,
38 KillContext *c,
39 const char *name,
40 sd_bus_message *message,
41 UnitSetPropertiesMode mode,
42 sd_bus_error *error) {
43
44 int r;
45
46 assert(u);
47 assert(c);
48 assert(name);
49 assert(message);
50
51 if (streq(name, "KillMode")) {
52 const char *m;
53 KillMode k;
54
55 r = sd_bus_message_read(message, "s", &m);
56 if (r < 0)
57 return r;
58
59 k = kill_mode_from_string(m);
60 if (k < 0)
61 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Kill mode '%s' not known.", m);
62
63 if (mode != UNIT_CHECK) {
64 c->kill_mode = k;
65
66 unit_write_drop_in_private_format(u, mode, name, "KillMode=%s", kill_mode_to_string(k));
67 }
68
69 return 1;
70
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 (!SIGNAL_VALID(sig))
79 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Signal %i out of range", sig);
80
81 if (mode != UNIT_CHECK) {
82 c->kill_signal = sig;
83
84 unit_write_drop_in_private_format(u, mode, name, "KillSignal=%s", signal_to_string(sig));
85 }
86
87 return 1;
88
89 } else if (streq(name, "SendSIGHUP")) {
90 int b;
91
92 r = sd_bus_message_read(message, "b", &b);
93 if (r < 0)
94 return r;
95
96 if (mode != UNIT_CHECK) {
97 c->send_sighup = b;
98
99 unit_write_drop_in_private_format(u, mode, name, "SendSIGHUP=%s", yes_no(b));
100 }
101
102 return 1;
103
104 } else if (streq(name, "SendSIGKILL")) {
105 int b;
106
107 r = sd_bus_message_read(message, "b", &b);
108 if (r < 0)
109 return r;
110
111 if (mode != UNIT_CHECK) {
112 c->send_sigkill = b;
113
114 unit_write_drop_in_private_format(u, mode, name, "SendSIGKILL=%s", yes_no(b));
115 }
116
117 return 1;
118
119 }
120
121 return 0;
122 }