]>
Commit | Line | Data |
---|---|---|
d6c9574f | 1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
4139c1b2 LP |
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" | |
bfebab7f | 27 | #include "dbus-common.h" |
4139c1b2 | 28 | |
4288f619 LP |
29 | #define BUS_MOUNT_INTERFACE \ |
30 | " <interface name=\"org.freedesktop.systemd1.Mount\">\n" \ | |
31 | " <property name=\"Where\" type=\"s\" access=\"read\"/>\n" \ | |
32 | " <property name=\"What\" type=\"s\" access=\"read\"/>\n" \ | |
33 | " <property name=\"Options\" type=\"s\" access=\"read\"/>\n" \ | |
34 | " <property name=\"Type\" type=\"s\" access=\"read\"/>\n" \ | |
35 | " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \ | |
fe68089d LP |
36 | BUS_EXEC_COMMAND_INTERFACE("ExecMount") \ |
37 | BUS_EXEC_COMMAND_INTERFACE("ExecUnmount") \ | |
38 | BUS_EXEC_COMMAND_INTERFACE("ExecRemount") \ | |
4288f619 | 39 | BUS_EXEC_CONTEXT_INTERFACE \ |
4288f619 | 40 | " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \ |
5bd07073 | 41 | " <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \ |
4288f619 LP |
42 | " </interface>\n" |
43 | ||
44 | #define INTROSPECTION \ | |
45 | DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \ | |
46 | "<node>\n" \ | |
47 | BUS_UNIT_INTERFACE \ | |
48 | BUS_MOUNT_INTERFACE \ | |
49 | BUS_PROPERTIES_INTERFACE \ | |
c4e2ceae | 50 | BUS_PEER_INTERFACE \ |
4288f619 LP |
51 | BUS_INTROSPECTABLE_INTERFACE \ |
52 | "</node>\n" | |
53 | ||
05feefe0 LP |
54 | #define INTERFACES_LIST \ |
55 | BUS_UNIT_INTERFACES_LIST \ | |
56 | "org.freedesktop.systemd1.Mount\0" | |
57 | ||
9a60da28 | 58 | const char bus_mount_interface[] _introspect_("Mount") = BUS_MOUNT_INTERFACE; |
4139c1b2 | 59 | |
c4e2ceae LP |
60 | const char bus_mount_invalidating_properties[] = |
61 | "What\0" | |
62 | "Options\0" | |
63 | "Type\0" | |
64 | "ExecMount\0" | |
65 | "ExecUnmount\0" | |
66 | "ExecRemount\0" | |
34df5a34 | 67 | "ControlPID\0"; |
c4e2ceae | 68 | |
bfebab7f | 69 | static int bus_mount_append_what(DBusMessageIter *i, const char *property, void *data) { |
4e85aff4 LP |
70 | Mount *m = data; |
71 | const char *d; | |
72 | ||
4e85aff4 LP |
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 | ||
bfebab7f | 92 | static int bus_mount_append_options(DBusMessageIter *i, const char *property, void *data) { |
4e85aff4 LP |
93 | Mount *m = data; |
94 | const char *d; | |
95 | ||
4e85aff4 LP |
96 | assert(i); |
97 | assert(property); | |
98 | assert(m); | |
99 | ||
100 | if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options) | |
101 | d = m->parameters_proc_self_mountinfo.options; | |
102 | else if (m->from_fragment && m->parameters_fragment.options) | |
103 | d = m->parameters_fragment.options; | |
104 | else if (m->from_etc_fstab && m->parameters_etc_fstab.options) | |
105 | d = m->parameters_etc_fstab.options; | |
106 | else | |
107 | d = ""; | |
108 | ||
109 | if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d)) | |
110 | return -ENOMEM; | |
111 | ||
112 | return 0; | |
113 | } | |
114 | ||
bfebab7f | 115 | static int bus_mount_append_type(DBusMessageIter *i, const char *property, void *data) { |
4e85aff4 LP |
116 | Mount *m = data; |
117 | const char *d; | |
118 | ||
4e85aff4 LP |
119 | assert(i); |
120 | assert(property); | |
121 | assert(m); | |
122 | ||
123 | if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype) | |
124 | d = m->parameters_proc_self_mountinfo.fstype; | |
125 | else if (m->from_fragment && m->parameters_fragment.fstype) | |
126 | d = m->parameters_fragment.fstype; | |
127 | else if (m->from_etc_fstab && m->parameters_etc_fstab.fstype) | |
128 | d = m->parameters_etc_fstab.fstype; | |
129 | else | |
130 | d = ""; | |
131 | ||
132 | if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d)) | |
133 | return -ENOMEM; | |
134 | ||
135 | return 0; | |
136 | } | |
137 | ||
d200735e MS |
138 | static const BusProperty bus_mount_properties[] = { |
139 | { "Where", bus_property_append_string, "s", offsetof(Mount, where), true }, | |
140 | { "What", bus_mount_append_what, "s", 0 }, | |
141 | { "Options", bus_mount_append_options, "s", 0 }, | |
142 | { "Type", bus_mount_append_type, "s", 0 }, | |
143 | { "TimeoutUSec", bus_property_append_usec, "t", offsetof(Mount, timeout_usec) }, | |
144 | BUS_EXEC_COMMAND_PROPERTY("ExecMount", offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]), false), | |
145 | BUS_EXEC_COMMAND_PROPERTY("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), false), | |
146 | BUS_EXEC_COMMAND_PROPERTY("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), false), | |
147 | { "ControlPID", bus_property_append_pid, "u", offsetof(Mount, control_pid) }, | |
148 | { "DirectoryMode", bus_property_append_mode, "u", offsetof(Mount, directory_mode) }, | |
149 | { NULL, } | |
150 | }; | |
151 | ||
5e8d1c9a | 152 | DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) { |
ac155bb8 | 153 | Mount *m = MOUNT(u); |
d200735e MS |
154 | |
155 | const BusBoundProperties bps[] = { | |
156 | { "org.freedesktop.systemd1.Unit", bus_unit_properties, u }, | |
157 | { "org.freedesktop.systemd1.Mount", bus_mount_properties, m }, | |
158 | { "org.freedesktop.systemd1.Mount", bus_exec_context_properties, &m->exec_context }, | |
159 | { NULL, } | |
4139c1b2 LP |
160 | }; |
161 | ||
d200735e | 162 | return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps ); |
4139c1b2 | 163 | } |