]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/dbus-kill.c
tty-ask-password: Split out password sending
[thirdparty/systemd.git] / src / core / dbus-kill.c
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
22 #include "bus-util.h"
23 #include "dbus-kill.h"
24 #include "kill.h"
25 #include "signal-util.h"
26
27 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_kill_mode, kill_mode, KillMode);
28
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
36 };
37
38 int bus_kill_context_set_transient_property(
39 Unit *u,
40 KillContext *c,
41 const char *name,
42 sd_bus_message *message,
43 UnitSetPropertiesMode mode,
44 sd_bus_error *error) {
45
46 int r;
47
48 assert(u);
49 assert(c);
50 assert(name);
51 assert(message);
52
53 if (streq(name, "KillMode")) {
54 const char *m;
55 KillMode k;
56
57 r = sd_bus_message_read(message, "s", &m);
58 if (r < 0)
59 return r;
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
73 } else if (streq(name, "KillSignal")) {
74 int sig;
75
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);
82
83 if (mode != UNIT_CHECK) {
84 c->kill_signal = sig;
85
86 unit_write_drop_in_private_format(u, mode, name, "KillSignal=%s\n", signal_to_string(sig));
87 }
88
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) {
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")) {
107 int b;
108
109 r = sd_bus_message_read(message, "b", &b);
110 if (r < 0)
111 return r;
112
113 if (mode != UNIT_CHECK) {
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 }