]>
Commit | Line | Data |
---|---|---|
d6c9574f | 1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
07b0b134 ML |
2 | |
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2010 Lennart Poettering | |
7 | Copyright 2010 Maarten Lankhorst | |
8 | ||
9 | systemd is free software; you can redistribute it and/or modify it | |
10 | under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | systemd is distributed in the hope that it will be useful, but | |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
21 | ***/ | |
22 | ||
4e85aff4 LP |
23 | #include <errno.h> |
24 | ||
07b0b134 ML |
25 | #include "dbus-unit.h" |
26 | #include "dbus-swap.h" | |
15412f29 | 27 | #include "dbus-execute.h" |
bfebab7f | 28 | #include "dbus-common.h" |
07b0b134 | 29 | |
4288f619 LP |
30 | #define BUS_SWAP_INTERFACE \ |
31 | " <interface name=\"org.freedesktop.systemd1.Swap\">\n" \ | |
32 | " <property name=\"What\" type=\"s\" access=\"read\"/>\n" \ | |
33 | " <property name=\"Priority\" type=\"i\" access=\"read\"/>\n" \ | |
15412f29 LP |
34 | " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \ |
35 | BUS_EXEC_COMMAND_INTERFACE("ExecActivate") \ | |
36 | BUS_EXEC_COMMAND_INTERFACE("ExecDeactivate") \ | |
37 | BUS_EXEC_CONTEXT_INTERFACE \ | |
38 | " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \ | |
4288f619 LP |
39 | " </interface>\n" |
40 | ||
41 | #define INTROSPECTION \ | |
42 | DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \ | |
43 | "<node>\n" \ | |
44 | BUS_UNIT_INTERFACE \ | |
45 | BUS_SWAP_INTERFACE \ | |
46 | BUS_PROPERTIES_INTERFACE \ | |
c4e2ceae | 47 | BUS_PEER_INTERFACE \ |
4288f619 LP |
48 | BUS_INTROSPECTABLE_INTERFACE \ |
49 | "</node>\n" | |
50 | ||
05feefe0 LP |
51 | #define INTERFACES_LIST \ |
52 | BUS_UNIT_INTERFACES_LIST \ | |
53 | "org.freedesktop.systemd1.Swap\0" | |
54 | ||
9a60da28 | 55 | const char bus_swap_interface[] _introspect_("Swap") = BUS_SWAP_INTERFACE; |
07b0b134 | 56 | |
c4e2ceae LP |
57 | const char bus_swap_invalidating_properties[] = |
58 | "What\0" | |
59 | "Priority\0" | |
15412f29 LP |
60 | "ExecActivate\0" |
61 | "ExecDeactivate\0" | |
34df5a34 | 62 | "ControlPID\0"; |
c4e2ceae | 63 | |
bfebab7f | 64 | static int bus_swap_append_priority(DBusMessageIter *i, const char *property, void *data) { |
4e85aff4 LP |
65 | Swap *s = data; |
66 | dbus_int32_t j; | |
67 | ||
4e85aff4 LP |
68 | assert(i); |
69 | assert(property); | |
70 | assert(s); | |
71 | ||
72 | if (s->from_proc_swaps) | |
73 | j = s->parameters_proc_swaps.priority; | |
74 | else if (s->from_fragment) | |
75 | j = s->parameters_fragment.priority; | |
76 | else if (s->from_etc_fstab) | |
77 | j = s->parameters_etc_fstab.priority; | |
78 | else | |
79 | j = -1; | |
80 | ||
81 | if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &j)) | |
82 | return -ENOMEM; | |
83 | ||
84 | return 0; | |
85 | } | |
86 | ||
5e8d1c9a | 87 | DBusHandlerResult bus_swap_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) { |
07b0b134 ML |
88 | const BusProperty properties[] = { |
89 | BUS_UNIT_PROPERTIES, | |
15412f29 LP |
90 | { "org.freedesktop.systemd1.Swap", "What", bus_property_append_string, "s", u->swap.what }, |
91 | { "org.freedesktop.systemd1.Swap", "Priority", bus_swap_append_priority, "i", u }, | |
92 | BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Swap", u->swap.exec_command+SWAP_EXEC_ACTIVATE, "ExecActivate"), | |
93 | BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Swap", u->swap.exec_command+SWAP_EXEC_DEACTIVATE, "ExecDeactivate"), | |
94 | BUS_EXEC_CONTEXT_PROPERTIES("org.freedesktop.systemd1.Swap", u->swap.exec_context), | |
95 | { "org.freedesktop.systemd1.Swap", "ControlPID", bus_property_append_pid, "u", &u->swap.control_pid }, | |
07b0b134 ML |
96 | { NULL, NULL, NULL, NULL, NULL } |
97 | }; | |
98 | ||
bfebab7f | 99 | return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties); |
07b0b134 | 100 | } |