]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/dbus-mount.c
Merge pull request #7388 from keszybz/doc-tweak
[thirdparty/systemd.git] / src / core / dbus-mount.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2010 Lennart Poettering
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include "bus-util.h"
21 #include "dbus-cgroup.h"
22 #include "dbus-execute.h"
23 #include "dbus-kill.h"
24 #include "dbus-mount.h"
25 #include "mount.h"
26 #include "string-util.h"
27 #include "unit.h"
28
29 static int property_get_what(
30 sd_bus *bus,
31 const char *path,
32 const char *interface,
33 const char *property,
34 sd_bus_message *reply,
35 void *userdata,
36 sd_bus_error *error) {
37
38 Mount *m = userdata;
39 const char *d = NULL;
40
41 assert(bus);
42 assert(reply);
43 assert(m);
44
45 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
46 d = m->parameters_proc_self_mountinfo.what;
47 else if (m->from_fragment && m->parameters_fragment.what)
48 d = m->parameters_fragment.what;
49
50 return sd_bus_message_append(reply, "s", d);
51 }
52
53 static int property_get_options(
54 sd_bus *bus,
55 const char *path,
56 const char *interface,
57 const char *property,
58 sd_bus_message *reply,
59 void *userdata,
60 sd_bus_error *error) {
61
62 Mount *m = userdata;
63 const char *d = NULL;
64
65 assert(bus);
66 assert(reply);
67 assert(m);
68
69 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
70 d = m->parameters_proc_self_mountinfo.options;
71 else if (m->from_fragment && m->parameters_fragment.options)
72 d = m->parameters_fragment.options;
73
74 return sd_bus_message_append(reply, "s", d);
75 }
76
77 static int property_get_type(
78 sd_bus *bus,
79 const char *path,
80 const char *interface,
81 const char *property,
82 sd_bus_message *reply,
83 void *userdata,
84 sd_bus_error *error) {
85
86 const char *fstype = NULL;
87 Mount *m = userdata;
88
89 assert(bus);
90 assert(reply);
91 assert(m);
92
93 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
94 fstype = m->parameters_proc_self_mountinfo.fstype;
95 else if (m->from_fragment && m->parameters_fragment.fstype)
96 fstype = m->parameters_fragment.fstype;
97
98 return sd_bus_message_append(reply, "s", fstype);
99 }
100
101 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, mount_result, MountResult);
102
103 const sd_bus_vtable bus_mount_vtable[] = {
104 SD_BUS_VTABLE_START(0),
105 SD_BUS_PROPERTY("Where", "s", NULL, offsetof(Mount, where), SD_BUS_VTABLE_PROPERTY_CONST),
106 SD_BUS_PROPERTY("What", "s", property_get_what, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
107 SD_BUS_PROPERTY("Options","s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
108 SD_BUS_PROPERTY("Type", "s", property_get_type, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
109 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Mount, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST),
110 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Mount, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
111 SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode, offsetof(Mount, directory_mode), SD_BUS_VTABLE_PROPERTY_CONST),
112 SD_BUS_PROPERTY("SloppyOptions", "b", bus_property_get_bool, offsetof(Mount, sloppy_options), SD_BUS_VTABLE_PROPERTY_CONST),
113 SD_BUS_PROPERTY("LazyUnmount", "b", bus_property_get_bool, offsetof(Mount, lazy_unmount), SD_BUS_VTABLE_PROPERTY_CONST),
114 SD_BUS_PROPERTY("ForceUnmount", "b", bus_property_get_bool, offsetof(Mount, force_unmount), SD_BUS_VTABLE_PROPERTY_CONST),
115 SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Mount, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
116 SD_BUS_PROPERTY("UID", "u", NULL, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
117 SD_BUS_PROPERTY("GID", "u", NULL, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
118 BUS_EXEC_COMMAND_VTABLE("ExecMount", offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
119 BUS_EXEC_COMMAND_VTABLE("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
120 BUS_EXEC_COMMAND_VTABLE("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
121 SD_BUS_VTABLE_END
122 };
123
124 static int bus_mount_set_transient_property(
125 Mount *m,
126 const char *name,
127 sd_bus_message *message,
128 UnitSetPropertiesMode mode,
129 sd_bus_error *error) {
130
131 const char *new_property;
132 char **property;
133 char *p;
134 int r;
135
136 assert(m);
137 assert(name);
138 assert(message);
139
140 if (streq(name, "What"))
141 property = &m->parameters_fragment.what;
142 else if (streq(name, "Options"))
143 property = &m->parameters_fragment.options;
144 else if (streq(name, "Type"))
145 property = &m->parameters_fragment.fstype;
146 else
147 return 0;
148
149 r = sd_bus_message_read(message, "s", &new_property);
150 if (r < 0)
151 return r;
152
153 if (mode != UNIT_CHECK) {
154 p = strdup(new_property);
155 if (!p)
156 return -ENOMEM;
157
158 unit_write_drop_in_format(UNIT(m), mode, name, "[Mount]\n%s=%s\n",
159 name, new_property);
160
161 free(*property);
162 *property = p;
163 }
164
165 return 1;
166 }
167
168 int bus_mount_set_property(
169 Unit *u,
170 const char *name,
171 sd_bus_message *message,
172 UnitSetPropertiesMode mode,
173 sd_bus_error *error) {
174
175 Mount *m = MOUNT(u);
176 int r;
177
178 assert(m);
179 assert(name);
180 assert(message);
181
182 r = bus_cgroup_set_property(u, &m->cgroup_context, name, message, mode, error);
183 if (r != 0)
184 return r;
185
186 if (u->transient && u->load_state == UNIT_STUB) {
187 /* This is a transient unit, let's load a little more */
188
189 r = bus_mount_set_transient_property(m, name, message, mode, error);
190 if (r != 0)
191 return r;
192
193 r = bus_exec_context_set_transient_property(u, &m->exec_context, name, message, mode, error);
194 if (r != 0)
195 return r;
196
197 r = bus_kill_context_set_transient_property(u, &m->kill_context, name, message, mode, error);
198 if (r != 0)
199 return r;
200 }
201
202 return 0;
203 }
204
205 int bus_mount_commit_properties(Unit *u) {
206 assert(u);
207
208 unit_update_cgroup_members_masks(u);
209 unit_realize_cgroup(u);
210
211 return 0;
212 }