]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/dbus-mount.c
dbus: to make sure that systemd stays controllable during early bootup, register...
[thirdparty/systemd.git] / src / dbus-mount.c
CommitLineData
4139c1b2
LP
1/*-*- Mode: C; c-basic-offset: 8 -*-*/
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
4e85aff4
LP
22#include <errno.h>
23
4139c1b2
LP
24#include "dbus-unit.h"
25#include "dbus-mount.h"
26#include "dbus-execute.h"
27
4288f619
LP
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_CONTEXT_INTERFACE \
36 " <property name=\"KillMode\" type=\"s\" access=\"read\"/>\n" \
37 " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
38 " </interface>\n"
39
40#define INTROSPECTION \
41 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
42 "<node>\n" \
43 BUS_UNIT_INTERFACE \
44 BUS_MOUNT_INTERFACE \
45 BUS_PROPERTIES_INTERFACE \
46 BUS_INTROSPECTABLE_INTERFACE \
47 "</node>\n"
48
49const char bus_mount_interface[] = BUS_MOUNT_INTERFACE;
4139c1b2 50
4e85aff4
LP
51static int bus_mount_append_what(Manager *n, DBusMessageIter *i, const char *property, void *data) {
52 Mount *m = data;
53 const char *d;
54
55 assert(n);
56 assert(i);
57 assert(property);
58 assert(m);
59
60 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
61 d = m->parameters_proc_self_mountinfo.what;
62 else if (m->from_fragment && m->parameters_fragment.what)
63 d = m->parameters_fragment.what;
64 else if (m->from_etc_fstab && m->parameters_etc_fstab.what)
65 d = m->parameters_etc_fstab.what;
66 else
67 d = "";
68
69 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
70 return -ENOMEM;
71
72 return 0;
73}
74
75static int bus_mount_append_options(Manager *n, DBusMessageIter *i, const char *property, void *data) {
76 Mount *m = data;
77 const char *d;
78
79 assert(n);
80 assert(i);
81 assert(property);
82 assert(m);
83
84 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
85 d = m->parameters_proc_self_mountinfo.options;
86 else if (m->from_fragment && m->parameters_fragment.options)
87 d = m->parameters_fragment.options;
88 else if (m->from_etc_fstab && m->parameters_etc_fstab.options)
89 d = m->parameters_etc_fstab.options;
90 else
91 d = "";
92
93 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
94 return -ENOMEM;
95
96 return 0;
97}
98
99static int bus_mount_append_type(Manager *n, DBusMessageIter *i, const char *property, void *data) {
100 Mount *m = data;
101 const char *d;
102
103 assert(n);
104 assert(i);
105 assert(property);
106 assert(m);
107
108 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
109 d = m->parameters_proc_self_mountinfo.fstype;
110 else if (m->from_fragment && m->parameters_fragment.fstype)
111 d = m->parameters_fragment.fstype;
112 else if (m->from_etc_fstab && m->parameters_etc_fstab.fstype)
113 d = m->parameters_etc_fstab.fstype;
114 else
115 d = "";
116
117 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
118 return -ENOMEM;
119
120 return 0;
121}
122
5e8d1c9a 123DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
4139c1b2
LP
124 const BusProperty properties[] = {
125 BUS_UNIT_PROPERTIES,
126 { "org.freedesktop.systemd1.Mount", "Where", bus_property_append_string, "s", u->mount.where },
4e85aff4
LP
127 { "org.freedesktop.systemd1.Mount", "What", bus_mount_append_what, "s", u },
128 { "org.freedesktop.systemd1.Mount", "Options", bus_mount_append_options, "s", u },
129 { "org.freedesktop.systemd1.Mount", "Type", bus_mount_append_type, "s", u },
4139c1b2
LP
130 { "org.freedesktop.systemd1.Mount", "TimeoutUSec", bus_property_append_usec, "t", &u->mount.timeout_usec },
131 /* ExecCommand */
132 BUS_EXEC_CONTEXT_PROPERTIES("org.freedesktop.systemd1.Mount", u->mount.exec_context),
133 { "org.freedesktop.systemd1.Mount", "KillMode", bus_unit_append_kill_mode, "s", &u->mount.kill_mode },
134 { "org.freedesktop.systemd1.Mount", "ControlPID", bus_property_append_pid, "u", &u->mount.control_pid },
135 { NULL, NULL, NULL, NULL, NULL }
136 };
137
5e8d1c9a 138 return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
4139c1b2 139}