chiark / gitweb /
mount-setup: fix selinux label after mounting
[elogind.git] / src / dbus-swap.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
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
23 #include <errno.h>
24
25 #include "dbus-unit.h"
26 #include "dbus-swap.h"
27
28 #define BUS_SWAP_INTERFACE                                              \
29         " <interface name=\"org.freedesktop.systemd1.Swap\">\n"         \
30         "  <property name=\"What\" type=\"s\" access=\"read\"/>\n"      \
31         "  <property name=\"Priority\" type=\"i\" access=\"read\"/>\n"  \
32         " </interface>\n"
33
34 #define INTROSPECTION                                                   \
35         DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                       \
36         "<node>\n"                                                      \
37         BUS_UNIT_INTERFACE                                              \
38         BUS_SWAP_INTERFACE                                              \
39         BUS_PROPERTIES_INTERFACE                                        \
40         BUS_PEER_INTERFACE                                              \
41         BUS_INTROSPECTABLE_INTERFACE                                    \
42         "</node>\n"
43
44 const char bus_swap_interface[] = BUS_SWAP_INTERFACE;
45
46 const char bus_swap_invalidating_properties[] =
47         "What\0"
48         "Priority\0"
49         "\0";
50
51 static int bus_swap_append_priority(Manager *m, DBusMessageIter *i, const char *property, void *data) {
52         Swap *s = data;
53         dbus_int32_t j;
54
55         assert(m);
56         assert(i);
57         assert(property);
58         assert(s);
59
60         if (s->from_proc_swaps)
61                 j = s->parameters_proc_swaps.priority;
62         else if (s->from_fragment)
63                 j = s->parameters_fragment.priority;
64         else if (s->from_etc_fstab)
65                 j = s->parameters_etc_fstab.priority;
66         else
67                 j = -1;
68
69         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &j))
70                 return -ENOMEM;
71
72         return 0;
73 }
74
75 DBusHandlerResult bus_swap_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
76         const BusProperty properties[] = {
77                 BUS_UNIT_PROPERTIES,
78                 { "org.freedesktop.systemd1.Swap", "What",     bus_property_append_string, "s", u->swap.what },
79                 { "org.freedesktop.systemd1.Swap", "Priority", bus_swap_append_priority,   "i", u            },
80                 { NULL, NULL, NULL, NULL, NULL }
81         };
82
83         return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
84 }