chiark / gitweb /
bus: instead of exposing the dbus1 flags when acquiring a name use our own that are...
[elogind.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 "kill.h"
24 #include "dbus-kill.h"
25 #include "bus-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), 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
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, "SendSIGHUP")) {
74                 int b;
75
76                 r = sd_bus_message_read(message, "b", &b);
77                 if (r < 0)
78                         return r;
79
80                 if (mode != UNIT_CHECK) {
81                         c->send_sighup = b;
82
83                         unit_write_drop_in_private_format(u, mode, name, "SendSIGHUP=%s\n", yes_no(b));
84                 }
85
86                 return 1;
87
88         } else if (streq(name, "SendSIGKILL")) {
89                 int b;
90
91                 r = sd_bus_message_read(message, "b", &b);
92                 if (r < 0)
93                         return r;
94
95                 if (mode != UNIT_CHECK) {
96                         c->send_sigkill = b;
97
98                         unit_write_drop_in_private_format(u, mode, name, "SendSIGKILL=%s\n", yes_no(b));
99                 }
100
101                 return 1;
102
103         }
104
105         return 0;
106 }