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