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