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