chiark / gitweb /
dbus: add service D-Bus property "Sockets"
[elogind.git] / src / dbus-mount.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
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2 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   General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <errno.h>
23
24 #include "dbus-unit.h"
25 #include "dbus-mount.h"
26 #include "dbus-execute.h"
27
28 #define BUS_MOUNT_INTERFACE                                             \
29         " <interface name=\"org.freedesktop.systemd1.Mount\">\n"        \
30         "  <property name=\"Where\" type=\"s\" access=\"read\"/>\n"     \
31         "  <property name=\"What\" type=\"s\" access=\"read\"/>\n"      \
32         "  <property name=\"Options\" type=\"s\" access=\"read\"/>\n"   \
33         "  <property name=\"Type\" type=\"s\" access=\"read\"/>\n"      \
34         "  <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
35         BUS_EXEC_COMMAND_INTERFACE("ExecMount")                         \
36         BUS_EXEC_COMMAND_INTERFACE("ExecUnmount")                       \
37         BUS_EXEC_COMMAND_INTERFACE("ExecRemount")                       \
38         BUS_EXEC_CONTEXT_INTERFACE                                      \
39         "  <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
40         "  <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
41         " </interface>\n"
42
43 #define INTROSPECTION                                                   \
44         DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                       \
45         "<node>\n"                                                      \
46         BUS_UNIT_INTERFACE                                              \
47         BUS_MOUNT_INTERFACE                                             \
48         BUS_PROPERTIES_INTERFACE                                        \
49         BUS_PEER_INTERFACE                                              \
50         BUS_INTROSPECTABLE_INTERFACE                                    \
51         "</node>\n"
52
53 #define INTERFACES_LIST                              \
54         BUS_UNIT_INTERFACES_LIST                     \
55         "org.freedesktop.systemd1.Mount\0"
56
57 const char bus_mount_interface[] _introspect_("Mount") = BUS_MOUNT_INTERFACE;
58
59 const char bus_mount_invalidating_properties[] =
60         "What\0"
61         "Options\0"
62         "Type\0"
63         "ExecMount\0"
64         "ExecUnmount\0"
65         "ExecRemount\0"
66         "ControlPID\0";
67
68 static int bus_mount_append_what(Manager *n, DBusMessageIter *i, const char *property, void *data) {
69         Mount *m = data;
70         const char *d;
71
72         assert(n);
73         assert(i);
74         assert(property);
75         assert(m);
76
77         if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
78                 d = m->parameters_proc_self_mountinfo.what;
79         else if (m->from_fragment && m->parameters_fragment.what)
80                 d = m->parameters_fragment.what;
81         else if (m->from_etc_fstab && m->parameters_etc_fstab.what)
82                 d = m->parameters_etc_fstab.what;
83         else
84                 d = "";
85
86         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
87                 return -ENOMEM;
88
89         return 0;
90 }
91
92 static int bus_mount_append_options(Manager *n, DBusMessageIter *i, const char *property, void *data) {
93         Mount *m = data;
94         const char *d;
95
96         assert(n);
97         assert(i);
98         assert(property);
99         assert(m);
100
101         if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
102                 d = m->parameters_proc_self_mountinfo.options;
103         else if (m->from_fragment && m->parameters_fragment.options)
104                 d = m->parameters_fragment.options;
105         else if (m->from_etc_fstab && m->parameters_etc_fstab.options)
106                 d = m->parameters_etc_fstab.options;
107         else
108                 d = "";
109
110         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
111                 return -ENOMEM;
112
113         return 0;
114 }
115
116 static int bus_mount_append_type(Manager *n, DBusMessageIter *i, const char *property, void *data) {
117         Mount *m = data;
118         const char *d;
119
120         assert(n);
121         assert(i);
122         assert(property);
123         assert(m);
124
125         if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
126                 d = m->parameters_proc_self_mountinfo.fstype;
127         else if (m->from_fragment && m->parameters_fragment.fstype)
128                 d = m->parameters_fragment.fstype;
129         else if (m->from_etc_fstab && m->parameters_etc_fstab.fstype)
130                 d = m->parameters_etc_fstab.fstype;
131         else
132                 d = "";
133
134         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
135                 return -ENOMEM;
136
137         return 0;
138 }
139
140 DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
141         const BusProperty properties[] = {
142                 BUS_UNIT_PROPERTIES,
143                 { "org.freedesktop.systemd1.Mount", "Where",         bus_property_append_string, "s", u->mount.where           },
144                 { "org.freedesktop.systemd1.Mount", "What",          bus_mount_append_what,      "s", u                        },
145                 { "org.freedesktop.systemd1.Mount", "Options",       bus_mount_append_options,   "s", u                        },
146                 { "org.freedesktop.systemd1.Mount", "Type",          bus_mount_append_type,      "s", u                        },
147                 { "org.freedesktop.systemd1.Mount", "TimeoutUSec",   bus_property_append_usec,   "t", &u->mount.timeout_usec   },
148                 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Mount", u->mount.exec_command+MOUNT_EXEC_MOUNT,   "ExecMount"),
149                 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Mount", u->mount.exec_command+MOUNT_EXEC_UNMOUNT, "ExecUnmount"),
150                 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Mount", u->mount.exec_command+MOUNT_EXEC_REMOUNT, "ExecRemount"),
151                 BUS_EXEC_CONTEXT_PROPERTIES("org.freedesktop.systemd1.Mount", u->mount.exec_context),
152                 { "org.freedesktop.systemd1.Mount", "ControlPID",    bus_property_append_pid,    "u", &u->mount.control_pid    },
153                 { "org.freedesktop.systemd1.Mount", "DirectoryMode", bus_property_append_mode,   "u", &u->mount.directory_mode },
154                 { NULL, NULL, NULL, NULL, NULL }
155         };
156
157         return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
158 }