]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/dbus-kill.c
core: convert PID 1 to libsystemd-bus
[thirdparty/systemd.git] / src / core / dbus-kill.c
CommitLineData
4819ff03
LP
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
718db961
LP
22#include "bus-util.h"
23#include "kill.h"
4819ff03 24#include "dbus-kill.h"
718db961 25#include "bus-util.h"
4819ff03 26
718db961 27static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_kill_mode, kill_mode, KillMode);
4819ff03 28
718db961
LP
29const 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), 0),
32 SD_BUS_PROPERTY("KillSignal", "i", bus_property_get_int, offsetof(KillContext, kill_signal), 0),
33 SD_BUS_PROPERTY("SendSIGKILL", "b", bus_property_get_bool, offsetof(KillContext, send_sigkill), 0),
34 SD_BUS_PROPERTY("SendSIGHUP", "b", bus_property_get_bool, offsetof(KillContext, send_sighup), 0),
35 SD_BUS_VTABLE_END
4819ff03 36};
a6c0353b
LP
37
38int bus_kill_context_set_transient_property(
39 Unit *u,
40 KillContext *c,
41 const char *name,
718db961 42 sd_bus_message *message,
a6c0353b 43 UnitSetPropertiesMode mode,
718db961
LP
44 sd_bus_error *error) {
45
46 int r;
a6c0353b
LP
47
48 assert(u);
49 assert(c);
50 assert(name);
718db961 51 assert(message);
a6c0353b 52
405e0255
LP
53 if (streq(name, "KillMode")) {
54 const char *m;
55 KillMode k;
56
718db961
LP
57 r = sd_bus_message_read(message, "s", &m);
58 if (r < 0)
59 return r;
405e0255
LP
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, "SendSIGHUP")) {
718db961 74 int b;
a6c0353b 75
718db961
LP
76 r = sd_bus_message_read(message, "b", &b);
77 if (r < 0)
78 return r;
a6c0353b
LP
79
80 if (mode != UNIT_CHECK) {
a6c0353b 81 c->send_sighup = b;
c3df8d3d 82
405e0255 83 unit_write_drop_in_private_format(u, mode, name, "SendSIGHUP=%s\n", yes_no(b));
a6c0353b
LP
84 }
85
86 return 1;
87
88 } else if (streq(name, "SendSIGKILL")) {
718db961 89 int b;
a6c0353b 90
718db961
LP
91 r = sd_bus_message_read(message, "b", &b);
92 if (r < 0)
93 return r;
a6c0353b
LP
94
95 if (mode != UNIT_CHECK) {
a6c0353b 96 c->send_sigkill = b;
c3df8d3d 97
405e0255 98 unit_write_drop_in_private_format(u, mode, name, "SendSIGKILL=%s\n", yes_no(b));
a6c0353b
LP
99 }
100
101 return 1;
102
103 }
104
105 return 0;
106}