]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/dbus-kill.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / core / dbus-kill.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
4819ff03
LP
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
24882e06 21#include "bus-util.h"
4819ff03 22#include "dbus-kill.h"
cf0fbc49
TA
23#include "kill.h"
24#include "signal-util.h"
4819ff03 25
718db961 26static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_kill_mode, kill_mode, KillMode);
4819ff03 27
718db961
LP
28const sd_bus_vtable bus_kill_vtable[] = {
29 SD_BUS_VTABLE_START(0),
556089dc
LP
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),
718db961 34 SD_BUS_VTABLE_END
4819ff03 35};
a6c0353b
LP
36
37int bus_kill_context_set_transient_property(
38 Unit *u,
39 KillContext *c,
40 const char *name,
718db961 41 sd_bus_message *message,
a6c0353b 42 UnitSetPropertiesMode mode,
718db961
LP
43 sd_bus_error *error) {
44
45 int r;
a6c0353b
LP
46
47 assert(u);
48 assert(c);
49 assert(name);
718db961 50 assert(message);
a6c0353b 51
405e0255
LP
52 if (streq(name, "KillMode")) {
53 const char *m;
54 KillMode k;
55
718db961
LP
56 r = sd_bus_message_read(message, "s", &m);
57 if (r < 0)
58 return r;
405e0255
LP
59
60 k = kill_mode_from_string(m);
61 if (k < 0)
6eb7c172 62 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Kill mode '%s' not known.", m);
405e0255
LP
63
64 if (mode != UNIT_CHECK) {
65 c->kill_mode = k;
66
b27b4b51 67 unit_write_drop_in_private_format(u, mode, name, "KillMode=%s", kill_mode_to_string(k));
405e0255
LP
68 }
69
70 return 1;
71
c7040b5d
LP
72 } else if (streq(name, "KillSignal")) {
73 int sig;
74
75 r = sd_bus_message_read(message, "i", &sig);
76 if (r < 0)
77 return r;
78
6eb7c172 79 if (!SIGNAL_VALID(sig))
b4f052a0 80 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Signal %i out of range", sig);
c7040b5d
LP
81
82 if (mode != UNIT_CHECK) {
83 c->kill_signal = sig;
84
b27b4b51 85 unit_write_drop_in_private_format(u, mode, name, "KillSignal=%s", signal_to_string(sig));
c7040b5d
LP
86 }
87
88 return 1;
89
405e0255 90 } else if (streq(name, "SendSIGHUP")) {
718db961 91 int b;
a6c0353b 92
718db961
LP
93 r = sd_bus_message_read(message, "b", &b);
94 if (r < 0)
95 return r;
a6c0353b
LP
96
97 if (mode != UNIT_CHECK) {
a6c0353b 98 c->send_sighup = b;
c3df8d3d 99
b27b4b51 100 unit_write_drop_in_private_format(u, mode, name, "SendSIGHUP=%s", yes_no(b));
a6c0353b
LP
101 }
102
103 return 1;
104
105 } else if (streq(name, "SendSIGKILL")) {
718db961 106 int b;
a6c0353b 107
718db961
LP
108 r = sd_bus_message_read(message, "b", &b);
109 if (r < 0)
110 return r;
a6c0353b
LP
111
112 if (mode != UNIT_CHECK) {
a6c0353b 113 c->send_sigkill = b;
c3df8d3d 114
b27b4b51 115 unit_write_drop_in_private_format(u, mode, name, "SendSIGKILL=%s", yes_no(b));
a6c0353b
LP
116 }
117
118 return 1;
119
120 }
121
122 return 0;
123}