]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/dbus-kill.c
catalog: don't say "systemd" when we mean "system"
[thirdparty/systemd.git] / src / core / dbus-kill.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 This file is part of systemd.
4
5 Copyright 2012 Lennart Poettering
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include "bus-util.h"
22 #include "dbus-kill.h"
23 #include "kill.h"
24 #include "signal-util.h"
25
26 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_kill_mode, kill_mode, KillMode);
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("SendSIGKILL", "b", bus_property_get_bool, offsetof(KillContext, send_sigkill), SD_BUS_VTABLE_PROPERTY_CONST),
33 SD_BUS_PROPERTY("SendSIGHUP", "b", bus_property_get_bool, offsetof(KillContext, send_sighup), SD_BUS_VTABLE_PROPERTY_CONST),
34 SD_BUS_VTABLE_END
35 };
36
37 int bus_kill_context_set_transient_property(
38 Unit *u,
39 KillContext *c,
40 const char *name,
41 sd_bus_message *message,
42 UnitWriteFlags flags,
43 sd_bus_error *error) {
44
45 int r;
46
47 assert(u);
48 assert(c);
49 assert(name);
50 assert(message);
51
52 flags |= UNIT_PRIVATE;
53
54 if (streq(name, "KillMode")) {
55 const char *m;
56 KillMode k;
57
58 r = sd_bus_message_read(message, "s", &m);
59 if (r < 0)
60 return r;
61
62 k = kill_mode_from_string(m);
63 if (k < 0)
64 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Kill mode '%s' not known.", m);
65
66 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
67 c->kill_mode = k;
68
69 unit_write_settingf(u, flags, name, "KillMode=%s", kill_mode_to_string(k));
70 }
71
72 return 1;
73
74 } else if (streq(name, "KillSignal")) {
75 int sig;
76
77 r = sd_bus_message_read(message, "i", &sig);
78 if (r < 0)
79 return r;
80
81 if (!SIGNAL_VALID(sig))
82 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Signal %i out of range", sig);
83
84 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
85 c->kill_signal = sig;
86
87 unit_write_settingf(u, flags, name, "KillSignal=%s", signal_to_string(sig));
88 }
89
90 return 1;
91
92 } else if (streq(name, "SendSIGHUP")) {
93 int b;
94
95 r = sd_bus_message_read(message, "b", &b);
96 if (r < 0)
97 return r;
98
99 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
100 c->send_sighup = b;
101
102 unit_write_settingf(u, flags, name, "SendSIGHUP=%s", yes_no(b));
103 }
104
105 return 1;
106
107 } else if (streq(name, "SendSIGKILL")) {
108 int b;
109
110 r = sd_bus_message_read(message, "b", &b);
111 if (r < 0)
112 return r;
113
114 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
115 c->send_sigkill = b;
116
117 unit_write_settingf(u, flags, name, "SendSIGKILL=%s", yes_no(b));
118 }
119
120 return 1;
121
122 }
123
124 return 0;
125 }