]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
4139c1b2 | 2 | |
ca78ad1d | 3 | #include <fcntl.h> |
836e4e7e DDM |
4 | #include <sys/stat.h> |
5 | #include <sys/sysmacros.h> | |
0d536673 | 6 | |
b5efdb8a | 7 | #include "alloc-util.h" |
a34ceba6 | 8 | #include "async.h" |
2ea24611 | 9 | #include "bus-common-errors.h" |
40af3d02 | 10 | #include "bus-get-properties.h" |
836e4e7e | 11 | #include "constants.h" |
07630cea | 12 | #include "dbus-cgroup.h" |
4139c1b2 | 13 | #include "dbus-execute.h" |
4819ff03 | 14 | #include "dbus-kill.h" |
afcfaa69 | 15 | #include "dbus-manager.h" |
3ffd4af2 | 16 | #include "dbus-service.h" |
d2f05617 | 17 | #include "dbus-util.h" |
836e4e7e | 18 | #include "dissect-image.h" |
1cf40697 | 19 | #include "execute.h" |
d2f05617 | 20 | #include "exit-status.h" |
3ffd4af2 | 21 | #include "fd-util.h" |
836e4e7e | 22 | #include "glyph-util.h" |
5e8deb94 | 23 | #include "locale-util.h" |
836e4e7e | 24 | #include "manager.h" |
836e4e7e | 25 | #include "mount-util.h" |
cd48e23f | 26 | #include "open-file.h" |
07630cea | 27 | #include "path-util.h" |
5e8deb94 | 28 | #include "selinux-access.h" |
07630cea | 29 | #include "service.h" |
d2f05617 | 30 | #include "signal-util.h" |
07630cea | 31 | #include "string-util.h" |
07630cea | 32 | #include "unit.h" |
718db961 LP |
33 | |
34 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, service_type, ServiceType); | |
596e4470 | 35 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exit_type, service_exit_type, ServiceExitType); |
718db961 LP |
36 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, service_result, ServiceResult); |
37 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_restart, service_restart, ServiceRestart); | |
e568fea9 | 38 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_restart_mode, service_restart_mode, ServiceRestartMode); |
87a47f99 | 39 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_emergency_action, emergency_action, EmergencyAction); |
19dff691 | 40 | static BUS_DEFINE_PROPERTY_GET2(property_get_notify_access, "s", Service, service_get_notify_access, notify_access_to_string); |
5171356e | 41 | static BUS_DEFINE_PROPERTY_GET(property_get_restart_usec_next, "t", Service, service_restart_usec_next); |
3bf0cb65 | 42 | static BUS_DEFINE_PROPERTY_GET(property_get_timeout_abort_usec, "t", Service, service_timeout_abort_usec); |
4793c310 | 43 | static BUS_DEFINE_PROPERTY_GET(property_get_watchdog_usec, "t", Service, service_get_watchdog_usec); |
bf760801 | 44 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_timeout_failure_mode, service_timeout_failure_mode, ServiceTimeoutFailureMode); |
dc653bf4 | 45 | |
cd48e23f RP |
46 | static int property_get_open_files( |
47 | sd_bus *bus, | |
48 | const char *path, | |
49 | const char *interface, | |
50 | const char *property, | |
51 | sd_bus_message *reply, | |
52 | void *userdata, | |
53 | sd_bus_error *error) { | |
54 | ||
55 | OpenFile **open_files = ASSERT_PTR(userdata); | |
56 | int r; | |
57 | ||
58 | assert(bus); | |
59 | assert(reply); | |
60 | ||
61 | r = sd_bus_message_open_container(reply, 'a', "(sst)"); | |
62 | if (r < 0) | |
63 | return r; | |
64 | ||
65 | LIST_FOREACH(open_files, of, *open_files) { | |
04a3af3c | 66 | r = sd_bus_message_append(reply, "(sst)", of->path, of->fdname, (uint64_t) of->flags); |
cd48e23f RP |
67 | if (r < 0) |
68 | return r; | |
69 | } | |
70 | ||
71 | return sd_bus_message_close_container(reply); | |
72 | } | |
73 | ||
3543456f RW |
74 | static int property_get_extra_file_descriptors( |
75 | sd_bus *bus, | |
76 | const char *path, | |
77 | const char *interface, | |
78 | const char *property, | |
79 | sd_bus_message *reply, | |
80 | void *userdata, | |
81 | sd_bus_error *error) { | |
82 | ||
32af4dd8 | 83 | Service *s = ASSERT_PTR(userdata); |
3543456f RW |
84 | int r; |
85 | ||
86 | assert(bus); | |
87 | assert(reply); | |
88 | ||
89 | r = sd_bus_message_open_container(reply, 'a', "s"); | |
90 | if (r < 0) | |
91 | return r; | |
92 | ||
32af4dd8 MY |
93 | FOREACH_ARRAY(i, s->extra_fds, s->n_extra_fds) { |
94 | r = sd_bus_message_append_basic(reply, 's', i->fdname); | |
3543456f RW |
95 | if (r < 0) |
96 | return r; | |
97 | } | |
98 | ||
99 | return sd_bus_message_close_container(reply); | |
100 | } | |
101 | ||
dea700bf YW |
102 | static int property_get_exit_status_set( |
103 | sd_bus *bus, | |
104 | const char *path, | |
105 | const char *interface, | |
106 | const char *property, | |
107 | sd_bus_message *reply, | |
108 | void *userdata, | |
109 | sd_bus_error *error) { | |
110 | ||
99534007 | 111 | const ExitStatusSet *status_set = ASSERT_PTR(userdata); |
23d5dd16 | 112 | unsigned n; |
dea700bf YW |
113 | int r; |
114 | ||
115 | assert(bus); | |
116 | assert(reply); | |
dea700bf YW |
117 | |
118 | r = sd_bus_message_open_container(reply, 'r', "aiai"); | |
119 | if (r < 0) | |
120 | return r; | |
121 | ||
122 | r = sd_bus_message_open_container(reply, 'a', "i"); | |
123 | if (r < 0) | |
124 | return r; | |
125 | ||
90e74a66 | 126 | BITMAP_FOREACH(n, &status_set->status) { |
23d5dd16 | 127 | assert(n < 256); |
dea700bf | 128 | |
23d5dd16 | 129 | r = sd_bus_message_append_basic(reply, 'i', &n); |
dea700bf YW |
130 | if (r < 0) |
131 | return r; | |
132 | } | |
133 | ||
134 | r = sd_bus_message_close_container(reply); | |
135 | if (r < 0) | |
136 | return r; | |
137 | ||
138 | r = sd_bus_message_open_container(reply, 'a', "i"); | |
139 | if (r < 0) | |
140 | return r; | |
141 | ||
90e74a66 | 142 | BITMAP_FOREACH(n, &status_set->signal) { |
dea700bf YW |
143 | const char *str; |
144 | ||
23d5dd16 | 145 | str = signal_to_string(n); |
dea700bf YW |
146 | if (!str) |
147 | continue; | |
148 | ||
23d5dd16 | 149 | r = sd_bus_message_append_basic(reply, 'i', &n); |
dea700bf YW |
150 | if (r < 0) |
151 | return r; | |
152 | } | |
153 | ||
154 | r = sd_bus_message_close_container(reply); | |
155 | if (r < 0) | |
156 | return r; | |
157 | ||
158 | return sd_bus_message_close_container(reply); | |
159 | } | |
160 | ||
af477139 | 161 | static int bus_service_method_mount(sd_bus_message *message, void *userdata, sd_bus_error *error, bool is_image) { |
5162829e | 162 | MountInNamespaceFlags flags = 0; |
99534007 | 163 | Unit *u = ASSERT_PTR(userdata); |
5e8deb94 LB |
164 | int r; |
165 | ||
166 | assert(message); | |
5e8deb94 LB |
167 | |
168 | if (!MANAGER_IS_SYSTEM(u->manager)) | |
f31906ff MY |
169 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, "Adding bind mounts at runtime is only supported by system manager"); |
170 | ||
5162829e LB |
171 | r = unit_can_live_mount(u, error); |
172 | if (r < 0) | |
d24d546d | 173 | return log_unit_debug_errno(u, r, "Cannot schedule live mount operation: %s", bus_error_message(error, r)); |
5e8deb94 LB |
174 | |
175 | r = mac_selinux_unit_access_check(u, message, "start", error); | |
176 | if (r < 0) | |
177 | return r; | |
178 | ||
f31906ff MY |
179 | _cleanup_(mount_options_free_allp) MountOptions *options = NULL; |
180 | const char *src, *dest; | |
181 | int read_only, make_file_or_directory; | |
182 | ||
5e8deb94 LB |
183 | r = sd_bus_message_read(message, "ssbb", &src, &dest, &read_only, &make_file_or_directory); |
184 | if (r < 0) | |
185 | return r; | |
186 | ||
187 | if (!path_is_absolute(src) || !path_is_normalized(src)) | |
f31906ff | 188 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Source path must be absolute and normalized"); |
5e8deb94 | 189 | |
af477139 | 190 | if (!is_image && isempty(dest)) |
5e8deb94 LB |
191 | dest = src; |
192 | else if (!path_is_absolute(dest) || !path_is_normalized(dest)) | |
f31906ff | 193 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path must be absolute and normalized"); |
5e8deb94 | 194 | |
af477139 LB |
195 | if (is_image) { |
196 | r = bus_read_mount_options(message, error, &options, NULL, ""); | |
197 | if (r < 0) | |
198 | return r; | |
199 | } | |
200 | ||
5e8deb94 LB |
201 | r = bus_verify_manage_units_async_full( |
202 | u, | |
af477139 | 203 | is_image ? "mount-image" : "bind-mount", |
af477139 | 204 | N_("Authentication is required to mount on '$(unit)'."), |
5e8deb94 LB |
205 | message, |
206 | error); | |
207 | if (r < 0) | |
208 | return r; | |
209 | if (r == 0) | |
210 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
211 | ||
af477139 | 212 | if (is_image) |
5162829e LB |
213 | flags |= MOUNT_IN_NAMESPACE_IS_IMAGE; |
214 | if (read_only) | |
215 | flags |= MOUNT_IN_NAMESPACE_READ_ONLY; | |
216 | if (make_file_or_directory) | |
217 | flags |= MOUNT_IN_NAMESPACE_MAKE_FILE_OR_DIRECTORY; | |
218 | ||
219 | r = unit_live_mount(u, src, dest, message, flags, options, error); | |
5e8deb94 | 220 | if (r < 0) |
5162829e | 221 | return r; |
5e8deb94 | 222 | |
5162829e | 223 | return 1; |
5e8deb94 LB |
224 | } |
225 | ||
af477139 LB |
226 | int bus_service_method_bind_mount(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
227 | return bus_service_method_mount(message, userdata, error, false); | |
228 | } | |
229 | ||
230 | int bus_service_method_mount_image(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
231 | return bus_service_method_mount(message, userdata, error, true); | |
232 | } | |
233 | ||
2ea24611 LP |
234 | int bus_service_method_dump_file_descriptor_store(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
235 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
236 | Service *s = ASSERT_PTR(userdata); | |
237 | int r; | |
238 | ||
239 | assert(message); | |
240 | ||
241 | r = mac_selinux_unit_access_check(UNIT(s), message, "status", error); | |
242 | if (r < 0) | |
243 | return r; | |
244 | ||
245 | if (s->n_fd_store_max == 0 && s->n_fd_store == 0) | |
246 | return sd_bus_error_setf(error, BUS_ERROR_FILE_DESCRIPTOR_STORE_DISABLED, "File descriptor store not enabled for %s.", UNIT(s)->id); | |
247 | ||
248 | r = sd_bus_message_new_method_return(message, &reply); | |
249 | if (r < 0) | |
250 | return r; | |
251 | ||
252 | r = sd_bus_message_open_container(reply, 'a', "(suuutuusu)"); | |
253 | if (r < 0) | |
254 | return r; | |
255 | ||
256 | LIST_FOREACH(fd_store, i, s->fd_store) { | |
257 | _cleanup_free_ char *path = NULL; | |
258 | struct stat st; | |
259 | int flags; | |
260 | ||
261 | if (fstat(i->fd, &st) < 0) { | |
262 | log_debug_errno(errno, "Failed to stat() file descriptor entry '%s', skipping.", strna(i->fdname)); | |
263 | continue; | |
264 | } | |
265 | ||
266 | flags = fcntl(i->fd, F_GETFL); | |
267 | if (flags < 0) { | |
268 | log_debug_errno(errno, "Failed to issue F_GETFL on file descriptor entry '%s', skipping.", strna(i->fdname)); | |
269 | continue; | |
270 | } | |
271 | ||
da890466 | 272 | /* glibc implies O_LARGEFILE everywhere on 64-bit off_t builds, but forgets to hide it away on |
2ea24611 LP |
273 | * F_GETFL, but provides no definition to check for that. Let's mask the flag away manually, |
274 | * to not confuse clients. */ | |
275 | flags &= ~RAW_O_LARGEFILE; | |
276 | ||
277 | (void) fd_get_path(i->fd, &path); | |
278 | ||
279 | r = sd_bus_message_append( | |
280 | reply, | |
281 | "(suuutuusu)", | |
282 | i->fdname, | |
283 | (uint32_t) st.st_mode, | |
284 | (uint32_t) major(st.st_dev), (uint32_t) minor(st.st_dev), | |
285 | (uint64_t) st.st_ino, | |
286 | (uint32_t) major(st.st_rdev), (uint32_t) minor(st.st_rdev), | |
287 | path, | |
288 | (uint32_t) flags); | |
289 | if (r < 0) | |
290 | return r; | |
291 | } | |
292 | ||
293 | r = sd_bus_message_close_container(reply); | |
294 | if (r < 0) | |
295 | return r; | |
296 | ||
51cc3825 | 297 | return sd_bus_message_send(reply); |
2ea24611 LP |
298 | } |
299 | ||
47226e89 LP |
300 | #if __SIZEOF_SIZE_T__ == 8 |
301 | static int property_get_size_as_uint32( | |
302 | sd_bus *bus, | |
303 | const char *path, | |
304 | const char *interface, | |
305 | const char *property, | |
306 | sd_bus_message *reply, | |
307 | void *userdata, | |
308 | sd_bus_error *error) { | |
309 | ||
310 | size_t *value = ASSERT_PTR(userdata); | |
311 | uint32_t sz = *value >= UINT32_MAX ? UINT32_MAX : (uint32_t) *value; | |
312 | ||
da890466 | 313 | /* Returns a size_t as a D-Bus "u" type, i.e. as 32-bit value, even if size_t is 64-bit. We'll saturate if it doesn't fit. */ |
47226e89 LP |
314 | |
315 | return sd_bus_message_append_basic(reply, 'u', &sz); | |
316 | } | |
317 | #elif __SIZEOF_SIZE_T__ == 4 | |
318 | #define property_get_size_as_uint32 ((sd_bus_property_get_t) NULL) | |
319 | #else | |
320 | #error "Unexpected size of size_t" | |
321 | #endif | |
322 | ||
718db961 LP |
323 | const sd_bus_vtable bus_service_vtable[] = { |
324 | SD_BUS_VTABLE_START(0), | |
556089dc | 325 | SD_BUS_PROPERTY("Type", "s", property_get_type, offsetof(Service, type), SD_BUS_VTABLE_PROPERTY_CONST), |
596e4470 | 326 | SD_BUS_PROPERTY("ExitType", "s", property_get_exit_type, offsetof(Service, exit_type), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 327 | SD_BUS_PROPERTY("Restart", "s", property_get_restart, offsetof(Service, restart), SD_BUS_VTABLE_PROPERTY_CONST), |
e568fea9 | 328 | SD_BUS_PROPERTY("RestartMode", "s", property_get_restart_mode, offsetof(Service, restart_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 329 | SD_BUS_PROPERTY("PIDFile", "s", NULL, offsetof(Service, pid_file), SD_BUS_VTABLE_PROPERTY_CONST), |
19dff691 | 330 | SD_BUS_PROPERTY("NotifyAccess", "s", property_get_notify_access, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
556089dc | 331 | SD_BUS_PROPERTY("RestartUSec", "t", bus_property_get_usec, offsetof(Service, restart_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
be1adc27 | 332 | SD_BUS_PROPERTY("RestartSteps", "u", bus_property_get_unsigned, offsetof(Service, restart_steps), SD_BUS_VTABLE_PROPERTY_CONST), |
e9f17fa8 | 333 | SD_BUS_PROPERTY("RestartMaxDelayUSec", "t", bus_property_get_usec, offsetof(Service, restart_max_delay_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
5171356e | 334 | SD_BUS_PROPERTY("RestartUSecNext", "t", property_get_restart_usec_next, 0, 0), |
556089dc LP |
335 | SD_BUS_PROPERTY("TimeoutStartUSec", "t", bus_property_get_usec, offsetof(Service, timeout_start_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
336 | SD_BUS_PROPERTY("TimeoutStopUSec", "t", bus_property_get_usec, offsetof(Service, timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
dc653bf4 | 337 | SD_BUS_PROPERTY("TimeoutAbortUSec", "t", property_get_timeout_abort_usec, 0, 0), |
bf760801 JK |
338 | SD_BUS_PROPERTY("TimeoutStartFailureMode", "s", property_get_timeout_failure_mode, offsetof(Service, timeout_start_failure_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
339 | SD_BUS_PROPERTY("TimeoutStopFailureMode", "s", property_get_timeout_failure_mode, offsetof(Service, timeout_stop_failure_mode), SD_BUS_VTABLE_PROPERTY_CONST), | |
36c16a7c | 340 | SD_BUS_PROPERTY("RuntimeMaxUSec", "t", bus_property_get_usec, offsetof(Service, runtime_max_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
5918a933 | 341 | SD_BUS_PROPERTY("RuntimeRandomizedExtraUSec", "t", bus_property_get_usec, offsetof(Service, runtime_rand_extra_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
4793c310 | 342 | SD_BUS_PROPERTY("WatchdogUSec", "t", property_get_watchdog_usec, 0, 0), |
718db961 | 343 | BUS_PROPERTY_DUAL_TIMESTAMP("WatchdogTimestamp", offsetof(Service, watchdog_timestamp), 0), |
899feb72 | 344 | SD_BUS_PROPERTY("PermissionsStartOnly", "b", bus_property_get_bool, offsetof(Service, permissions_start_only), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), /* 😷 deprecated */ |
556089dc LP |
345 | SD_BUS_PROPERTY("RootDirectoryStartOnly", "b", bus_property_get_bool, offsetof(Service, root_directory_start_only), SD_BUS_VTABLE_PROPERTY_CONST), |
346 | SD_BUS_PROPERTY("RemainAfterExit", "b", bus_property_get_bool, offsetof(Service, remain_after_exit), SD_BUS_VTABLE_PROPERTY_CONST), | |
347 | SD_BUS_PROPERTY("GuessMainPID", "b", bus_property_get_bool, offsetof(Service, guess_main_pid), SD_BUS_VTABLE_PROPERTY_CONST), | |
dea700bf YW |
348 | SD_BUS_PROPERTY("RestartPreventExitStatus", "(aiai)", property_get_exit_status_set, offsetof(Service, restart_prevent_status), SD_BUS_VTABLE_PROPERTY_CONST), |
349 | SD_BUS_PROPERTY("RestartForceExitStatus", "(aiai)", property_get_exit_status_set, offsetof(Service, restart_force_status), SD_BUS_VTABLE_PROPERTY_CONST), | |
350 | SD_BUS_PROPERTY("SuccessExitStatus", "(aiai)", property_get_exit_status_set, offsetof(Service, success_status), SD_BUS_VTABLE_PROPERTY_CONST), | |
c79ab77c LP |
351 | SD_BUS_PROPERTY("MainPID", "u", bus_property_get_pid, offsetof(Service, main_pid.pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
352 | SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Service, control_pid.pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
556089dc | 353 | SD_BUS_PROPERTY("BusName", "s", NULL, offsetof(Service, bus_name), SD_BUS_VTABLE_PROPERTY_CONST), |
d8e023aa | 354 | SD_BUS_PROPERTY("FileDescriptorStoreMax", "u", bus_property_get_unsigned, offsetof(Service, n_fd_store_max), SD_BUS_VTABLE_PROPERTY_CONST), |
47226e89 | 355 | SD_BUS_PROPERTY("NFileDescriptorStore", "u", property_get_size_as_uint32, offsetof(Service, n_fd_store), 0), |
b9c1883a | 356 | SD_BUS_PROPERTY("FileDescriptorStorePreserve", "s", bus_property_get_exec_preserve_mode, offsetof(Service, fd_store_preserve_mode), 0), |
718db961 | 357 | SD_BUS_PROPERTY("StatusText", "s", NULL, offsetof(Service, status_text), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
05156503 | 358 | SD_BUS_PROPERTY("StatusErrno", "i", bus_property_get_int, offsetof(Service, status_errno), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
9c025022 MY |
359 | SD_BUS_PROPERTY("StatusBusError", "s", NULL, offsetof(Service, status_bus_error), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
360 | SD_BUS_PROPERTY("StatusVarlinkError", "s", NULL, offsetof(Service, status_varlink_error), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
718db961 | 361 | SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Service, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
ebf8d79a | 362 | SD_BUS_PROPERTY("ReloadResult", "s", property_get_result, offsetof(Service, reload_result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
345f3221 | 363 | SD_BUS_PROPERTY("CleanResult", "s", property_get_result, offsetof(Service, clean_result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
5162829e | 364 | SD_BUS_PROPERTY("LiveMountResult", "s", property_get_result, offsetof(Service, live_mount_result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
b4525804 LP |
365 | SD_BUS_PROPERTY("USBFunctionDescriptors", "s", NULL, offsetof(Service, usb_function_descriptors), SD_BUS_VTABLE_PROPERTY_CONST), |
366 | SD_BUS_PROPERTY("USBFunctionStrings", "s", NULL, offsetof(Service, usb_function_strings), SD_BUS_VTABLE_PROPERTY_CONST), | |
05156503 YW |
367 | SD_BUS_PROPERTY("UID", "u", bus_property_get_uid, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
368 | SD_BUS_PROPERTY("GID", "u", bus_property_get_gid, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
7a0019d3 | 369 | SD_BUS_PROPERTY("NRestarts", "u", bus_property_get_unsigned, offsetof(Service, n_restarts), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
afcfaa69 | 370 | SD_BUS_PROPERTY("OOMPolicy", "s", bus_property_get_oom_policy, offsetof(Service, oom_policy), SD_BUS_VTABLE_PROPERTY_CONST), |
cd48e23f | 371 | SD_BUS_PROPERTY("OpenFile", "a(sst)", property_get_open_files, offsetof(Service, open_files), SD_BUS_VTABLE_PROPERTY_CONST), |
32af4dd8 | 372 | SD_BUS_PROPERTY("ExtraFileDescriptorNames", "as", property_get_extra_file_descriptors, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
3bd28bf7 | 373 | SD_BUS_PROPERTY("ReloadSignal", "i", bus_property_get_int, offsetof(Service, reload_signal), SD_BUS_VTABLE_PROPERTY_CONST), |
00d9ef85 | 374 | |
718db961 | 375 | BUS_EXEC_STATUS_VTABLE("ExecMain", offsetof(Service, main_exec_status), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
31cd5f63 | 376 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecCondition", offsetof(Service, exec_command[SERVICE_EXEC_CONDITION]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
898fc00e | 377 | BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecConditionEx", offsetof(Service, exec_command[SERVICE_EXEC_CONDITION]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
556089dc | 378 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPre", offsetof(Service, exec_command[SERVICE_EXEC_START_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
b3d59367 | 379 | BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStartPreEx", offsetof(Service, exec_command[SERVICE_EXEC_START_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
556089dc | 380 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecStart", offsetof(Service, exec_command[SERVICE_EXEC_START]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
b3d59367 | 381 | BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStartEx", offsetof(Service, exec_command[SERVICE_EXEC_START]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
556089dc | 382 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPost", offsetof(Service, exec_command[SERVICE_EXEC_START_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
b3d59367 | 383 | BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStartPostEx", offsetof(Service, exec_command[SERVICE_EXEC_START_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
556089dc | 384 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecReload", offsetof(Service, exec_command[SERVICE_EXEC_RELOAD]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
898fc00e | 385 | BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecReloadEx", offsetof(Service, exec_command[SERVICE_EXEC_RELOAD]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
556089dc | 386 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecStop", offsetof(Service, exec_command[SERVICE_EXEC_STOP]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
898fc00e | 387 | BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStopEx", offsetof(Service, exec_command[SERVICE_EXEC_STOP]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
556089dc | 388 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecStopPost", offsetof(Service, exec_command[SERVICE_EXEC_STOP_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
898fc00e | 389 | BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStopPostEx", offsetof(Service, exec_command[SERVICE_EXEC_STOP_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
51d73fd9 | 390 | |
a008b6d7 | 391 | SD_BUS_METHOD_WITH_ARGS("BindMount", |
392 | SD_BUS_ARGS("s", source, "s", destination, "b", read_only, "b", mkdir), | |
393 | SD_BUS_NO_RESULT, | |
394 | bus_service_method_bind_mount, | |
395 | SD_BUS_VTABLE_UNPRIVILEGED), | |
396 | ||
397 | SD_BUS_METHOD_WITH_ARGS("MountImage", | |
5fe4c30c MY |
398 | SD_BUS_ARGS("s", source, "s", destination, "b", read_only, "b", mkdir, "a(ss)", options), |
399 | SD_BUS_NO_RESULT, | |
400 | bus_service_method_mount_image, | |
401 | SD_BUS_VTABLE_UNPRIVILEGED), | |
af477139 | 402 | |
2ea24611 LP |
403 | SD_BUS_METHOD_WITH_ARGS("DumpFileDescriptorStore", |
404 | SD_BUS_NO_ARGS, | |
405 | SD_BUS_ARGS("a(suuutuusu)", entries), | |
406 | bus_service_method_dump_file_descriptor_store, | |
407 | SD_BUS_VTABLE_UNPRIVILEGED), | |
408 | ||
51d73fd9 | 409 | /* The following four are obsolete, and thus marked hidden here. They moved into the Unit interface */ |
7bf081a1 ZJS |
410 | SD_BUS_PROPERTY("StartLimitInterval", "t", bus_property_get_usec, offsetof(Unit, start_ratelimit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
411 | SD_BUS_PROPERTY("StartLimitBurst", "u", bus_property_get_unsigned, offsetof(Unit, start_ratelimit.burst), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
87a47f99 | 412 | SD_BUS_PROPERTY("StartLimitAction", "s", property_get_emergency_action, offsetof(Unit, start_limit_action), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
53c35a76 | 413 | SD_BUS_PROPERTY("FailureAction", "s", property_get_emergency_action, offsetof(Unit, failure_action), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
51d73fd9 | 414 | SD_BUS_PROPERTY("RebootArgument", "s", NULL, offsetof(Unit, reboot_arg), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
718db961 | 415 | SD_BUS_VTABLE_END |
d200735e MS |
416 | }; |
417 | ||
d2f05617 YW |
418 | static int bus_set_transient_exit_status( |
419 | Unit *u, | |
c2756a68 | 420 | const char *name, |
d2f05617 | 421 | ExitStatusSet *status_set, |
718db961 | 422 | sd_bus_message *message, |
2e59b241 | 423 | UnitWriteFlags flags, |
718db961 | 424 | sd_bus_error *error) { |
c2756a68 | 425 | |
a672f4fe | 426 | const int32_t *status, *signal; |
62b21e2e | 427 | size_t n_status, n_signal, i; |
c2756a68 LP |
428 | int r; |
429 | ||
d2f05617 YW |
430 | r = sd_bus_message_enter_container(message, 'r', "aiai"); |
431 | if (r < 0) | |
432 | return r; | |
c2756a68 | 433 | |
62b21e2e | 434 | r = sd_bus_message_read_array(message, 'i', (const void **) &status, &n_status); |
d2f05617 YW |
435 | if (r < 0) |
436 | return r; | |
2e59b241 | 437 | |
62b21e2e | 438 | r = sd_bus_message_read_array(message, 'i', (const void **) &signal, &n_signal); |
d2f05617 YW |
439 | if (r < 0) |
440 | return r; | |
6577c7ce | 441 | |
d2f05617 YW |
442 | r = sd_bus_message_exit_container(message); |
443 | if (r < 0) | |
444 | return r; | |
6577c7ce | 445 | |
62b21e2e ZJS |
446 | n_status /= sizeof(int32_t); |
447 | n_signal /= sizeof(int32_t); | |
a672f4fe | 448 | |
62b21e2e | 449 | if (n_status == 0 && n_signal == 0 && !UNIT_WRITE_FLAGS_NOOP(flags)) { |
d2f05617 YW |
450 | exit_status_set_free(status_set); |
451 | unit_write_settingf(u, flags, name, "%s=", name); | |
6577c7ce | 452 | return 1; |
d2f05617 | 453 | } |
6577c7ce | 454 | |
62b21e2e | 455 | for (i = 0; i < n_status; i++) { |
d2f05617 | 456 | if (status[i] < 0 || status[i] > 255) |
a672f4fe | 457 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid status code in %s: %"PRIi32, name, status[i]); |
c7040b5d | 458 | |
d2f05617 | 459 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
23d5dd16 | 460 | r = bitmap_set(&status_set->status, status[i]); |
d2f05617 YW |
461 | if (r < 0) |
462 | return r; | |
c7040b5d | 463 | |
a672f4fe | 464 | unit_write_settingf(u, flags, name, "%s=%"PRIi32, name, status[i]); |
c7040b5d | 465 | } |
d2f05617 | 466 | } |
c7040b5d | 467 | |
62b21e2e | 468 | for (i = 0; i < n_signal; i++) { |
d2f05617 | 469 | const char *str; |
36c16a7c | 470 | |
a672f4fe | 471 | str = signal_to_string((int) signal[i]); |
d2f05617 | 472 | if (!str) |
a672f4fe | 473 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal in %s: %"PRIi32, name, signal[i]); |
36c16a7c | 474 | |
2e59b241 | 475 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
23d5dd16 | 476 | r = bitmap_set(&status_set->signal, signal[i]); |
d2f05617 YW |
477 | if (r < 0) |
478 | return r; | |
479 | ||
480 | unit_write_settingf(u, flags, name, "%s=%s", name, str); | |
36c16a7c | 481 | } |
d2f05617 | 482 | } |
36c16a7c | 483 | |
d2f05617 YW |
484 | return 1; |
485 | } | |
c7040b5d | 486 | |
d2f05617 YW |
487 | static int bus_set_transient_std_fd( |
488 | Unit *u, | |
489 | const char *name, | |
490 | int *p, | |
491 | bool *b, | |
492 | sd_bus_message *message, | |
493 | UnitWriteFlags flags, | |
494 | sd_bus_error *error) { | |
4ea0d7f4 | 495 | |
d2f05617 | 496 | int fd, r; |
4ea0d7f4 | 497 | |
d2f05617 YW |
498 | assert(p); |
499 | assert(b); | |
4ea0d7f4 | 500 | |
d2f05617 YW |
501 | r = sd_bus_message_read(message, "h", &fd); |
502 | if (r < 0) | |
503 | return r; | |
4ea0d7f4 | 504 | |
d2f05617 YW |
505 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
506 | int copy; | |
4ea0d7f4 | 507 | |
d2f05617 YW |
508 | copy = fcntl(fd, F_DUPFD_CLOEXEC, 3); |
509 | if (copy < 0) | |
510 | return -errno; | |
a34ceba6 | 511 | |
d2f05617 YW |
512 | asynchronous_close(*p); |
513 | *p = copy; | |
514 | *b = true; | |
515 | } | |
a34ceba6 | 516 | |
d2f05617 YW |
517 | return 1; |
518 | } | |
519 | static BUS_DEFINE_SET_TRANSIENT_PARSE(notify_access, NotifyAccess, notify_access_from_string); | |
520 | static BUS_DEFINE_SET_TRANSIENT_PARSE(service_type, ServiceType, service_type_from_string); | |
596e4470 | 521 | static BUS_DEFINE_SET_TRANSIENT_PARSE(service_exit_type, ServiceExitType, service_exit_type_from_string); |
d2f05617 | 522 | static BUS_DEFINE_SET_TRANSIENT_PARSE(service_restart, ServiceRestart, service_restart_from_string); |
e568fea9 | 523 | static BUS_DEFINE_SET_TRANSIENT_PARSE(service_restart_mode, ServiceRestartMode, service_restart_mode_from_string); |
afcfaa69 | 524 | static BUS_DEFINE_SET_TRANSIENT_PARSE(oom_policy, OOMPolicy, oom_policy_from_string); |
5453a4b1 | 525 | static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(bus_name, sd_bus_service_name_is_valid); |
bf760801 | 526 | static BUS_DEFINE_SET_TRANSIENT_PARSE(timeout_failure_mode, ServiceTimeoutFailureMode, service_timeout_failure_mode_from_string); |
3bd28bf7 | 527 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING(reload_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check); |
a34ceba6 | 528 | |
d2f05617 YW |
529 | static int bus_service_set_transient_property( |
530 | Service *s, | |
531 | const char *name, | |
532 | sd_bus_message *message, | |
533 | UnitWriteFlags flags, | |
534 | sd_bus_error *error) { | |
a34ceba6 | 535 | |
d2f05617 YW |
536 | Unit *u = UNIT(s); |
537 | ServiceExecCommand ci; | |
538 | int r; | |
9efb9df9 | 539 | |
d2f05617 YW |
540 | assert(s); |
541 | assert(name); | |
542 | assert(message); | |
9efb9df9 | 543 | |
d2f05617 | 544 | flags |= UNIT_PRIVATE; |
9efb9df9 | 545 | |
d2f05617 YW |
546 | if (streq(name, "PermissionsStartOnly")) |
547 | return bus_set_transient_bool(u, name, &s->permissions_start_only, message, flags, error); | |
9efb9df9 | 548 | |
d2f05617 YW |
549 | if (streq(name, "RootDirectoryStartOnly")) |
550 | return bus_set_transient_bool(u, name, &s->root_directory_start_only, message, flags, error); | |
9efb9df9 | 551 | |
d2f05617 YW |
552 | if (streq(name, "RemainAfterExit")) |
553 | return bus_set_transient_bool(u, name, &s->remain_after_exit, message, flags, error); | |
9efb9df9 | 554 | |
d2f05617 YW |
555 | if (streq(name, "GuessMainPID")) |
556 | return bus_set_transient_bool(u, name, &s->guess_main_pid, message, flags, error); | |
9efb9df9 | 557 | |
d2f05617 YW |
558 | if (streq(name, "Type")) |
559 | return bus_set_transient_service_type(u, name, &s->type, message, flags, error); | |
9efb9df9 | 560 | |
596e4470 HC |
561 | if (streq(name, "ExitType")) |
562 | return bus_set_transient_service_exit_type(u, name, &s->exit_type, message, flags, error); | |
563 | ||
afcfaa69 LP |
564 | if (streq(name, "OOMPolicy")) |
565 | return bus_set_transient_oom_policy(u, name, &s->oom_policy, message, flags, error); | |
566 | ||
d2f05617 YW |
567 | if (streq(name, "RestartUSec")) |
568 | return bus_set_transient_usec(u, name, &s->restart_usec, message, flags, error); | |
569 | ||
be1adc27 MY |
570 | if (streq(name, "RestartSteps")) |
571 | return bus_set_transient_unsigned(u, name, &s->restart_steps, message, flags, error); | |
572 | ||
e9f17fa8 MY |
573 | if (streq(name, "RestartMaxDelayUSec")) |
574 | return bus_set_transient_usec(u, name, &s->restart_max_delay_usec, message, flags, error); | |
be1adc27 | 575 | |
d2f05617 YW |
576 | if (streq(name, "TimeoutStartUSec")) { |
577 | r = bus_set_transient_usec(u, name, &s->timeout_start_usec, message, flags, error); | |
578 | if (r >= 0 && !UNIT_WRITE_FLAGS_NOOP(flags)) | |
579 | s->start_timeout_defined = true; | |
580 | ||
581 | return r; | |
582 | } | |
583 | ||
584 | if (streq(name, "TimeoutStopUSec")) | |
585 | return bus_set_transient_usec(u, name, &s->timeout_stop_usec, message, flags, error); | |
586 | ||
e737017b ZJS |
587 | if (streq(name, "TimeoutAbortUSec")) { |
588 | r = bus_set_transient_usec(u, name, &s->timeout_abort_usec, message, flags, error); | |
589 | if (r >= 0 && !UNIT_WRITE_FLAGS_NOOP(flags)) | |
590 | s->timeout_abort_set = true; | |
591 | return r; | |
592 | } | |
593 | ||
bf760801 JK |
594 | if (streq(name, "TimeoutStartFailureMode")) |
595 | return bus_set_transient_timeout_failure_mode(u, name, &s->timeout_start_failure_mode, message, flags, error); | |
596 | ||
597 | if (streq(name, "TimeoutStopFailureMode")) | |
598 | return bus_set_transient_timeout_failure_mode(u, name, &s->timeout_stop_failure_mode, message, flags, error); | |
599 | ||
d2f05617 YW |
600 | if (streq(name, "RuntimeMaxUSec")) |
601 | return bus_set_transient_usec(u, name, &s->runtime_max_usec, message, flags, error); | |
602 | ||
5918a933 AB |
603 | if (streq(name, "RuntimeRandomizedExtraUSec")) |
604 | return bus_set_transient_usec(u, name, &s->runtime_rand_extra_usec, message, flags, error); | |
605 | ||
d2f05617 YW |
606 | if (streq(name, "WatchdogUSec")) |
607 | return bus_set_transient_usec(u, name, &s->watchdog_usec, message, flags, error); | |
608 | ||
609 | if (streq(name, "FileDescriptorStoreMax")) | |
610 | return bus_set_transient_unsigned(u, name, &s->n_fd_store_max, message, flags, error); | |
611 | ||
b9c1883a LP |
612 | if (streq(name, "FileDescriptorStorePreserve")) |
613 | return bus_set_transient_exec_preserve_mode(u, name, &s->fd_store_preserve_mode, message, flags, error); | |
614 | ||
d2f05617 YW |
615 | if (streq(name, "NotifyAccess")) |
616 | return bus_set_transient_notify_access(u, name, &s->notify_access, message, flags, error); | |
617 | ||
a9353a5c LP |
618 | if (streq(name, "PIDFile")) { |
619 | _cleanup_free_ char *n = NULL; | |
620 | const char *v, *e; | |
621 | ||
622 | r = sd_bus_message_read(message, "s", &v); | |
623 | if (r < 0) | |
624 | return r; | |
625 | ||
64242fd3 YW |
626 | if (!isempty(v)) { |
627 | n = path_make_absolute(v, u->manager->prefix[EXEC_DIRECTORY_RUNTIME]); | |
628 | if (!n) | |
629 | return -ENOMEM; | |
a9353a5c | 630 | |
4ff361cc | 631 | path_simplify(n); |
a9353a5c | 632 | |
64242fd3 YW |
633 | if (!path_is_normalized(n)) |
634 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "PIDFile= path '%s' is not valid", n); | |
a9353a5c | 635 | |
64242fd3 YW |
636 | e = path_startswith(n, "/var/run/"); |
637 | if (e) { | |
638 | char *z; | |
a9353a5c | 639 | |
657ee2d8 | 640 | z = path_join("/run", e); |
64242fd3 YW |
641 | if (!z) |
642 | return log_oom(); | |
a9353a5c | 643 | |
64242fd3 | 644 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) |
e2341b6b | 645 | log_unit_notice(u, "Transient unit's PIDFile= property references path below legacy directory /var/run, updating %s %s %s; please update client accordingly.", |
1ae9b0cf | 646 | n, glyph(GLYPH_ARROW_RIGHT), z); |
a9353a5c | 647 | |
64242fd3 YW |
648 | free_and_replace(n, z); |
649 | } | |
c79d66fc YW |
650 | } |
651 | ||
652 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
a9353a5c | 653 | free_and_replace(s->pid_file, n); |
64242fd3 | 654 | unit_write_settingf(u, flags, name, "%s=%s", name, strempty(s->pid_file)); |
c79d66fc | 655 | } |
a9353a5c LP |
656 | |
657 | return 1; | |
658 | } | |
d2f05617 YW |
659 | |
660 | if (streq(name, "USBFunctionDescriptors")) | |
661 | return bus_set_transient_path(u, name, &s->usb_function_descriptors, message, flags, error); | |
662 | ||
663 | if (streq(name, "USBFunctionStrings")) | |
664 | return bus_set_transient_path(u, name, &s->usb_function_strings, message, flags, error); | |
665 | ||
666 | if (streq(name, "BusName")) | |
667 | return bus_set_transient_bus_name(u, name, &s->bus_name, message, flags, error); | |
668 | ||
669 | if (streq(name, "Restart")) | |
670 | return bus_set_transient_service_restart(u, name, &s->restart, message, flags, error); | |
671 | ||
e568fea9 RP |
672 | if (streq(name, "RestartMode")) |
673 | return bus_set_transient_service_restart_mode(u, name, &s->restart_mode, message, flags, error); | |
674 | ||
d2f05617 YW |
675 | if (streq(name, "RestartPreventExitStatus")) |
676 | return bus_set_transient_exit_status(u, name, &s->restart_prevent_status, message, flags, error); | |
677 | ||
678 | if (streq(name, "RestartForceExitStatus")) | |
679 | return bus_set_transient_exit_status(u, name, &s->restart_force_status, message, flags, error); | |
680 | ||
681 | if (streq(name, "SuccessExitStatus")) | |
682 | return bus_set_transient_exit_status(u, name, &s->success_status, message, flags, error); | |
683 | ||
be6bca47 | 684 | ci = service_exec_command_from_string(name); |
0a27d86a ZJS |
685 | if (ci < 0) |
686 | ci = service_exec_ex_command_from_string(name); | |
be6bca47 | 687 | if (ci >= 0) |
d2f05617 YW |
688 | return bus_set_transient_exec_command(u, name, &s->exec_command[ci], message, flags, error); |
689 | ||
690 | if (streq(name, "StandardInputFileDescriptor")) | |
691 | return bus_set_transient_std_fd(u, name, &s->stdin_fd, &s->exec_context.stdio_as_fds, message, flags, error); | |
692 | ||
693 | if (streq(name, "StandardOutputFileDescriptor")) | |
694 | return bus_set_transient_std_fd(u, name, &s->stdout_fd, &s->exec_context.stdio_as_fds, message, flags, error); | |
9efb9df9 | 695 | |
d2f05617 YW |
696 | if (streq(name, "StandardErrorFileDescriptor")) |
697 | return bus_set_transient_std_fd(u, name, &s->stderr_fd, &s->exec_context.stdio_as_fds, message, flags, error); | |
c2756a68 | 698 | |
cd48e23f RP |
699 | if (streq(name, "OpenFile")) { |
700 | const char *path, *fdname; | |
701 | uint64_t offlags; | |
702 | ||
703 | r = sd_bus_message_enter_container(message, 'a', "(sst)"); | |
704 | if (r < 0) | |
705 | return r; | |
706 | ||
707 | while ((r = sd_bus_message_read(message, "(sst)", &path, &fdname, &offlags)) > 0) { | |
708 | _cleanup_(open_file_freep) OpenFile *of = NULL; | |
709 | _cleanup_free_ char *ofs = NULL; | |
710 | ||
711 | of = new(OpenFile, 1); | |
712 | if (!of) | |
713 | return -ENOMEM; | |
714 | ||
715 | *of = (OpenFile) { | |
716 | .path = strdup(path), | |
717 | .fdname = strdup(fdname), | |
718 | .flags = offlags, | |
719 | }; | |
720 | ||
721 | if (!of->path || !of->fdname) | |
722 | return -ENOMEM; | |
723 | ||
724 | r = open_file_validate(of); | |
725 | if (r < 0) | |
726 | return r; | |
727 | ||
728 | if (UNIT_WRITE_FLAGS_NOOP(flags)) | |
729 | continue; | |
730 | ||
731 | r = open_file_to_string(of, &ofs); | |
732 | if (r < 0) | |
733 | return sd_bus_error_set_errnof( | |
734 | error, r, "Failed to convert OpenFile= value to string: %m"); | |
735 | ||
736 | LIST_APPEND(open_files, s->open_files, TAKE_PTR(of)); | |
737 | unit_write_settingf(u, flags | UNIT_ESCAPE_SPECIFIERS, name, "OpenFile=%s", ofs); | |
738 | } | |
739 | if (r < 0) | |
740 | return r; | |
741 | ||
742 | r = sd_bus_message_exit_container(message); | |
743 | if (r < 0) | |
744 | return r; | |
745 | ||
746 | return 1; | |
747 | } | |
748 | ||
3bd28bf7 LP |
749 | if (streq(name, "ReloadSignal")) |
750 | return bus_set_transient_reload_signal(u, name, &s->reload_signal, message, flags, error); | |
751 | ||
3543456f | 752 | if (streq(name, "ExtraFileDescriptors")) { |
3543456f RW |
753 | r = sd_bus_message_enter_container(message, 'a', "(hs)"); |
754 | if (r < 0) | |
755 | return r; | |
756 | ||
757 | for (;;) { | |
32af4dd8 MY |
758 | const char *fdname; |
759 | int fd; | |
3543456f RW |
760 | |
761 | r = sd_bus_message_read(message, "(hs)", &fd, &fdname); | |
762 | if (r < 0) | |
763 | return r; | |
764 | if (r == 0) | |
765 | break; | |
766 | ||
767 | /* Disallow empty string for ExtraFileDescriptors. | |
768 | * Unlike OpenFile, StandardInput and friends, there isn't a good sane | |
769 | * default for an arbitrary FD. */ | |
32af4dd8 MY |
770 | if (isempty(fdname) || !fdname_is_valid(fdname)) |
771 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid extra fd name: %s", fdname); | |
772 | ||
773 | if (s->n_extra_fds >= NOTIFY_FD_MAX) | |
774 | return sd_bus_error_set(error, SD_BUS_ERROR_LIMITS_EXCEEDED, "Too many extra fds sent"); | |
3543456f RW |
775 | |
776 | if (UNIT_WRITE_FLAGS_NOOP(flags)) | |
777 | continue; | |
778 | ||
32af4dd8 | 779 | if (!GREEDY_REALLOC(s->extra_fds, s->n_extra_fds + 1)) |
3543456f RW |
780 | return -ENOMEM; |
781 | ||
32af4dd8 MY |
782 | _cleanup_free_ char *fdname_dup = strdup(fdname); |
783 | if (!fdname_dup) | |
3543456f RW |
784 | return -ENOMEM; |
785 | ||
32af4dd8 MY |
786 | _cleanup_close_ int fd_dup = fcntl(fd, F_DUPFD_CLOEXEC, 3); |
787 | if (fd_dup < 0) | |
3543456f RW |
788 | return -errno; |
789 | ||
32af4dd8 MY |
790 | s->extra_fds[s->n_extra_fds++] = (ServiceExtraFD) { |
791 | .fd = TAKE_FD(fd_dup), | |
792 | .fdname = TAKE_PTR(fdname_dup), | |
793 | }; | |
3543456f RW |
794 | } |
795 | ||
796 | r = sd_bus_message_exit_container(message); | |
797 | if (r < 0) | |
798 | return r; | |
799 | ||
800 | return 1; | |
801 | } | |
802 | ||
c2756a68 LP |
803 | return 0; |
804 | } | |
805 | ||
74c964d3 LP |
806 | int bus_service_set_property( |
807 | Unit *u, | |
808 | const char *name, | |
718db961 | 809 | sd_bus_message *message, |
2e59b241 | 810 | UnitWriteFlags flags, |
718db961 | 811 | sd_bus_error *error) { |
74c964d3 LP |
812 | |
813 | Service *s = SERVICE(u); | |
814 | int r; | |
815 | ||
718db961 | 816 | assert(s); |
74c964d3 | 817 | assert(name); |
718db961 | 818 | assert(message); |
74c964d3 | 819 | |
2e59b241 | 820 | r = bus_cgroup_set_property(u, &s->cgroup_context, name, message, flags, error); |
74c964d3 LP |
821 | if (r != 0) |
822 | return r; | |
823 | ||
c2756a68 | 824 | if (u->transient && u->load_state == UNIT_STUB) { |
4a055e5a | 825 | /* This is a transient unit, let's allow a little more */ |
c2756a68 | 826 | |
2e59b241 | 827 | r = bus_service_set_transient_property(s, name, message, flags, error); |
c2756a68 LP |
828 | if (r != 0) |
829 | return r; | |
a6c0353b | 830 | |
2e59b241 | 831 | r = bus_exec_context_set_transient_property(u, &s->exec_context, name, message, flags, error); |
c7040b5d LP |
832 | if (r != 0) |
833 | return r; | |
834 | ||
2e59b241 | 835 | r = bus_kill_context_set_transient_property(u, &s->kill_context, name, message, flags, error); |
a6c0353b LP |
836 | if (r != 0) |
837 | return r; | |
c2756a68 LP |
838 | } |
839 | ||
74c964d3 LP |
840 | return 0; |
841 | } | |
842 | ||
843 | int bus_service_commit_properties(Unit *u) { | |
844 | assert(u); | |
845 | ||
8d178f70 | 846 | (void) unit_realize_cgroup(u); |
bc432dc7 | 847 | |
74c964d3 LP |
848 | return 0; |
849 | } |