]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
4139c1b2 | 2 | |
40af3d02 | 3 | #include "bus-get-properties.h" |
07630cea | 4 | #include "dbus-cgroup.h" |
4139c1b2 | 5 | #include "dbus-execute.h" |
4ad49000 | 6 | #include "dbus-kill.h" |
cf0fbc49 | 7 | #include "dbus-mount.h" |
b3f1d540 | 8 | #include "dbus-util.h" |
435e1098 | 9 | #include "fstab-util.h" |
07630cea LP |
10 | #include "mount.h" |
11 | #include "string-util.h" | |
12 | #include "unit.h" | |
4804da58 YW |
13 | #include "utf8.h" |
14 | ||
15 | static int property_get_what( | |
16 | sd_bus *bus, | |
17 | const char *path, | |
18 | const char *interface, | |
19 | const char *property, | |
20 | sd_bus_message *reply, | |
21 | void *userdata, | |
22 | sd_bus_error *error) { | |
23 | ||
24 | _cleanup_free_ char *escaped = NULL; | |
25 | Mount *m = ASSERT_PTR(userdata); | |
4804da58 YW |
26 | |
27 | assert(bus); | |
28 | assert(reply); | |
718db961 | 29 | |
8dbab37d DDM |
30 | escaped = mount_get_what_escaped(m); |
31 | if (!escaped) | |
32 | return -ENOMEM; | |
4804da58 YW |
33 | |
34 | return sd_bus_message_append_basic(reply, 's', escaped); | |
4e85aff4 LP |
35 | } |
36 | ||
4804da58 YW |
37 | static int property_get_options( |
38 | sd_bus *bus, | |
39 | const char *path, | |
40 | const char *interface, | |
41 | const char *property, | |
42 | sd_bus_message *reply, | |
43 | void *userdata, | |
44 | sd_bus_error *error) { | |
45 | ||
46 | _cleanup_free_ char *escaped = NULL; | |
47 | Mount *m = ASSERT_PTR(userdata); | |
4804da58 YW |
48 | |
49 | assert(bus); | |
50 | assert(reply); | |
51 | ||
8dbab37d DDM |
52 | escaped = mount_get_options_escaped(m); |
53 | if (!escaped) | |
54 | return -ENOMEM; | |
4804da58 YW |
55 | |
56 | return sd_bus_message_append_basic(reply, 's', escaped); | |
4e85aff4 LP |
57 | } |
58 | ||
f724fd4c | 59 | static BUS_DEFINE_PROPERTY_GET(property_get_type, "s", Mount, mount_get_fstype); |
718db961 LP |
60 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, mount_result, MountResult); |
61 | ||
62 | const sd_bus_vtable bus_mount_vtable[] = { | |
63 | SD_BUS_VTABLE_START(0), | |
556089dc | 64 | SD_BUS_PROPERTY("Where", "s", NULL, offsetof(Mount, where), SD_BUS_VTABLE_PROPERTY_CONST), |
718db961 | 65 | SD_BUS_PROPERTY("What", "s", property_get_what, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
7f5c82aa | 66 | SD_BUS_PROPERTY("Options", "s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
718db961 | 67 | SD_BUS_PROPERTY("Type", "s", property_get_type, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
556089dc | 68 | SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Mount, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
360f384f | 69 | SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Mount, control_pid.pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
556089dc | 70 | SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode, offsetof(Mount, directory_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
2dbd4a94 | 71 | SD_BUS_PROPERTY("SloppyOptions", "b", bus_property_get_bool, offsetof(Mount, sloppy_options), SD_BUS_VTABLE_PROPERTY_CONST), |
e520950a | 72 | SD_BUS_PROPERTY("LazyUnmount", "b", bus_property_get_bool, offsetof(Mount, lazy_unmount), SD_BUS_VTABLE_PROPERTY_CONST), |
4f8d40a9 | 73 | SD_BUS_PROPERTY("ForceUnmount", "b", bus_property_get_bool, offsetof(Mount, force_unmount), SD_BUS_VTABLE_PROPERTY_CONST), |
c600357b | 74 | SD_BUS_PROPERTY("ReadWriteOnly", "b", bus_property_get_bool, offsetof(Mount, read_write_only), SD_BUS_VTABLE_PROPERTY_CONST), |
718db961 | 75 | SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Mount, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
05156503 YW |
76 | SD_BUS_PROPERTY("UID", "u", bus_property_get_uid, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
77 | SD_BUS_PROPERTY("GID", "u", bus_property_get_gid, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
556089dc LP |
78 | BUS_EXEC_COMMAND_VTABLE("ExecMount", offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
79 | BUS_EXEC_COMMAND_VTABLE("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), | |
80 | BUS_EXEC_COMMAND_VTABLE("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), | |
718db961 | 81 | SD_BUS_VTABLE_END |
d200735e MS |
82 | }; |
83 | ||
0e252f6b TG |
84 | static int bus_mount_set_transient_property( |
85 | Mount *m, | |
86 | const char *name, | |
87 | sd_bus_message *message, | |
2e59b241 | 88 | UnitWriteFlags flags, |
0e252f6b TG |
89 | sd_bus_error *error) { |
90 | ||
b3f1d540 | 91 | Unit *u = UNIT(m); |
435e1098 | 92 | int r; |
0e252f6b TG |
93 | |
94 | assert(m); | |
95 | assert(name); | |
96 | assert(message); | |
97 | ||
2e59b241 LP |
98 | flags |= UNIT_PRIVATE; |
99 | ||
b3f1d540 YW |
100 | if (streq(name, "Where")) |
101 | return bus_set_transient_path(u, name, &m->where, message, flags, error); | |
102 | ||
435e1098 MY |
103 | if (streq(name, "What")) { |
104 | _cleanup_free_ char *path = NULL; | |
105 | const char *v; | |
106 | ||
107 | r = sd_bus_message_read(message, "s", &v); | |
108 | if (r < 0) | |
109 | return r; | |
110 | ||
111 | if (!isempty(v)) { | |
112 | path = fstab_node_to_udev_node(v); | |
113 | if (!path) | |
114 | return -ENOMEM; | |
115 | ||
116 | /* path_is_valid is not used - see the comment for config_parse_mount_node */ | |
117 | if (strlen(path) >= PATH_MAX) | |
118 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Resolved What=%s too long", path); | |
119 | } | |
120 | ||
121 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
122 | free_and_replace(m->parameters_fragment.what, path); | |
123 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "What=%s", strempty(m->parameters_fragment.what)); | |
124 | } | |
125 | ||
126 | return 1; | |
127 | } | |
b3f1d540 YW |
128 | |
129 | if (streq(name, "Options")) | |
130 | return bus_set_transient_string(u, name, &m->parameters_fragment.options, message, flags, error); | |
131 | ||
132 | if (streq(name, "Type")) | |
133 | return bus_set_transient_string(u, name, &m->parameters_fragment.fstype, message, flags, error); | |
134 | ||
135 | if (streq(name, "TimeoutUSec")) | |
136 | return bus_set_transient_usec_fix_0(u, name, &m->timeout_usec, message, flags, error); | |
0e252f6b | 137 | |
b3f1d540 YW |
138 | if (streq(name, "DirectoryMode")) |
139 | return bus_set_transient_mode_t(u, name, &m->directory_mode, message, flags, error); | |
0e252f6b | 140 | |
b3f1d540 YW |
141 | if (streq(name, "SloppyOptions")) |
142 | return bus_set_transient_bool(u, name, &m->sloppy_options, message, flags, error); | |
0e252f6b | 143 | |
b3f1d540 YW |
144 | if (streq(name, "LazyUnmount")) |
145 | return bus_set_transient_bool(u, name, &m->lazy_unmount, message, flags, error); | |
96f5957f | 146 | |
b3f1d540 YW |
147 | if (streq(name, "ForceUnmount")) |
148 | return bus_set_transient_bool(u, name, &m->force_unmount, message, flags, error); | |
0e252f6b | 149 | |
c600357b MH |
150 | if (streq(name, "ReadWriteOnly")) |
151 | return bus_set_transient_bool(u, name, &m->read_write_only, message, flags, error); | |
152 | ||
b3f1d540 | 153 | return 0; |
0e252f6b TG |
154 | } |
155 | ||
74c964d3 LP |
156 | int bus_mount_set_property( |
157 | Unit *u, | |
158 | const char *name, | |
718db961 | 159 | sd_bus_message *message, |
2e59b241 | 160 | UnitWriteFlags flags, |
718db961 | 161 | sd_bus_error *error) { |
74c964d3 LP |
162 | |
163 | Mount *m = MOUNT(u); | |
0e252f6b | 164 | int r; |
74c964d3 | 165 | |
718db961 | 166 | assert(m); |
74c964d3 | 167 | assert(name); |
718db961 | 168 | assert(message); |
74c964d3 | 169 | |
2e59b241 | 170 | r = bus_cgroup_set_property(u, &m->cgroup_context, name, message, flags, error); |
0e252f6b TG |
171 | if (r != 0) |
172 | return r; | |
173 | ||
174 | if (u->transient && u->load_state == UNIT_STUB) { | |
175 | /* This is a transient unit, let's load a little more */ | |
176 | ||
2e59b241 | 177 | r = bus_mount_set_transient_property(m, name, message, flags, error); |
0e252f6b TG |
178 | if (r != 0) |
179 | return r; | |
180 | ||
2e59b241 | 181 | r = bus_exec_context_set_transient_property(u, &m->exec_context, name, message, flags, error); |
0e252f6b TG |
182 | if (r != 0) |
183 | return r; | |
184 | ||
2e59b241 | 185 | r = bus_kill_context_set_transient_property(u, &m->kill_context, name, message, flags, error); |
0e252f6b TG |
186 | if (r != 0) |
187 | return r; | |
188 | } | |
189 | ||
190 | return 0; | |
74c964d3 LP |
191 | } |
192 | ||
193 | int bus_mount_commit_properties(Unit *u) { | |
194 | assert(u); | |
195 | ||
196 | unit_realize_cgroup(u); | |
bc432dc7 | 197 | |
74c964d3 LP |
198 | return 0; |
199 | } |