]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
4139c1b2 | 2 | |
227b8a76 | 3 | #include <sys/mount.h> |
82c121a4 | 4 | #include <sys/prctl.h> |
4139c1b2 | 5 | |
349cc4a5 | 6 | #if HAVE_SECCOMP |
57183d11 LP |
7 | #include <seccomp.h> |
8 | #endif | |
9 | ||
3ffd4af2 | 10 | #include "af-list.h" |
b5efdb8a | 11 | #include "alloc-util.h" |
718db961 | 12 | #include "bus-util.h" |
cffaed83 | 13 | #include "cap-list.h" |
d3070fbd | 14 | #include "capability-util.h" |
501941aa | 15 | #include "cpu-set-util.h" |
3ffd4af2 | 16 | #include "dbus-execute.h" |
7e2a3fcc | 17 | #include "dbus-util.h" |
c7040b5d | 18 | #include "env-util.h" |
cffaed83 | 19 | #include "errno-list.h" |
2e59b241 | 20 | #include "escape.h" |
3ffd4af2 LP |
21 | #include "execute.h" |
22 | #include "fd-util.h" | |
23 | #include "fileio.h" | |
08f3be7a | 24 | #include "hexdecoct.h" |
d3070fbd | 25 | #include "io-util.h" |
3ffd4af2 | 26 | #include "ioprio.h" |
d3070fbd | 27 | #include "journal-util.h" |
049af8ad | 28 | #include "mountpoint-util.h" |
417116f2 | 29 | #include "namespace.h" |
6bedfcbb | 30 | #include "parse-util.h" |
9b15b784 | 31 | #include "path-util.h" |
7b3e062c | 32 | #include "process-util.h" |
78f22b97 | 33 | #include "rlimit-util.h" |
349cc4a5 | 34 | #if HAVE_SECCOMP |
57183d11 LP |
35 | #include "seccomp-util.h" |
36 | #endif | |
cffaed83 | 37 | #include "securebits-util.h" |
2e59b241 | 38 | #include "specifier.h" |
6bedfcbb | 39 | #include "strv.h" |
7ccbd1ae | 40 | #include "syslog-util.h" |
f900f582 | 41 | #include "unit-printf.h" |
6f3e7985 | 42 | #include "user-util.h" |
6bedfcbb | 43 | #include "utf8.h" |
57183d11 | 44 | |
718db961 | 45 | BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput); |
718db961 | 46 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input, exec_input, ExecInput); |
023a4f67 | 47 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode); |
53f47dfc | 48 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode, exec_preserve_mode, ExecPreserveMode); |
b1edf445 | 49 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode); |
73b84e92 YW |
50 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home, protect_home, ProtectHome); |
51 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system, protect_system, ProtectSystem); | |
491eecb3 | 52 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality, personality, unsigned long); |
019b34ca YW |
53 | static BUS_DEFINE_PROPERTY_GET(property_get_ioprio, "i", ExecContext, exec_context_get_effective_ioprio); |
54 | static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class, "i", ExecContext, exec_context_get_effective_ioprio, IOPRIO_PRIO_CLASS); | |
55 | static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority, "i", ExecContext, exec_context_get_effective_ioprio, IOPRIO_PRIO_DATA); | |
92c23c5a YW |
56 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string, "s", NULL); |
57 | static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level, "i", int, LOG_PRI); | |
58 | static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility, "i", int, LOG_FAC); | |
e2b2fb7f MS |
59 | static BUS_DEFINE_PROPERTY_GET(property_get_cpu_affinity_from_numa, "b", ExecContext, exec_context_get_cpu_affinity_from_numa); |
60 | ||
417116f2 | 61 | |
718db961 LP |
62 | static int property_get_environment_files( |
63 | sd_bus *bus, | |
64 | const char *path, | |
65 | const char *interface, | |
66 | const char *property, | |
67 | sd_bus_message *reply, | |
ebcf1f97 LP |
68 | void *userdata, |
69 | sd_bus_error *error) { | |
8c7be95e | 70 | |
718db961 LP |
71 | ExecContext *c = userdata; |
72 | char **j; | |
73 | int r; | |
8c7be95e | 74 | |
718db961 LP |
75 | assert(bus); |
76 | assert(reply); | |
77 | assert(c); | |
78 | ||
79 | r = sd_bus_message_open_container(reply, 'a', "(sb)"); | |
80 | if (r < 0) | |
81 | return r; | |
8c7be95e | 82 | |
718db961 LP |
83 | STRV_FOREACH(j, c->environment_files) { |
84 | const char *fn = *j; | |
8c7be95e | 85 | |
718db961 LP |
86 | r = sd_bus_message_append(reply, "(sb)", fn[0] == '-' ? fn + 1 : fn, fn[0] == '-'); |
87 | if (r < 0) | |
88 | return r; | |
8c7be95e LP |
89 | } |
90 | ||
718db961 LP |
91 | return sd_bus_message_close_container(reply); |
92 | } | |
93 | ||
718db961 LP |
94 | static int property_get_oom_score_adjust( |
95 | sd_bus *bus, | |
96 | const char *path, | |
97 | const char *interface, | |
98 | const char *property, | |
99 | sd_bus_message *reply, | |
ebcf1f97 LP |
100 | void *userdata, |
101 | sd_bus_error *error) { | |
718db961 | 102 | |
718db961 | 103 | ExecContext *c = userdata; |
82c121a4 | 104 | int32_t n; |
b94fb74b | 105 | int r; |
82c121a4 | 106 | |
718db961 LP |
107 | assert(bus); |
108 | assert(reply); | |
82c121a4 LP |
109 | assert(c); |
110 | ||
dd6c17b1 LP |
111 | if (c->oom_score_adjust_set) |
112 | n = c->oom_score_adjust; | |
82c121a4 | 113 | else { |
68eda4bd | 114 | _cleanup_free_ char *t = NULL; |
82c121a4 LP |
115 | |
116 | n = 0; | |
b94fb74b ZJS |
117 | r = read_one_line_file("/proc/self/oom_score_adj", &t); |
118 | if (r < 0) | |
119 | log_debug_errno(r, "Failed to read /proc/self/oom_score_adj, ignoring: %m"); | |
120 | else { | |
121 | r = safe_atoi32(t, &n); | |
122 | if (r < 0) | |
123 | log_debug_errno(r, "Failed to parse \"%s\" from /proc/self/oom_score_adj, ignoring: %m", t); | |
124 | } | |
82c121a4 LP |
125 | } |
126 | ||
718db961 | 127 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
128 | } |
129 | ||
ad21e542 ZJS |
130 | static int property_get_coredump_filter( |
131 | sd_bus *bus, | |
132 | const char *path, | |
133 | const char *interface, | |
134 | const char *property, | |
135 | sd_bus_message *reply, | |
136 | void *userdata, | |
137 | sd_bus_error *error) { | |
138 | ||
139 | ExecContext *c = userdata; | |
140 | uint64_t n; | |
141 | int r; | |
142 | ||
143 | assert(bus); | |
144 | assert(reply); | |
145 | assert(c); | |
146 | ||
147 | if (c->coredump_filter_set) | |
148 | n = c->coredump_filter; | |
149 | else { | |
150 | _cleanup_free_ char *t = NULL; | |
151 | ||
152 | n = COREDUMP_FILTER_MASK_DEFAULT; | |
153 | r = read_one_line_file("/proc/self/coredump_filter", &t); | |
154 | if (r < 0) | |
155 | log_debug_errno(r, "Failed to read /proc/self/coredump_filter, ignoring: %m"); | |
156 | else { | |
157 | r = safe_atoux64(t, &n); | |
158 | if (r < 0) | |
159 | log_debug_errno(r, "Failed to parse \"%s\" from /proc/self/coredump_filter, ignoring: %m", t); | |
160 | } | |
161 | } | |
162 | ||
163 | return sd_bus_message_append(reply, "t", n); | |
164 | } | |
165 | ||
718db961 LP |
166 | static int property_get_nice( |
167 | sd_bus *bus, | |
168 | const char *path, | |
169 | const char *interface, | |
170 | const char *property, | |
171 | sd_bus_message *reply, | |
ebcf1f97 LP |
172 | void *userdata, |
173 | sd_bus_error *error) { | |
718db961 | 174 | |
718db961 | 175 | ExecContext *c = userdata; |
82c121a4 LP |
176 | int32_t n; |
177 | ||
718db961 LP |
178 | assert(bus); |
179 | assert(reply); | |
82c121a4 LP |
180 | assert(c); |
181 | ||
182 | if (c->nice_set) | |
183 | n = c->nice; | |
718db961 LP |
184 | else { |
185 | errno = 0; | |
82c121a4 | 186 | n = getpriority(PRIO_PROCESS, 0); |
b3267152 | 187 | if (errno > 0) |
718db961 LP |
188 | n = 0; |
189 | } | |
82c121a4 | 190 | |
718db961 | 191 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
192 | } |
193 | ||
718db961 LP |
194 | static int property_get_cpu_sched_policy( |
195 | sd_bus *bus, | |
196 | const char *path, | |
197 | const char *interface, | |
198 | const char *property, | |
199 | sd_bus_message *reply, | |
ebcf1f97 LP |
200 | void *userdata, |
201 | sd_bus_error *error) { | |
718db961 LP |
202 | |
203 | ExecContext *c = userdata; | |
82c121a4 LP |
204 | int32_t n; |
205 | ||
718db961 LP |
206 | assert(bus); |
207 | assert(reply); | |
82c121a4 LP |
208 | assert(c); |
209 | ||
210 | if (c->cpu_sched_set) | |
211 | n = c->cpu_sched_policy; | |
718db961 | 212 | else { |
82c121a4 | 213 | n = sched_getscheduler(0); |
718db961 LP |
214 | if (n < 0) |
215 | n = SCHED_OTHER; | |
216 | } | |
82c121a4 | 217 | |
718db961 | 218 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
219 | } |
220 | ||
718db961 LP |
221 | static int property_get_cpu_sched_priority( |
222 | sd_bus *bus, | |
223 | const char *path, | |
224 | const char *interface, | |
225 | const char *property, | |
226 | sd_bus_message *reply, | |
ebcf1f97 LP |
227 | void *userdata, |
228 | sd_bus_error *error) { | |
718db961 LP |
229 | |
230 | ExecContext *c = userdata; | |
82c121a4 LP |
231 | int32_t n; |
232 | ||
718db961 LP |
233 | assert(bus); |
234 | assert(reply); | |
82c121a4 LP |
235 | assert(c); |
236 | ||
237 | if (c->cpu_sched_set) | |
238 | n = c->cpu_sched_priority; | |
239 | else { | |
b92bea5d | 240 | struct sched_param p = {}; |
82c121a4 | 241 | |
82c121a4 LP |
242 | if (sched_getparam(0, &p) >= 0) |
243 | n = p.sched_priority; | |
e62d8c39 ZJS |
244 | else |
245 | n = 0; | |
82c121a4 LP |
246 | } |
247 | ||
718db961 | 248 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
249 | } |
250 | ||
718db961 LP |
251 | static int property_get_cpu_affinity( |
252 | sd_bus *bus, | |
253 | const char *path, | |
254 | const char *interface, | |
255 | const char *property, | |
256 | sd_bus_message *reply, | |
ebcf1f97 LP |
257 | void *userdata, |
258 | sd_bus_error *error) { | |
82c121a4 | 259 | |
718db961 | 260 | ExecContext *c = userdata; |
e2b2fb7f | 261 | _cleanup_(cpu_set_reset) CPUSet s = {}; |
75e40119 MS |
262 | _cleanup_free_ uint8_t *array = NULL; |
263 | size_t allocated; | |
82c121a4 | 264 | |
718db961 LP |
265 | assert(bus); |
266 | assert(reply); | |
267 | assert(c); | |
82c121a4 | 268 | |
e2b2fb7f MS |
269 | if (c->cpu_affinity_from_numa) { |
270 | int r; | |
271 | ||
272 | r = numa_to_cpu_set(&c->numa_policy, &s); | |
273 | if (r < 0) | |
274 | return r; | |
275 | } | |
276 | ||
277 | (void) cpu_set_to_dbus(c->cpu_affinity_from_numa ? &s : &c->cpu_set, &array, &allocated); | |
278 | ||
75e40119 | 279 | return sd_bus_message_append_array(reply, 'y', array, allocated); |
82c121a4 LP |
280 | } |
281 | ||
b070c7c0 MS |
282 | static int property_get_numa_mask( |
283 | sd_bus *bus, | |
284 | const char *path, | |
285 | const char *interface, | |
286 | const char *property, | |
287 | sd_bus_message *reply, | |
288 | void *userdata, | |
289 | sd_bus_error *error) { | |
290 | ||
291 | ExecContext *c = userdata; | |
292 | _cleanup_free_ uint8_t *array = NULL; | |
293 | size_t allocated; | |
294 | ||
295 | assert(bus); | |
296 | assert(reply); | |
297 | assert(c); | |
298 | ||
299 | (void) cpu_set_to_dbus(&c->numa_policy.nodes, &array, &allocated); | |
300 | ||
301 | return sd_bus_message_append_array(reply, 'y', array, allocated); | |
302 | } | |
303 | ||
304 | static int property_get_numa_policy( | |
305 | sd_bus *bus, | |
306 | const char *path, | |
307 | const char *interface, | |
308 | const char *property, | |
309 | sd_bus_message *reply, | |
310 | void *userdata, | |
311 | sd_bus_error *error) { | |
312 | ExecContext *c = userdata; | |
313 | int32_t policy; | |
314 | ||
315 | assert(bus); | |
316 | assert(reply); | |
317 | assert(c); | |
318 | ||
319 | policy = numa_policy_get_type(&c->numa_policy); | |
320 | ||
321 | return sd_bus_message_append_basic(reply, 'i', &policy); | |
322 | } | |
323 | ||
718db961 LP |
324 | static int property_get_timer_slack_nsec( |
325 | sd_bus *bus, | |
326 | const char *path, | |
327 | const char *interface, | |
328 | const char *property, | |
329 | sd_bus_message *reply, | |
ebcf1f97 LP |
330 | void *userdata, |
331 | sd_bus_error *error) { | |
718db961 LP |
332 | |
333 | ExecContext *c = userdata; | |
82c121a4 LP |
334 | uint64_t u; |
335 | ||
718db961 LP |
336 | assert(bus); |
337 | assert(reply); | |
82c121a4 LP |
338 | assert(c); |
339 | ||
3a43da28 | 340 | if (c->timer_slack_nsec != NSEC_INFINITY) |
03fae018 | 341 | u = (uint64_t) c->timer_slack_nsec; |
82c121a4 LP |
342 | else |
343 | u = (uint64_t) prctl(PR_GET_TIMERSLACK); | |
344 | ||
718db961 | 345 | return sd_bus_message_append(reply, "t", u); |
82c121a4 LP |
346 | } |
347 | ||
718db961 LP |
348 | static int property_get_syscall_filter( |
349 | sd_bus *bus, | |
350 | const char *path, | |
351 | const char *interface, | |
352 | const char *property, | |
353 | sd_bus_message *reply, | |
ebcf1f97 LP |
354 | void *userdata, |
355 | sd_bus_error *error) { | |
82c121a4 | 356 | |
17df7223 LP |
357 | ExecContext *c = userdata; |
358 | _cleanup_strv_free_ char **l = NULL; | |
57183d11 LP |
359 | int r; |
360 | ||
349cc4a5 | 361 | #if HAVE_SECCOMP |
17df7223 | 362 | Iterator i; |
8cfa775f | 363 | void *id, *val; |
351a19b1 | 364 | #endif |
17df7223 LP |
365 | |
366 | assert(bus); | |
367 | assert(reply); | |
368 | assert(c); | |
369 | ||
57183d11 LP |
370 | r = sd_bus_message_open_container(reply, 'r', "bas"); |
371 | if (r < 0) | |
372 | return r; | |
373 | ||
374 | r = sd_bus_message_append(reply, "b", c->syscall_whitelist); | |
375 | if (r < 0) | |
376 | return r; | |
377 | ||
349cc4a5 | 378 | #if HAVE_SECCOMP |
8cfa775f YW |
379 | HASHMAP_FOREACH_KEY(val, id, c->syscall_filter, i) { |
380 | _cleanup_free_ char *name = NULL; | |
381 | const char *e = NULL; | |
382 | char *s; | |
383 | int num = PTR_TO_INT(val); | |
17df7223 LP |
384 | |
385 | name = seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE, PTR_TO_INT(id) - 1); | |
386 | if (!name) | |
387 | continue; | |
388 | ||
8cfa775f YW |
389 | if (num >= 0) { |
390 | e = errno_to_name(num); | |
391 | if (e) { | |
392 | s = strjoin(name, ":", e); | |
393 | if (!s) | |
394 | return -ENOMEM; | |
395 | } else { | |
396 | r = asprintf(&s, "%s:%d", name, num); | |
397 | if (r < 0) | |
398 | return -ENOMEM; | |
399 | } | |
ae2a15bc LP |
400 | } else |
401 | s = TAKE_PTR(name); | |
8cfa775f YW |
402 | |
403 | r = strv_consume(&l, s); | |
6e18964d ZJS |
404 | if (r < 0) |
405 | return r; | |
17df7223 | 406 | } |
351a19b1 | 407 | #endif |
17df7223 LP |
408 | |
409 | strv_sort(l); | |
410 | ||
57183d11 LP |
411 | r = sd_bus_message_append_strv(reply, l); |
412 | if (r < 0) | |
413 | return r; | |
17df7223 | 414 | |
57183d11 LP |
415 | return sd_bus_message_close_container(reply); |
416 | } | |
17df7223 | 417 | |
57183d11 LP |
418 | static int property_get_syscall_archs( |
419 | sd_bus *bus, | |
420 | const char *path, | |
421 | const char *interface, | |
422 | const char *property, | |
423 | sd_bus_message *reply, | |
424 | void *userdata, | |
425 | sd_bus_error *error) { | |
426 | ||
427 | ExecContext *c = userdata; | |
428 | _cleanup_strv_free_ char **l = NULL; | |
429 | int r; | |
430 | ||
349cc4a5 | 431 | #if HAVE_SECCOMP |
57183d11 LP |
432 | Iterator i; |
433 | void *id; | |
434 | #endif | |
435 | ||
436 | assert(bus); | |
437 | assert(reply); | |
438 | assert(c); | |
17df7223 | 439 | |
349cc4a5 | 440 | #if HAVE_SECCOMP |
57183d11 LP |
441 | SET_FOREACH(id, c->syscall_archs, i) { |
442 | const char *name; | |
443 | ||
444 | name = seccomp_arch_to_string(PTR_TO_UINT32(id) - 1); | |
445 | if (!name) | |
446 | continue; | |
447 | ||
448 | r = strv_extend(&l, name); | |
449 | if (r < 0) | |
450 | return -ENOMEM; | |
17df7223 | 451 | } |
57183d11 LP |
452 | #endif |
453 | ||
454 | strv_sort(l); | |
455 | ||
456 | r = sd_bus_message_append_strv(reply, l); | |
457 | if (r < 0) | |
458 | return r; | |
17df7223 | 459 | |
57183d11 | 460 | return 0; |
17df7223 LP |
461 | } |
462 | ||
5f8640fb LP |
463 | static int property_get_selinux_context( |
464 | sd_bus *bus, | |
465 | const char *path, | |
466 | const char *interface, | |
467 | const char *property, | |
468 | sd_bus_message *reply, | |
469 | void *userdata, | |
470 | sd_bus_error *error) { | |
471 | ||
472 | ExecContext *c = userdata; | |
473 | ||
474 | assert(bus); | |
475 | assert(reply); | |
476 | assert(c); | |
477 | ||
478 | return sd_bus_message_append(reply, "(bs)", c->selinux_context_ignore, c->selinux_context); | |
479 | } | |
480 | ||
eef65bf3 MS |
481 | static int property_get_apparmor_profile( |
482 | sd_bus *bus, | |
483 | const char *path, | |
484 | const char *interface, | |
485 | const char *property, | |
486 | sd_bus_message *reply, | |
487 | void *userdata, | |
488 | sd_bus_error *error) { | |
489 | ||
490 | ExecContext *c = userdata; | |
491 | ||
492 | assert(bus); | |
493 | assert(reply); | |
494 | assert(c); | |
495 | ||
496 | return sd_bus_message_append(reply, "(bs)", c->apparmor_profile_ignore, c->apparmor_profile); | |
497 | } | |
498 | ||
2ca620c4 WC |
499 | static int property_get_smack_process_label( |
500 | sd_bus *bus, | |
501 | const char *path, | |
502 | const char *interface, | |
503 | const char *property, | |
504 | sd_bus_message *reply, | |
505 | void *userdata, | |
506 | sd_bus_error *error) { | |
507 | ||
508 | ExecContext *c = userdata; | |
509 | ||
510 | assert(bus); | |
511 | assert(reply); | |
512 | assert(c); | |
513 | ||
514 | return sd_bus_message_append(reply, "(bs)", c->smack_process_label_ignore, c->smack_process_label); | |
515 | } | |
516 | ||
4298d0b5 LP |
517 | static int property_get_address_families( |
518 | sd_bus *bus, | |
519 | const char *path, | |
520 | const char *interface, | |
521 | const char *property, | |
522 | sd_bus_message *reply, | |
523 | void *userdata, | |
524 | sd_bus_error *error) { | |
525 | ||
526 | ExecContext *c = userdata; | |
527 | _cleanup_strv_free_ char **l = NULL; | |
528 | Iterator i; | |
529 | void *af; | |
530 | int r; | |
531 | ||
532 | assert(bus); | |
533 | assert(reply); | |
534 | assert(c); | |
535 | ||
536 | r = sd_bus_message_open_container(reply, 'r', "bas"); | |
537 | if (r < 0) | |
538 | return r; | |
539 | ||
540 | r = sd_bus_message_append(reply, "b", c->address_families_whitelist); | |
541 | if (r < 0) | |
542 | return r; | |
543 | ||
544 | SET_FOREACH(af, c->address_families, i) { | |
545 | const char *name; | |
546 | ||
547 | name = af_to_name(PTR_TO_INT(af)); | |
548 | if (!name) | |
549 | continue; | |
550 | ||
551 | r = strv_extend(&l, name); | |
552 | if (r < 0) | |
553 | return -ENOMEM; | |
554 | } | |
555 | ||
556 | strv_sort(l); | |
557 | ||
558 | r = sd_bus_message_append_strv(reply, l); | |
559 | if (r < 0) | |
560 | return r; | |
561 | ||
562 | return sd_bus_message_close_container(reply); | |
563 | } | |
564 | ||
5f5d8eab LP |
565 | static int property_get_working_directory( |
566 | sd_bus *bus, | |
567 | const char *path, | |
568 | const char *interface, | |
569 | const char *property, | |
570 | sd_bus_message *reply, | |
571 | void *userdata, | |
572 | sd_bus_error *error) { | |
573 | ||
574 | ExecContext *c = userdata; | |
575 | const char *wd; | |
576 | ||
577 | assert(bus); | |
578 | assert(reply); | |
579 | assert(c); | |
580 | ||
581 | if (c->working_directory_home) | |
582 | wd = "~"; | |
583 | else | |
584 | wd = c->working_directory; | |
585 | ||
586 | if (c->working_directory_missing_ok) | |
587 | wd = strjoina("!", wd); | |
588 | ||
589 | return sd_bus_message_append(reply, "s", wd); | |
590 | } | |
591 | ||
5073ff6b | 592 | static int property_get_stdio_fdname( |
52c239d7 LB |
593 | sd_bus *bus, |
594 | const char *path, | |
595 | const char *interface, | |
596 | const char *property, | |
597 | sd_bus_message *reply, | |
598 | void *userdata, | |
599 | sd_bus_error *error) { | |
600 | ||
601 | ExecContext *c = userdata; | |
5073ff6b | 602 | int fileno; |
52c239d7 LB |
603 | |
604 | assert(bus); | |
605 | assert(c); | |
606 | assert(property); | |
607 | assert(reply); | |
608 | ||
5073ff6b LP |
609 | if (streq(property, "StandardInputFileDescriptorName")) |
610 | fileno = STDIN_FILENO; | |
611 | else if (streq(property, "StandardOutputFileDescriptorName")) | |
612 | fileno = STDOUT_FILENO; | |
613 | else { | |
614 | assert(streq(property, "StandardErrorFileDescriptorName")); | |
615 | fileno = STDERR_FILENO; | |
616 | } | |
52c239d7 | 617 | |
5073ff6b | 618 | return sd_bus_message_append(reply, "s", exec_context_fdname(c, fileno)); |
52c239d7 LB |
619 | } |
620 | ||
08f3be7a | 621 | static int property_get_input_data( |
52c239d7 LB |
622 | sd_bus *bus, |
623 | const char *path, | |
624 | const char *interface, | |
625 | const char *property, | |
626 | sd_bus_message *reply, | |
627 | void *userdata, | |
628 | sd_bus_error *error) { | |
629 | ||
630 | ExecContext *c = userdata; | |
52c239d7 LB |
631 | |
632 | assert(bus); | |
633 | assert(c); | |
634 | assert(property); | |
635 | assert(reply); | |
636 | ||
08f3be7a | 637 | return sd_bus_message_append_array(reply, 'y', c->stdin_data, c->stdin_data_size); |
52c239d7 LB |
638 | } |
639 | ||
d2d6c096 LP |
640 | static int property_get_bind_paths( |
641 | sd_bus *bus, | |
642 | const char *path, | |
643 | const char *interface, | |
644 | const char *property, | |
645 | sd_bus_message *reply, | |
646 | void *userdata, | |
647 | sd_bus_error *error) { | |
648 | ||
649 | ExecContext *c = userdata; | |
650 | unsigned i; | |
651 | bool ro; | |
652 | int r; | |
653 | ||
654 | assert(bus); | |
655 | assert(c); | |
656 | assert(property); | |
657 | assert(reply); | |
658 | ||
5d904a6a | 659 | ro = strstr(property, "ReadOnly"); |
d2d6c096 LP |
660 | |
661 | r = sd_bus_message_open_container(reply, 'a', "(ssbt)"); | |
662 | if (r < 0) | |
663 | return r; | |
664 | ||
665 | for (i = 0; i < c->n_bind_mounts; i++) { | |
666 | ||
667 | if (ro != c->bind_mounts[i].read_only) | |
668 | continue; | |
669 | ||
670 | r = sd_bus_message_append( | |
671 | reply, "(ssbt)", | |
672 | c->bind_mounts[i].source, | |
673 | c->bind_mounts[i].destination, | |
674 | c->bind_mounts[i].ignore_enoent, | |
c9b06108 | 675 | c->bind_mounts[i].recursive ? (uint64_t) MS_REC : (uint64_t) 0); |
d2d6c096 LP |
676 | if (r < 0) |
677 | return r; | |
678 | } | |
679 | ||
680 | return sd_bus_message_close_container(reply); | |
681 | } | |
682 | ||
784ad252 YW |
683 | static int property_get_temporary_filesystems( |
684 | sd_bus *bus, | |
685 | const char *path, | |
686 | const char *interface, | |
687 | const char *property, | |
688 | sd_bus_message *reply, | |
689 | void *userdata, | |
690 | sd_bus_error *error) { | |
691 | ||
692 | ExecContext *c = userdata; | |
693 | unsigned i; | |
694 | int r; | |
695 | ||
696 | assert(bus); | |
697 | assert(c); | |
698 | assert(property); | |
699 | assert(reply); | |
700 | ||
701 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); | |
702 | if (r < 0) | |
703 | return r; | |
704 | ||
705 | for (i = 0; i < c->n_temporary_filesystems; i++) { | |
706 | TemporaryFileSystem *t = c->temporary_filesystems + i; | |
707 | ||
708 | r = sd_bus_message_append( | |
709 | reply, "(ss)", | |
710 | t->path, | |
711 | t->options); | |
712 | if (r < 0) | |
713 | return r; | |
714 | } | |
715 | ||
716 | return sd_bus_message_close_container(reply); | |
717 | } | |
718 | ||
d3070fbd LP |
719 | static int property_get_log_extra_fields( |
720 | sd_bus *bus, | |
721 | const char *path, | |
722 | const char *interface, | |
723 | const char *property, | |
724 | sd_bus_message *reply, | |
725 | void *userdata, | |
726 | sd_bus_error *error) { | |
727 | ||
728 | ExecContext *c = userdata; | |
729 | size_t i; | |
730 | int r; | |
731 | ||
732 | assert(bus); | |
733 | assert(c); | |
734 | assert(property); | |
735 | assert(reply); | |
736 | ||
737 | r = sd_bus_message_open_container(reply, 'a', "ay"); | |
738 | if (r < 0) | |
739 | return r; | |
740 | ||
741 | for (i = 0; i < c->n_log_extra_fields; i++) { | |
742 | r = sd_bus_message_append_array(reply, 'y', c->log_extra_fields[i].iov_base, c->log_extra_fields[i].iov_len); | |
743 | if (r < 0) | |
744 | return r; | |
745 | } | |
746 | ||
747 | return sd_bus_message_close_container(reply); | |
748 | } | |
749 | ||
718db961 LP |
750 | const sd_bus_vtable bus_exec_vtable[] = { |
751 | SD_BUS_VTABLE_START(0), | |
556089dc LP |
752 | SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST), |
753 | SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
b4c14404 | 754 | SD_BUS_PROPERTY("PassEnvironment", "as", NULL, offsetof(ExecContext, pass_environment), SD_BUS_VTABLE_PROPERTY_CONST), |
00819cc1 | 755 | SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL, offsetof(ExecContext, unset_environment), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 756 | SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode, offsetof(ExecContext, umask), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 757 | SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 758 | SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 759 | SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 760 | SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 761 | SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 762 | SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 763 | SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 764 | SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 765 | SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 766 | SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 767 | SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 768 | SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 769 | SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 770 | SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 771 | SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 772 | SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 773 | SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 774 | SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 775 | SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 776 | SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 777 | SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 778 | SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 779 | SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 780 | SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 781 | SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 782 | SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 783 | SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 784 | SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 785 | SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 786 | SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 787 | SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 788 | SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
5f5d8eab | 789 | SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 790 | SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(ExecContext, root_directory), SD_BUS_VTABLE_PROPERTY_CONST), |
915e6d16 | 791 | SD_BUS_PROPERTY("RootImage", "s", NULL, offsetof(ExecContext, root_image), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 792 | SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
ad21e542 | 793 | SD_BUS_PROPERTY("CoredumpFilter", "t", property_get_coredump_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 794 | SD_BUS_PROPERTY("Nice", "i", property_get_nice, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
7f452159 LP |
795 | SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
796 | SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
797 | SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
798 | SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
799 | SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
e2b2fb7f | 800 | SD_BUS_PROPERTY("CPUAffinityFromNUMA", "b", property_get_cpu_affinity_from_numa, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
b070c7c0 MS |
801 | SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
802 | SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
803 | SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
804 | SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool, offsetof(ExecContext, cpu_sched_reset_on_fork), SD_BUS_VTABLE_PROPERTY_CONST), | |
805 | SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool, offsetof(ExecContext, non_blocking), SD_BUS_VTABLE_PROPERTY_CONST), | |
806 | SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input, offsetof(ExecContext, std_input), SD_BUS_VTABLE_PROPERTY_CONST), | |
5073ff6b | 807 | SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
08f3be7a | 808 | SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 809 | SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output, offsetof(ExecContext, std_output), SD_BUS_VTABLE_PROPERTY_CONST), |
5073ff6b | 810 | SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 811 | SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output, offsetof(ExecContext, std_error), SD_BUS_VTABLE_PROPERTY_CONST), |
5073ff6b | 812 | SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
813 | SD_BUS_PROPERTY("TTYPath", "s", NULL, offsetof(ExecContext, tty_path), SD_BUS_VTABLE_PROPERTY_CONST), |
814 | SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool, offsetof(ExecContext, tty_reset), SD_BUS_VTABLE_PROPERTY_CONST), | |
815 | SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool, offsetof(ExecContext, tty_vhangup), SD_BUS_VTABLE_PROPERTY_CONST), | |
816 | SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool, offsetof(ExecContext, tty_vt_disallocate), SD_BUS_VTABLE_PROPERTY_CONST), | |
817 | SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST), | |
818 | SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL, offsetof(ExecContext, syslog_identifier), SD_BUS_VTABLE_PROPERTY_CONST), | |
819 | SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), SD_BUS_VTABLE_PROPERTY_CONST), | |
9d5527f2 YW |
820 | SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST), |
821 | SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST), | |
d3070fbd | 822 | SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int, offsetof(ExecContext, log_level_max), SD_BUS_VTABLE_PROPERTY_CONST), |
5ac1530e ZJS |
823 | SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec, offsetof(ExecContext, log_ratelimit_interval_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
824 | SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned, offsetof(ExecContext, log_ratelimit_burst), SD_BUS_VTABLE_PROPERTY_CONST), | |
d3070fbd | 825 | SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
91dd5f7c | 826 | SD_BUS_PROPERTY("LogNamespace", "s", NULL, offsetof(ExecContext, log_namespace), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 827 | SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST), |
c0159e20 YW |
828 | SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL, offsetof(ExecContext, capability_bounding_set), SD_BUS_VTABLE_PROPERTY_CONST), |
829 | SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL, offsetof(ExecContext, capability_ambient_set), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
830 | SD_BUS_PROPERTY("User", "s", NULL, offsetof(ExecContext, user), SD_BUS_VTABLE_PROPERTY_CONST), |
831 | SD_BUS_PROPERTY("Group", "s", NULL, offsetof(ExecContext, group), SD_BUS_VTABLE_PROPERTY_CONST), | |
29206d46 | 832 | SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool, offsetof(ExecContext, dynamic_user), SD_BUS_VTABLE_PROPERTY_CONST), |
00d9ef85 | 833 | SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(ExecContext, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 834 | SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL, offsetof(ExecContext, supplementary_groups), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 835 | SD_BUS_PROPERTY("PAMName", "s", NULL, offsetof(ExecContext, pam_name), SD_BUS_VTABLE_PROPERTY_CONST), |
2a624c36 AP |
836 | SD_BUS_PROPERTY("ReadWritePaths", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST), |
837 | SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
838 | SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
839 | SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong, offsetof(ExecContext, mount_flags), SD_BUS_VTABLE_PROPERTY_CONST), |
840 | SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST), | |
7f112f50 | 841 | SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST), |
b8b7b838 | 842 | SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool, offsetof(ExecContext, protect_clock), SD_BUS_VTABLE_PROPERTY_CONST), |
59eeb84b | 843 | SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_tunables), SD_BUS_VTABLE_PROPERTY_CONST), |
502d704e | 844 | SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_modules), SD_BUS_VTABLE_PROPERTY_CONST), |
84703040 | 845 | SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_logs), SD_BUS_VTABLE_PROPERTY_CONST), |
59eeb84b | 846 | SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool, offsetof(ExecContext, protect_control_groups), SD_BUS_VTABLE_PROPERTY_CONST), |
d251207d LP |
847 | SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), SD_BUS_VTABLE_PROPERTY_CONST), |
848 | SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool, offsetof(ExecContext, private_users), SD_BUS_VTABLE_PROPERTY_CONST), | |
228af36f | 849 | SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_bool, offsetof(ExecContext, private_mounts), SD_BUS_VTABLE_PROPERTY_CONST), |
73b84e92 YW |
850 | SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST), |
851 | SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
852 | SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), SD_BUS_VTABLE_PROPERTY_CONST), |
853 | SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL, offsetof(ExecContext, utmp_id), SD_BUS_VTABLE_PROPERTY_CONST), | |
023a4f67 | 854 | SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
5f8640fb | 855 | SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
eef65bf3 | 856 | SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
2ca620c4 | 857 | SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
858 | SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool, offsetof(ExecContext, ignore_sigpipe), SD_BUS_VTABLE_PROPERTY_CONST), |
859 | SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), SD_BUS_VTABLE_PROPERTY_CONST), | |
57183d11 LP |
860 | SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
861 | SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
cf9d43a8 | 862 | SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int, offsetof(ExecContext, syscall_errno), SD_BUS_VTABLE_PROPERTY_CONST), |
491eecb3 | 863 | SD_BUS_PROPERTY("Personality", "s", property_get_personality, offsetof(ExecContext, personality), SD_BUS_VTABLE_PROPERTY_CONST), |
78e864e5 | 864 | SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool, offsetof(ExecContext, lock_personality), SD_BUS_VTABLE_PROPERTY_CONST), |
4298d0b5 | 865 | SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
53f47dfc | 866 | SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode, offsetof(ExecContext, runtime_directory_preserve_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
3536f49e YW |
867 | SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
868 | SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
e940c1ef YW |
869 | SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
870 | SD_BUS_PROPERTY("StateDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
3536f49e YW |
871 | SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
872 | SD_BUS_PROPERTY("CacheDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
873 | SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].mode), SD_BUS_VTABLE_PROPERTY_CONST), | |
874 | SD_BUS_PROPERTY("LogsDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
875 | SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].mode), SD_BUS_VTABLE_PROPERTY_CONST), | |
876 | SD_BUS_PROPERTY("ConfigurationDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
12213aed | 877 | SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec, offsetof(ExecContext, timeout_clean_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
f3e43635 | 878 | SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool, offsetof(ExecContext, memory_deny_write_execute), SD_BUS_VTABLE_PROPERTY_CONST), |
f4170c67 | 879 | SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool, offsetof(ExecContext, restrict_realtime), SD_BUS_VTABLE_PROPERTY_CONST), |
f69567cb | 880 | SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool, offsetof(ExecContext, restrict_suid_sgid), SD_BUS_VTABLE_PROPERTY_CONST), |
6a8c2d59 | 881 | SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong, offsetof(ExecContext, restrict_namespaces), SD_BUS_VTABLE_PROPERTY_CONST), |
d2d6c096 LP |
882 | SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
883 | SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
784ad252 | 884 | SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
5d997827 | 885 | SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool, offsetof(ExecContext, mount_apivfs), SD_BUS_VTABLE_PROPERTY_CONST), |
b1edf445 | 886 | SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode, offsetof(ExecContext, keyring_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
aecd5ac6 | 887 | SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool, offsetof(ExecContext, protect_hostname), SD_BUS_VTABLE_PROPERTY_CONST), |
a8d08f39 | 888 | SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL, offsetof(ExecContext, network_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST), |
7f452159 LP |
889 | |
890 | /* Obsolete/redundant properties: */ | |
891 | SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
892 | SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
893 | SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
894 | SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
895 | SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
896 | ||
718db961 LP |
897 | SD_BUS_VTABLE_END |
898 | }; | |
82c121a4 | 899 | |
4d4c80d0 LP |
900 | static int append_exec_command(sd_bus_message *reply, ExecCommand *c) { |
901 | int r; | |
902 | ||
903 | assert(reply); | |
904 | assert(c); | |
905 | ||
906 | if (!c->path) | |
907 | return 0; | |
908 | ||
909 | r = sd_bus_message_open_container(reply, 'r', "sasbttttuii"); | |
910 | if (r < 0) | |
911 | return r; | |
912 | ||
913 | r = sd_bus_message_append(reply, "s", c->path); | |
914 | if (r < 0) | |
915 | return r; | |
916 | ||
917 | r = sd_bus_message_append_strv(reply, c->argv); | |
918 | if (r < 0) | |
919 | return r; | |
920 | ||
921 | r = sd_bus_message_append(reply, "bttttuii", | |
3ed0cd26 | 922 | !!(c->flags & EXEC_COMMAND_IGNORE_FAILURE), |
4d4c80d0 LP |
923 | c->exec_status.start_timestamp.realtime, |
924 | c->exec_status.start_timestamp.monotonic, | |
925 | c->exec_status.exit_timestamp.realtime, | |
926 | c->exec_status.exit_timestamp.monotonic, | |
927 | (uint32_t) c->exec_status.pid, | |
928 | (int32_t) c->exec_status.code, | |
929 | (int32_t) c->exec_status.status); | |
930 | if (r < 0) | |
931 | return r; | |
932 | ||
933 | return sd_bus_message_close_container(reply); | |
934 | } | |
935 | ||
b3d59367 AZ |
936 | static int append_exec_ex_command(sd_bus_message *reply, ExecCommand *c) { |
937 | _cleanup_strv_free_ char **ex_opts = NULL; | |
938 | int r; | |
939 | ||
940 | assert(reply); | |
941 | assert(c); | |
942 | ||
943 | if (!c->path) | |
944 | return 0; | |
945 | ||
946 | r = sd_bus_message_open_container(reply, 'r', "sasasttttuii"); | |
947 | if (r < 0) | |
948 | return r; | |
949 | ||
950 | r = sd_bus_message_append(reply, "s", c->path); | |
951 | if (r < 0) | |
952 | return r; | |
953 | ||
954 | r = sd_bus_message_append_strv(reply, c->argv); | |
955 | if (r < 0) | |
956 | return r; | |
957 | ||
958 | r = exec_command_flags_to_strv(c->flags, &ex_opts); | |
959 | if (r < 0) | |
960 | return r; | |
961 | ||
962 | r = sd_bus_message_append_strv(reply, ex_opts); | |
963 | if (r < 0) | |
964 | return r; | |
965 | ||
966 | r = sd_bus_message_append(reply, "ttttuii", | |
967 | c->exec_status.start_timestamp.realtime, | |
968 | c->exec_status.start_timestamp.monotonic, | |
969 | c->exec_status.exit_timestamp.realtime, | |
970 | c->exec_status.exit_timestamp.monotonic, | |
971 | (uint32_t) c->exec_status.pid, | |
972 | (int32_t) c->exec_status.code, | |
973 | (int32_t) c->exec_status.status); | |
974 | if (r < 0) | |
975 | return r; | |
976 | ||
977 | return sd_bus_message_close_container(reply); | |
978 | } | |
979 | ||
718db961 LP |
980 | int bus_property_get_exec_command( |
981 | sd_bus *bus, | |
982 | const char *path, | |
983 | const char *interface, | |
984 | const char *property, | |
985 | sd_bus_message *reply, | |
ebcf1f97 LP |
986 | void *userdata, |
987 | sd_bus_error *ret_error) { | |
fe68089d | 988 | |
4d4c80d0 | 989 | ExecCommand *c = (ExecCommand*) userdata; |
718db961 | 990 | int r; |
fe68089d | 991 | |
718db961 LP |
992 | assert(bus); |
993 | assert(reply); | |
fe68089d | 994 | |
718db961 LP |
995 | r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)"); |
996 | if (r < 0) | |
997 | return r; | |
fe68089d | 998 | |
4d4c80d0 LP |
999 | r = append_exec_command(reply, c); |
1000 | if (r < 0) | |
1001 | return r; | |
fe68089d | 1002 | |
4d4c80d0 LP |
1003 | return sd_bus_message_close_container(reply); |
1004 | } | |
718db961 | 1005 | |
4d4c80d0 LP |
1006 | int bus_property_get_exec_command_list( |
1007 | sd_bus *bus, | |
1008 | const char *path, | |
1009 | const char *interface, | |
1010 | const char *property, | |
1011 | sd_bus_message *reply, | |
1012 | void *userdata, | |
1013 | sd_bus_error *ret_error) { | |
718db961 | 1014 | |
4d4c80d0 LP |
1015 | ExecCommand *c = *(ExecCommand**) userdata; |
1016 | int r; | |
718db961 | 1017 | |
4d4c80d0 LP |
1018 | assert(bus); |
1019 | assert(reply); | |
1020 | ||
1021 | r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)"); | |
1022 | if (r < 0) | |
1023 | return r; | |
718db961 | 1024 | |
4d4c80d0 LP |
1025 | LIST_FOREACH(command, c, c) { |
1026 | r = append_exec_command(reply, c); | |
718db961 LP |
1027 | if (r < 0) |
1028 | return r; | |
fe68089d LP |
1029 | } |
1030 | ||
718db961 | 1031 | return sd_bus_message_close_container(reply); |
8351ceae | 1032 | } |
c7040b5d | 1033 | |
b3d59367 AZ |
1034 | int bus_property_get_exec_ex_command_list( |
1035 | sd_bus *bus, | |
1036 | const char *path, | |
1037 | const char *interface, | |
1038 | const char *property, | |
1039 | sd_bus_message *reply, | |
1040 | void *userdata, | |
1041 | sd_bus_error *ret_error) { | |
1042 | ||
1043 | ExecCommand *c, *exec_command = *(ExecCommand**) userdata; | |
1044 | int r; | |
1045 | ||
1046 | assert(bus); | |
1047 | assert(reply); | |
1048 | ||
1049 | r = sd_bus_message_open_container(reply, 'a', "(sasasttttuii)"); | |
1050 | if (r < 0) | |
1051 | return r; | |
1052 | ||
1053 | LIST_FOREACH(command, c, exec_command) { | |
1054 | r = append_exec_ex_command(reply, c); | |
1055 | if (r < 0) | |
1056 | return r; | |
1057 | } | |
1058 | ||
1059 | return sd_bus_message_close_container(reply); | |
1060 | } | |
1061 | ||
1062 | static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags) { | |
a4fc96c8 ZJS |
1063 | return strjoin(FLAGS_SET(flags, EXEC_COMMAND_IGNORE_FAILURE) ? "-" : "", |
1064 | FLAGS_SET(flags, EXEC_COMMAND_NO_ENV_EXPAND) ? ":" : "", | |
1065 | FLAGS_SET(flags, EXEC_COMMAND_FULLY_PRIVILEGED) ? "+" : "", | |
1066 | FLAGS_SET(flags, EXEC_COMMAND_NO_SETUID) ? "!" : "", | |
1067 | FLAGS_SET(flags, EXEC_COMMAND_AMBIENT_MAGIC) ? "!!" : ""); | |
b3d59367 AZ |
1068 | } |
1069 | ||
237f7bcb | 1070 | int bus_set_transient_exec_command( |
9c0320e7 YW |
1071 | Unit *u, |
1072 | const char *name, | |
1073 | ExecCommand **exec_command, | |
1074 | sd_bus_message *message, | |
1075 | UnitWriteFlags flags, | |
1076 | sd_bus_error *error) { | |
b3d59367 | 1077 | bool is_ex_prop = endswith(name, "Ex"); |
9c0320e7 YW |
1078 | unsigned n = 0; |
1079 | int r; | |
1080 | ||
b3d59367 | 1081 | r = sd_bus_message_enter_container(message, 'a', is_ex_prop ? "(sasas)" : "(sasb)"); |
9c0320e7 YW |
1082 | if (r < 0) |
1083 | return r; | |
1084 | ||
b3d59367 AZ |
1085 | while ((r = sd_bus_message_enter_container(message, 'r', is_ex_prop ? "sasas" : "sasb")) > 0) { |
1086 | _cleanup_strv_free_ char **argv = NULL, **ex_opts = NULL; | |
9c0320e7 YW |
1087 | const char *path; |
1088 | int b; | |
1089 | ||
1090 | r = sd_bus_message_read(message, "s", &path); | |
1091 | if (r < 0) | |
1092 | return r; | |
1093 | ||
1094 | if (!path_is_absolute(path)) | |
1095 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path); | |
1096 | ||
1097 | r = sd_bus_message_read_strv(message, &argv); | |
1098 | if (r < 0) | |
1099 | return r; | |
1100 | ||
b3d59367 | 1101 | r = is_ex_prop ? sd_bus_message_read_strv(message, &ex_opts) : sd_bus_message_read(message, "b", &b); |
9c0320e7 YW |
1102 | if (r < 0) |
1103 | return r; | |
1104 | ||
1105 | r = sd_bus_message_exit_container(message); | |
1106 | if (r < 0) | |
1107 | return r; | |
1108 | ||
1109 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1110 | ExecCommand *c; | |
1111 | ||
1112 | c = new0(ExecCommand, 1); | |
1113 | if (!c) | |
1114 | return -ENOMEM; | |
1115 | ||
1116 | c->path = strdup(path); | |
1117 | if (!c->path) { | |
1118 | free(c); | |
1119 | return -ENOMEM; | |
1120 | } | |
1121 | ||
ae2a15bc | 1122 | c->argv = TAKE_PTR(argv); |
9c0320e7 | 1123 | |
b3d59367 AZ |
1124 | if (is_ex_prop) { |
1125 | r = exec_command_flags_from_strv(ex_opts, &c->flags); | |
1126 | if (r < 0) | |
1127 | return r; | |
1128 | } else | |
1129 | c->flags = b ? EXEC_COMMAND_IGNORE_FAILURE : 0; | |
9c0320e7 | 1130 | |
858d36c1 | 1131 | path_simplify(c->path, false); |
9c0320e7 YW |
1132 | exec_command_append_list(exec_command, c); |
1133 | } | |
1134 | ||
1135 | n++; | |
1136 | } | |
1137 | if (r < 0) | |
1138 | return r; | |
1139 | ||
1140 | r = sd_bus_message_exit_container(message); | |
1141 | if (r < 0) | |
1142 | return r; | |
1143 | ||
1144 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1145 | _cleanup_free_ char *buf = NULL; | |
1146 | _cleanup_fclose_ FILE *f = NULL; | |
1147 | ExecCommand *c; | |
1148 | size_t size = 0; | |
1149 | ||
1150 | if (n == 0) | |
1151 | *exec_command = exec_command_free_list(*exec_command); | |
1152 | ||
2fe21124 | 1153 | f = open_memstream_unlocked(&buf, &size); |
9c0320e7 YW |
1154 | if (!f) |
1155 | return -ENOMEM; | |
1156 | ||
f14bf013 | 1157 | fprintf(f, "%s=\n", name); |
9c0320e7 YW |
1158 | |
1159 | LIST_FOREACH(command, c, *exec_command) { | |
540ac933 | 1160 | _cleanup_free_ char *a = NULL, *exec_chars = NULL; |
9c0320e7 | 1161 | |
540ac933 LP |
1162 | exec_chars = exec_command_flags_to_exec_chars(c->flags); |
1163 | if (!exec_chars) | |
9c0320e7 YW |
1164 | return -ENOMEM; |
1165 | ||
1166 | a = unit_concat_strv(c->argv, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS); | |
1167 | if (!a) | |
1168 | return -ENOMEM; | |
1169 | ||
540ac933 LP |
1170 | if (streq_ptr(c->path, c->argv ? c->argv[0] : NULL)) |
1171 | fprintf(f, "%s=%s%s\n", name, exec_chars, a); | |
1172 | else { | |
1173 | _cleanup_free_ char *t = NULL; | |
1174 | const char *p; | |
1175 | ||
1176 | p = unit_escape_setting(c->path, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, &t); | |
1177 | if (!p) | |
1178 | return -ENOMEM; | |
b3d59367 | 1179 | |
540ac933 LP |
1180 | fprintf(f, "%s=%s@%s %s\n", name, exec_chars, p, a); |
1181 | } | |
9c0320e7 YW |
1182 | } |
1183 | ||
1184 | r = fflush_and_check(f); | |
1185 | if (r < 0) | |
1186 | return r; | |
1187 | ||
1188 | unit_write_setting(u, flags, name, buf); | |
1189 | } | |
1190 | ||
1191 | return 1; | |
1192 | } | |
1193 | ||
7e2a3fcc YW |
1194 | static int parse_personality(const char *s, unsigned long *p) { |
1195 | unsigned long v; | |
1196 | ||
1197 | assert(p); | |
1198 | ||
1199 | v = personality_from_string(s); | |
1200 | if (v == PERSONALITY_INVALID) | |
1201 | return -EINVAL; | |
1202 | ||
1203 | *p = v; | |
1204 | return 0; | |
1205 | } | |
1206 | ||
1207 | static const char* mount_propagation_flags_to_string_with_check(unsigned long n) { | |
1208 | if (!IN_SET(n, 0, MS_SHARED, MS_PRIVATE, MS_SLAVE)) | |
1209 | return NULL; | |
1210 | ||
1211 | return mount_propagation_flags_to_string(n); | |
1212 | } | |
1213 | ||
1214 | static BUS_DEFINE_SET_TRANSIENT(nsec, "t", uint64_t, nsec_t, NSEC_FMT); | |
1215 | static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level, "i", int32_t, int, "%" PRIi32, log_level_is_valid); | |
aad67b80 | 1216 | #if HAVE_SECCOMP |
7e2a3fcc | 1217 | static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno, "i", int32_t, int, "%" PRIi32, errno_is_valid); |
aad67b80 | 1218 | #endif |
7e2a3fcc YW |
1219 | static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input, ExecInput, exec_input_from_string); |
1220 | static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output, ExecOutput, exec_output_from_string); | |
1221 | static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode, ExecUtmpMode, exec_utmp_mode_from_string); | |
1e8c7bd5 YW |
1222 | static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system, ProtectSystem, protect_system_from_string); |
1223 | static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home, ProtectHome, protect_home_from_string); | |
7e2a3fcc YW |
1224 | static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode, ExecKeyringMode, exec_keyring_mode_from_string); |
1225 | static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode, ExecPreserveMode, exec_preserve_mode_from_string); | |
1226 | static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality, unsigned long, parse_personality); | |
1227 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits, "i", int32_t, int, "%" PRIi32, secure_bits_to_string_alloc_with_check); | |
1228 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability, "t", uint64_t, uint64_t, "%" PRIu64, capability_set_to_string_alloc); | |
86c2a9f1 | 1229 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag, "t", uint64_t, unsigned long, "%" PRIu64, namespace_flags_to_string); |
7e2a3fcc YW |
1230 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags, "t", uint64_t, unsigned long, "%" PRIu64, mount_propagation_flags_to_string_with_check); |
1231 | ||
c7040b5d LP |
1232 | int bus_exec_context_set_transient_property( |
1233 | Unit *u, | |
1234 | ExecContext *c, | |
1235 | const char *name, | |
1236 | sd_bus_message *message, | |
2e59b241 | 1237 | UnitWriteFlags flags, |
c7040b5d LP |
1238 | sd_bus_error *error) { |
1239 | ||
6550c24c LP |
1240 | const char *suffix; |
1241 | int r; | |
c7040b5d LP |
1242 | |
1243 | assert(u); | |
1244 | assert(c); | |
1245 | assert(name); | |
1246 | assert(message); | |
1247 | ||
2e59b241 LP |
1248 | flags |= UNIT_PRIVATE; |
1249 | ||
7e2a3fcc | 1250 | if (streq(name, "User")) |
7a8867ab | 1251 | return bus_set_transient_user_relaxed(u, name, &c->user, message, flags, error); |
c7040b5d | 1252 | |
7e2a3fcc | 1253 | if (streq(name, "Group")) |
7a8867ab | 1254 | return bus_set_transient_user_relaxed(u, name, &c->group, message, flags, error); |
c7040b5d | 1255 | |
7e2a3fcc YW |
1256 | if (streq(name, "TTYPath")) |
1257 | return bus_set_transient_path(u, name, &c->tty_path, message, flags, error); | |
6f3e7985 | 1258 | |
7e2a3fcc YW |
1259 | if (streq(name, "RootImage")) |
1260 | return bus_set_transient_path(u, name, &c->root_image, message, flags, error); | |
76736280 | 1261 | |
7e2a3fcc YW |
1262 | if (streq(name, "RootDirectory")) |
1263 | return bus_set_transient_path(u, name, &c->root_directory, message, flags, error); | |
c7040b5d | 1264 | |
7e2a3fcc YW |
1265 | if (streq(name, "SyslogIdentifier")) |
1266 | return bus_set_transient_string(u, name, &c->syslog_identifier, message, flags, error); | |
c7040b5d | 1267 | |
7e2a3fcc YW |
1268 | if (streq(name, "LogLevelMax")) |
1269 | return bus_set_transient_log_level(u, name, &c->log_level_max, message, flags, error); | |
1270 | ||
90fc172e | 1271 | if (streq(name, "LogRateLimitIntervalUSec")) |
5ac1530e | 1272 | return bus_set_transient_usec(u, name, &c->log_ratelimit_interval_usec, message, flags, error); |
90fc172e AZ |
1273 | |
1274 | if (streq(name, "LogRateLimitBurst")) | |
5ac1530e | 1275 | return bus_set_transient_unsigned(u, name, &c->log_ratelimit_burst, message, flags, error); |
90fc172e | 1276 | |
7e2a3fcc YW |
1277 | if (streq(name, "Personality")) |
1278 | return bus_set_transient_personality(u, name, &c->personality, message, flags, error); | |
1279 | ||
7e2a3fcc YW |
1280 | if (streq(name, "StandardInput")) |
1281 | return bus_set_transient_std_input(u, name, &c->std_input, message, flags, error); | |
1282 | ||
1283 | if (streq(name, "StandardOutput")) | |
1284 | return bus_set_transient_std_output(u, name, &c->std_output, message, flags, error); | |
1285 | ||
1286 | if (streq(name, "StandardError")) | |
1287 | return bus_set_transient_std_output(u, name, &c->std_error, message, flags, error); | |
1288 | ||
1289 | if (streq(name, "IgnoreSIGPIPE")) | |
1290 | return bus_set_transient_bool(u, name, &c->ignore_sigpipe, message, flags, error); | |
1291 | ||
1292 | if (streq(name, "TTYVHangup")) | |
1293 | return bus_set_transient_bool(u, name, &c->tty_vhangup, message, flags, error); | |
1294 | ||
1295 | if (streq(name, "TTYReset")) | |
1296 | return bus_set_transient_bool(u, name, &c->tty_reset, message, flags, error); | |
1297 | ||
1298 | if (streq(name, "TTYVTDisallocate")) | |
1299 | return bus_set_transient_bool(u, name, &c->tty_vt_disallocate, message, flags, error); | |
1300 | ||
1301 | if (streq(name, "PrivateTmp")) | |
1302 | return bus_set_transient_bool(u, name, &c->private_tmp, message, flags, error); | |
1303 | ||
1304 | if (streq(name, "PrivateDevices")) | |
1305 | return bus_set_transient_bool(u, name, &c->private_devices, message, flags, error); | |
1306 | ||
228af36f LP |
1307 | if (streq(name, "PrivateMounts")) |
1308 | return bus_set_transient_bool(u, name, &c->private_mounts, message, flags, error); | |
1309 | ||
7e2a3fcc YW |
1310 | if (streq(name, "PrivateNetwork")) |
1311 | return bus_set_transient_bool(u, name, &c->private_network, message, flags, error); | |
1312 | ||
1313 | if (streq(name, "PrivateUsers")) | |
1314 | return bus_set_transient_bool(u, name, &c->private_users, message, flags, error); | |
1315 | ||
1316 | if (streq(name, "NoNewPrivileges")) | |
1317 | return bus_set_transient_bool(u, name, &c->no_new_privileges, message, flags, error); | |
1318 | ||
1319 | if (streq(name, "SyslogLevelPrefix")) | |
1320 | return bus_set_transient_bool(u, name, &c->syslog_level_prefix, message, flags, error); | |
1321 | ||
1322 | if (streq(name, "MemoryDenyWriteExecute")) | |
1323 | return bus_set_transient_bool(u, name, &c->memory_deny_write_execute, message, flags, error); | |
1324 | ||
1325 | if (streq(name, "RestrictRealtime")) | |
1326 | return bus_set_transient_bool(u, name, &c->restrict_realtime, message, flags, error); | |
1327 | ||
f69567cb LP |
1328 | if (streq(name, "RestrictSUIDSGID")) |
1329 | return bus_set_transient_bool(u, name, &c->restrict_suid_sgid, message, flags, error); | |
1330 | ||
7e2a3fcc YW |
1331 | if (streq(name, "DynamicUser")) |
1332 | return bus_set_transient_bool(u, name, &c->dynamic_user, message, flags, error); | |
1333 | ||
1334 | if (streq(name, "RemoveIPC")) | |
1335 | return bus_set_transient_bool(u, name, &c->remove_ipc, message, flags, error); | |
1336 | ||
1337 | if (streq(name, "ProtectKernelTunables")) | |
1338 | return bus_set_transient_bool(u, name, &c->protect_kernel_tunables, message, flags, error); | |
1339 | ||
1340 | if (streq(name, "ProtectKernelModules")) | |
1341 | return bus_set_transient_bool(u, name, &c->protect_kernel_modules, message, flags, error); | |
1342 | ||
84703040 KK |
1343 | if (streq(name, "ProtectKernelLogs")) |
1344 | return bus_set_transient_bool(u, name, &c->protect_kernel_logs, message, flags, error); | |
1345 | ||
fc64760d KK |
1346 | if (streq(name, "ProtectClock")) |
1347 | return bus_set_transient_bool(u, name, &c->protect_clock, message, flags, error); | |
1348 | ||
7e2a3fcc YW |
1349 | if (streq(name, "ProtectControlGroups")) |
1350 | return bus_set_transient_bool(u, name, &c->protect_control_groups, message, flags, error); | |
1351 | ||
1352 | if (streq(name, "MountAPIVFS")) | |
1353 | return bus_set_transient_bool(u, name, &c->mount_apivfs, message, flags, error); | |
1354 | ||
1355 | if (streq(name, "CPUSchedulingResetOnFork")) | |
1356 | return bus_set_transient_bool(u, name, &c->cpu_sched_reset_on_fork, message, flags, error); | |
1357 | ||
1358 | if (streq(name, "NonBlocking")) | |
1359 | return bus_set_transient_bool(u, name, &c->non_blocking, message, flags, error); | |
1360 | ||
1361 | if (streq(name, "LockPersonality")) | |
1362 | return bus_set_transient_bool(u, name, &c->lock_personality, message, flags, error); | |
1363 | ||
aecd5ac6 TM |
1364 | if (streq(name, "ProtectHostname")) |
1365 | return bus_set_transient_bool(u, name, &c->protect_hostname, message, flags, error); | |
1366 | ||
7e2a3fcc YW |
1367 | if (streq(name, "UtmpIdentifier")) |
1368 | return bus_set_transient_string(u, name, &c->utmp_id, message, flags, error); | |
1369 | ||
1370 | if (streq(name, "UtmpMode")) | |
1371 | return bus_set_transient_utmp_mode(u, name, &c->utmp_mode, message, flags, error); | |
1372 | ||
1373 | if (streq(name, "PAMName")) | |
1374 | return bus_set_transient_string(u, name, &c->pam_name, message, flags, error); | |
1375 | ||
1376 | if (streq(name, "TimerSlackNSec")) | |
1377 | return bus_set_transient_nsec(u, name, &c->timer_slack_nsec, message, flags, error); | |
1378 | ||
1379 | if (streq(name, "ProtectSystem")) | |
1380 | return bus_set_transient_protect_system(u, name, &c->protect_system, message, flags, error); | |
1381 | ||
1382 | if (streq(name, "ProtectHome")) | |
1383 | return bus_set_transient_protect_home(u, name, &c->protect_home, message, flags, error); | |
cffaed83 | 1384 | |
7e2a3fcc YW |
1385 | if (streq(name, "KeyringMode")) |
1386 | return bus_set_transient_keyring_mode(u, name, &c->keyring_mode, message, flags, error); | |
1387 | ||
1388 | if (streq(name, "RuntimeDirectoryPreserve")) | |
1389 | return bus_set_transient_preserve_mode(u, name, &c->runtime_directory_preserve_mode, message, flags, error); | |
1390 | ||
1391 | if (streq(name, "UMask")) | |
1392 | return bus_set_transient_mode_t(u, name, &c->umask, message, flags, error); | |
1393 | ||
1394 | if (streq(name, "RuntimeDirectoryMode")) | |
1395 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_RUNTIME].mode, message, flags, error); | |
1396 | ||
1397 | if (streq(name, "StateDirectoryMode")) | |
1398 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_STATE].mode, message, flags, error); | |
1399 | ||
1400 | if (streq(name, "CacheDirectoryMode")) | |
1401 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CACHE].mode, message, flags, error); | |
1402 | ||
1403 | if (streq(name, "LogsDirectoryMode")) | |
1404 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_LOGS].mode, message, flags, error); | |
1405 | ||
1406 | if (streq(name, "ConfigurationDirectoryMode")) | |
1407 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CONFIGURATION].mode, message, flags, error); | |
1408 | ||
1409 | if (streq(name, "SELinuxContext")) | |
1410 | return bus_set_transient_string(u, name, &c->selinux_context, message, flags, error); | |
1411 | ||
1412 | if (streq(name, "SecureBits")) | |
1413 | return bus_set_transient_secure_bits(u, name, &c->secure_bits, message, flags, error); | |
1414 | ||
1415 | if (streq(name, "CapabilityBoundingSet")) | |
1416 | return bus_set_transient_capability(u, name, &c->capability_bounding_set, message, flags, error); | |
1417 | ||
1418 | if (streq(name, "AmbientCapabilities")) | |
1419 | return bus_set_transient_capability(u, name, &c->capability_ambient_set, message, flags, error); | |
1420 | ||
7e2a3fcc YW |
1421 | if (streq(name, "RestrictNamespaces")) |
1422 | return bus_set_transient_namespace_flag(u, name, &c->restrict_namespaces, message, flags, error); | |
1423 | ||
1424 | if (streq(name, "MountFlags")) | |
1425 | return bus_set_transient_mount_flags(u, name, &c->mount_flags, message, flags, error); | |
1426 | ||
a8d08f39 LP |
1427 | if (streq(name, "NetworkNamespacePath")) |
1428 | return bus_set_transient_path(u, name, &c->network_namespace_path, message, flags, error); | |
1429 | ||
7e2a3fcc | 1430 | if (streq(name, "SupplementaryGroups")) { |
cffaed83 YW |
1431 | _cleanup_strv_free_ char **l = NULL; |
1432 | char **p; | |
1433 | ||
1434 | r = sd_bus_message_read_strv(message, &l); | |
1435 | if (r < 0) | |
1436 | return r; | |
1437 | ||
d2a23692 | 1438 | STRV_FOREACH(p, l) |
7a8867ab | 1439 | if (!isempty(*p) && !valid_user_group_name(*p, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN)) |
d2a23692 ZJS |
1440 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
1441 | "Invalid supplementary group names"); | |
cffaed83 | 1442 | |
2e59b241 | 1443 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7b943bb7 | 1444 | if (strv_isempty(l)) { |
cffaed83 | 1445 | c->supplementary_groups = strv_free(c->supplementary_groups); |
2e59b241 | 1446 | unit_write_settingf(u, flags, name, "%s=", name); |
cffaed83 YW |
1447 | } else { |
1448 | _cleanup_free_ char *joined = NULL; | |
1449 | ||
1450 | r = strv_extend_strv(&c->supplementary_groups, l, true); | |
1451 | if (r < 0) | |
1452 | return -ENOMEM; | |
1453 | ||
1454 | joined = strv_join(c->supplementary_groups, " "); | |
1455 | if (!joined) | |
1456 | return -ENOMEM; | |
1457 | ||
2e59b241 | 1458 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, joined); |
cffaed83 YW |
1459 | } |
1460 | } | |
1461 | ||
1462 | return 1; | |
1463 | ||
a8a13575 | 1464 | } else if (streq(name, "SyslogLevel")) { |
8d1dd6ab | 1465 | int32_t level; |
a8a13575 EV |
1466 | |
1467 | r = sd_bus_message_read(message, "i", &level); | |
1468 | if (r < 0) | |
1469 | return r; | |
1470 | ||
e0d6e0fa EV |
1471 | if (!log_level_is_valid(level)) |
1472 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range"); | |
1473 | ||
2e59b241 | 1474 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
a8a13575 | 1475 | c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level; |
2e59b241 | 1476 | unit_write_settingf(u, flags, name, "SyslogLevel=%i", level); |
a8a13575 EV |
1477 | } |
1478 | ||
460ed929 | 1479 | return 1; |
7e2a3fcc | 1480 | |
460ed929 | 1481 | } else if (streq(name, "SyslogFacility")) { |
8d1dd6ab | 1482 | int32_t facility; |
460ed929 EV |
1483 | |
1484 | r = sd_bus_message_read(message, "i", &facility); | |
1485 | if (r < 0) | |
1486 | return r; | |
1487 | ||
e0d6e0fa EV |
1488 | if (!log_facility_unshifted_is_valid(facility)) |
1489 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range"); | |
1490 | ||
2e59b241 | 1491 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
460ed929 | 1492 | c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority); |
2e59b241 | 1493 | unit_write_settingf(u, flags, name, "SyslogFacility=%i", facility); |
460ed929 EV |
1494 | } |
1495 | ||
cffaed83 | 1496 | return 1; |
d3070fbd | 1497 | |
91dd5f7c LP |
1498 | } else if (streq(name, "LogNamespace")) { |
1499 | const char *n; | |
1500 | ||
1501 | r = sd_bus_message_read(message, "s", &n); | |
1502 | if (r < 0) | |
1503 | return r; | |
1504 | ||
1505 | if (!isempty(n) && !log_namespace_name_valid(n)) | |
1506 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log namespace name not valid"); | |
1507 | ||
1508 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1509 | ||
1510 | if (isempty(n)) { | |
1511 | c->log_namespace = mfree(c->log_namespace); | |
1512 | unit_write_settingf(u, flags, name, "%s=", name); | |
1513 | } else { | |
1514 | r = free_and_strdup(&c->log_namespace, n); | |
1515 | if (r < 0) | |
1516 | return r; | |
1517 | ||
1518 | unit_write_settingf(u, flags, name, "%s=%s", name, n); | |
1519 | } | |
1520 | } | |
1521 | ||
1522 | return 1; | |
1523 | ||
d3070fbd LP |
1524 | } else if (streq(name, "LogExtraFields")) { |
1525 | size_t n = 0; | |
1526 | ||
1527 | r = sd_bus_message_enter_container(message, 'a', "ay"); | |
1528 | if (r < 0) | |
1529 | return r; | |
1530 | ||
1531 | for (;;) { | |
1532 | _cleanup_free_ void *copy = NULL; | |
1533 | struct iovec *t; | |
1534 | const char *eq; | |
1535 | const void *p; | |
1536 | size_t sz; | |
1537 | ||
1538 | /* Note that we expect a byte array for each field, instead of a string. That's because on the | |
1539 | * lower-level journal fields can actually contain binary data and are not restricted to text, | |
1540 | * and we should not "lose precision" in our types on the way. That said, I am pretty sure | |
1541 | * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse | |
1542 | * any actual binary data, and only accept UTF-8. This allows us to eventually lift this | |
1543 | * limitation, should a good, valid usecase arise. */ | |
1544 | ||
1545 | r = sd_bus_message_read_array(message, 'y', &p, &sz); | |
1546 | if (r < 0) | |
1547 | return r; | |
1548 | if (r == 0) | |
1549 | break; | |
1550 | ||
1551 | if (memchr(p, 0, sz)) | |
1552 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains zero byte"); | |
1553 | ||
1554 | eq = memchr(p, '=', sz); | |
1555 | if (!eq) | |
1556 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains no '=' character"); | |
1557 | if (!journal_field_valid(p, eq - (const char*) p, false)) | |
1558 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field invalid"); | |
1559 | ||
2e59b241 | 1560 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
aa484f35 | 1561 | t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec)); |
d3070fbd LP |
1562 | if (!t) |
1563 | return -ENOMEM; | |
1564 | c->log_extra_fields = t; | |
1565 | } | |
1566 | ||
1567 | copy = malloc(sz + 1); | |
1568 | if (!copy) | |
1569 | return -ENOMEM; | |
1570 | ||
1571 | memcpy(copy, p, sz); | |
1572 | ((uint8_t*) copy)[sz] = 0; | |
1573 | ||
1574 | if (!utf8_is_valid(copy)) | |
1575 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field is not valid UTF-8"); | |
1576 | ||
2e59b241 | 1577 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
d3070fbd | 1578 | c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE(copy, sz); |
2e59b241 | 1579 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C, name, "LogExtraFields=%s", (char*) copy); |
d3070fbd LP |
1580 | |
1581 | copy = NULL; | |
1582 | } | |
1583 | ||
1584 | n++; | |
1585 | } | |
1586 | ||
1587 | r = sd_bus_message_exit_container(message); | |
1588 | if (r < 0) | |
1589 | return r; | |
1590 | ||
2e59b241 | 1591 | if (!UNIT_WRITE_FLAGS_NOOP(flags) && n == 0) { |
d3070fbd | 1592 | exec_context_free_log_extra_fields(c); |
2e59b241 | 1593 | unit_write_setting(u, flags, name, "LogExtraFields="); |
d3070fbd LP |
1594 | } |
1595 | ||
1596 | return 1; | |
7e2a3fcc | 1597 | } |
cffaed83 | 1598 | |
349cc4a5 | 1599 | #if HAVE_SECCOMP |
cffaed83 | 1600 | |
7e2a3fcc YW |
1601 | if (streq(name, "SystemCallErrorNumber")) |
1602 | return bus_set_transient_errno(u, name, &c->syscall_errno, message, flags, error); | |
1603 | ||
1604 | if (streq(name, "SystemCallFilter")) { | |
cffaed83 | 1605 | int whitelist; |
3f856a28 | 1606 | _cleanup_strv_free_ char **l = NULL; |
cffaed83 YW |
1607 | |
1608 | r = sd_bus_message_enter_container(message, 'r', "bas"); | |
1609 | if (r < 0) | |
1610 | return r; | |
1611 | ||
1612 | r = sd_bus_message_read(message, "b", &whitelist); | |
1613 | if (r < 0) | |
1614 | return r; | |
1615 | ||
1616 | r = sd_bus_message_read_strv(message, &l); | |
1617 | if (r < 0) | |
1618 | return r; | |
1619 | ||
1620 | r = sd_bus_message_exit_container(message); | |
1621 | if (r < 0) | |
1622 | return r; | |
1623 | ||
2e59b241 | 1624 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 | 1625 | _cleanup_free_ char *joined = NULL; |
e7ccdfa8 | 1626 | SeccompParseFlags invert_flag = whitelist ? 0 : SECCOMP_PARSE_INVERT; |
898748d8 | 1627 | char **s; |
cffaed83 | 1628 | |
7b943bb7 | 1629 | if (strv_isempty(l)) { |
cffaed83 | 1630 | c->syscall_whitelist = false; |
8cfa775f | 1631 | c->syscall_filter = hashmap_free(c->syscall_filter); |
cffaed83 | 1632 | |
898748d8 YW |
1633 | unit_write_settingf(u, flags, name, "SystemCallFilter="); |
1634 | return 1; | |
1635 | } | |
cffaed83 | 1636 | |
898748d8 YW |
1637 | if (!c->syscall_filter) { |
1638 | c->syscall_filter = hashmap_new(NULL); | |
1639 | if (!c->syscall_filter) | |
1640 | return log_oom(); | |
cffaed83 | 1641 | |
898748d8 | 1642 | c->syscall_whitelist = whitelist; |
8cfa775f | 1643 | |
898748d8 | 1644 | if (c->syscall_whitelist) { |
e7ccdfa8 ZJS |
1645 | r = seccomp_parse_syscall_filter("@default", |
1646 | -1, | |
1647 | c->syscall_filter, | |
72545ae0 | 1648 | SECCOMP_PARSE_PERMISSIVE | |
58f6ab44 ZJS |
1649 | SECCOMP_PARSE_WHITELIST | invert_flag, |
1650 | u->id, | |
1651 | NULL, 0); | |
8cfa775f YW |
1652 | if (r < 0) |
1653 | return r; | |
898748d8 YW |
1654 | } |
1655 | } | |
8cfa775f | 1656 | |
898748d8 YW |
1657 | STRV_FOREACH(s, l) { |
1658 | _cleanup_free_ char *n = NULL; | |
1659 | int e; | |
cffaed83 | 1660 | |
898748d8 YW |
1661 | r = parse_syscall_and_errno(*s, &n, &e); |
1662 | if (r < 0) | |
1663 | return r; | |
cffaed83 | 1664 | |
e7ccdfa8 ZJS |
1665 | r = seccomp_parse_syscall_filter(n, |
1666 | e, | |
1667 | c->syscall_filter, | |
72545ae0 AZ |
1668 | SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE | |
1669 | invert_flag | | |
1670 | (c->syscall_whitelist ? SECCOMP_PARSE_WHITELIST : 0), | |
58f6ab44 ZJS |
1671 | u->id, |
1672 | NULL, 0); | |
898748d8 YW |
1673 | if (r < 0) |
1674 | return r; | |
cffaed83 YW |
1675 | } |
1676 | ||
1677 | joined = strv_join(l, " "); | |
1678 | if (!joined) | |
1679 | return -ENOMEM; | |
1680 | ||
2e59b241 | 1681 | unit_write_settingf(u, flags, name, "SystemCallFilter=%s%s", whitelist ? "" : "~", joined); |
cffaed83 YW |
1682 | } |
1683 | ||
1684 | return 1; | |
1685 | ||
1686 | } else if (streq(name, "SystemCallArchitectures")) { | |
1687 | _cleanup_strv_free_ char **l = NULL; | |
1688 | ||
1689 | r = sd_bus_message_read_strv(message, &l); | |
1690 | if (r < 0) | |
1691 | return r; | |
1692 | ||
2e59b241 | 1693 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 YW |
1694 | _cleanup_free_ char *joined = NULL; |
1695 | ||
7b943bb7 | 1696 | if (strv_isempty(l)) |
cffaed83 YW |
1697 | c->syscall_archs = set_free(c->syscall_archs); |
1698 | else { | |
1699 | char **s; | |
1700 | ||
1701 | r = set_ensure_allocated(&c->syscall_archs, NULL); | |
1702 | if (r < 0) | |
1703 | return r; | |
1704 | ||
1705 | STRV_FOREACH(s, l) { | |
1706 | uint32_t a; | |
1707 | ||
1708 | r = seccomp_arch_from_string(*s, &a); | |
1709 | if (r < 0) | |
1710 | return r; | |
1711 | ||
1712 | r = set_put(c->syscall_archs, UINT32_TO_PTR(a + 1)); | |
1713 | if (r < 0) | |
1714 | return r; | |
1715 | } | |
1716 | ||
1717 | } | |
1718 | ||
1719 | joined = strv_join(l, " "); | |
1720 | if (!joined) | |
1721 | return -ENOMEM; | |
1722 | ||
2e59b241 | 1723 | unit_write_settingf(u, flags, name, "%s=%s", name, joined); |
cffaed83 YW |
1724 | } |
1725 | ||
1726 | return 1; | |
1727 | ||
cffaed83 YW |
1728 | } else if (streq(name, "RestrictAddressFamilies")) { |
1729 | int whitelist; | |
3f856a28 | 1730 | _cleanup_strv_free_ char **l = NULL; |
cffaed83 YW |
1731 | |
1732 | r = sd_bus_message_enter_container(message, 'r', "bas"); | |
1733 | if (r < 0) | |
1734 | return r; | |
1735 | ||
1736 | r = sd_bus_message_read(message, "b", &whitelist); | |
1737 | if (r < 0) | |
1738 | return r; | |
1739 | ||
1740 | r = sd_bus_message_read_strv(message, &l); | |
1741 | if (r < 0) | |
1742 | return r; | |
1743 | ||
1744 | r = sd_bus_message_exit_container(message); | |
1745 | if (r < 0) | |
1746 | return r; | |
1747 | ||
2e59b241 | 1748 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 | 1749 | _cleanup_free_ char *joined = NULL; |
9ee896d5 | 1750 | char **s; |
cffaed83 | 1751 | |
7b943bb7 | 1752 | if (strv_isempty(l)) { |
cffaed83 YW |
1753 | c->address_families_whitelist = false; |
1754 | c->address_families = set_free(c->address_families); | |
cffaed83 | 1755 | |
9ee896d5 YW |
1756 | unit_write_settingf(u, flags, name, "RestrictAddressFamilies="); |
1757 | return 1; | |
1758 | } | |
cffaed83 | 1759 | |
9ee896d5 YW |
1760 | if (!c->address_families) { |
1761 | c->address_families = set_new(NULL); | |
1762 | if (!c->address_families) | |
1763 | return log_oom(); | |
cffaed83 | 1764 | |
9ee896d5 YW |
1765 | c->address_families_whitelist = whitelist; |
1766 | } | |
1767 | ||
1768 | STRV_FOREACH(s, l) { | |
1769 | int af; | |
cffaed83 | 1770 | |
9ee896d5 | 1771 | af = af_from_name(*s); |
acf4d158 YW |
1772 | if (af < 0) |
1773 | return af; | |
cffaed83 | 1774 | |
e7ccdfa8 | 1775 | if (whitelist == c->address_families_whitelist) { |
cffaed83 YW |
1776 | r = set_put(c->address_families, INT_TO_PTR(af)); |
1777 | if (r < 0) | |
1778 | return r; | |
9ee896d5 YW |
1779 | } else |
1780 | (void) set_remove(c->address_families, INT_TO_PTR(af)); | |
cffaed83 YW |
1781 | } |
1782 | ||
1783 | joined = strv_join(l, " "); | |
1784 | if (!joined) | |
1785 | return -ENOMEM; | |
1786 | ||
2e59b241 | 1787 | unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s%s", whitelist ? "" : "~", joined); |
cffaed83 YW |
1788 | } |
1789 | ||
1790 | return 1; | |
7e2a3fcc | 1791 | } |
cffaed83 | 1792 | #endif |
b070c7c0 | 1793 | if (STR_IN_SET(name, "CPUAffinity", "NUMAMask")) { |
cffaed83 | 1794 | const void *a; |
bd0abfae | 1795 | size_t n; |
b070c7c0 | 1796 | bool affinity = streq(name, "CPUAffinity"); |
c367f996 | 1797 | _cleanup_(cpu_set_reset) CPUSet set = {}; |
cffaed83 YW |
1798 | |
1799 | r = sd_bus_message_read_array(message, 'y', &a, &n); | |
1800 | if (r < 0) | |
1801 | return r; | |
1802 | ||
c367f996 MS |
1803 | r = cpu_set_from_dbus(a, n, &set); |
1804 | if (r < 0) | |
1805 | return r; | |
1806 | ||
2e59b241 | 1807 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 | 1808 | if (n == 0) { |
b070c7c0 | 1809 | cpu_set_reset(affinity ? &c->cpu_set : &c->numa_policy.nodes); |
2e59b241 | 1810 | unit_write_settingf(u, flags, name, "%s=", name); |
cffaed83 YW |
1811 | } else { |
1812 | _cleanup_free_ char *str = NULL; | |
cffaed83 | 1813 | |
0985c7c4 | 1814 | str = cpu_set_to_string(&set); |
a832893f ZJS |
1815 | if (!str) |
1816 | return -ENOMEM; | |
cffaed83 | 1817 | |
0985c7c4 ZJS |
1818 | /* We forego any optimizations here, and always create the structure using |
1819 | * cpu_set_add_all(), because we don't want to care if the existing size we | |
1820 | * got over dbus is appropriate. */ | |
b070c7c0 | 1821 | r = cpu_set_add_all(affinity ? &c->cpu_set : &c->numa_policy.nodes, &set); |
0985c7c4 ZJS |
1822 | if (r < 0) |
1823 | return r; | |
501941aa | 1824 | |
2e59b241 | 1825 | unit_write_settingf(u, flags, name, "%s=%s", name, str); |
cffaed83 YW |
1826 | } |
1827 | } | |
1828 | ||
c7040b5d LP |
1829 | return 1; |
1830 | ||
e2b2fb7f MS |
1831 | } else if (streq(name, "CPUAffinityFromNUMA")) { |
1832 | int q; | |
1833 | ||
1834 | r = sd_bus_message_read_basic(message, 'b', &q); | |
1835 | if (r < 0) | |
1836 | return r; | |
1837 | ||
1838 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1839 | c->cpu_affinity_from_numa = q; | |
1840 | unit_write_settingf(u, flags, name, "%s=%s", "CPUAffinity", "numa"); | |
1841 | } | |
1842 | ||
1843 | return 1; | |
1844 | ||
b070c7c0 MS |
1845 | } else if (streq(name, "NUMAPolicy")) { |
1846 | int32_t type; | |
1847 | ||
1848 | r = sd_bus_message_read(message, "i", &type); | |
1849 | if (r < 0) | |
1850 | return r; | |
1851 | ||
1852 | if (!mpol_is_valid(type)) | |
1853 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid NUMAPolicy value: %i", type); | |
1854 | ||
1855 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) | |
1856 | c->numa_policy.type = type; | |
1857 | ||
1858 | return 1; | |
e2b2fb7f | 1859 | |
c250bf67 YW |
1860 | } else if (streq(name, "Nice")) { |
1861 | int32_t q; | |
1862 | ||
1863 | r = sd_bus_message_read(message, "i", &q); | |
1864 | if (r < 0) | |
1865 | return r; | |
1866 | ||
1867 | if (!nice_is_valid(q)) | |
1868 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Nice value: %i", q); | |
1869 | ||
1870 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1871 | c->nice = q; | |
1872 | c->nice_set = true; | |
1873 | ||
1874 | unit_write_settingf(u, flags, name, "Nice=%i", q); | |
1875 | } | |
1876 | ||
1877 | return 1; | |
1878 | ||
1879 | } else if (streq(name, "CPUSchedulingPolicy")) { | |
1880 | int32_t q; | |
1881 | ||
1882 | r = sd_bus_message_read(message, "i", &q); | |
1883 | if (r < 0) | |
1884 | return r; | |
1885 | ||
1886 | if (!sched_policy_is_valid(q)) | |
1887 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling policy: %i", q); | |
1888 | ||
1889 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1890 | _cleanup_free_ char *s = NULL; | |
1891 | ||
1892 | r = sched_policy_to_string_alloc(q, &s); | |
1893 | if (r < 0) | |
1894 | return r; | |
1895 | ||
1896 | c->cpu_sched_policy = q; | |
1897 | c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(q), sched_get_priority_max(q)); | |
1898 | c->cpu_sched_set = true; | |
1899 | ||
1900 | unit_write_settingf(u, flags, name, "CPUSchedulingPolicy=%s", s); | |
1901 | } | |
1902 | ||
1903 | return 1; | |
1904 | ||
1905 | } else if (streq(name, "CPUSchedulingPriority")) { | |
1906 | int32_t p, min, max; | |
1907 | ||
1908 | r = sd_bus_message_read(message, "i", &p); | |
1909 | if (r < 0) | |
1910 | return r; | |
1911 | ||
1912 | min = sched_get_priority_min(c->cpu_sched_policy); | |
1913 | max = sched_get_priority_max(c->cpu_sched_policy); | |
1914 | if (p < min || p > max) | |
1915 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling priority: %i", p); | |
1916 | ||
1917 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1918 | c->cpu_sched_priority = p; | |
1919 | c->cpu_sched_set = true; | |
1920 | ||
1921 | unit_write_settingf(u, flags, name, "CPUSchedulingPriority=%i", p); | |
1922 | } | |
1923 | ||
1924 | return 1; | |
1925 | ||
7f452159 LP |
1926 | } else if (streq(name, "IOSchedulingClass")) { |
1927 | int32_t q; | |
1928 | ||
1929 | r = sd_bus_message_read(message, "i", &q); | |
1930 | if (r < 0) | |
1931 | return r; | |
1932 | ||
1933 | if (!ioprio_class_is_valid(q)) | |
1934 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling class: %i", q); | |
1935 | ||
2e59b241 | 1936 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7f452159 LP |
1937 | _cleanup_free_ char *s = NULL; |
1938 | ||
1939 | r = ioprio_class_to_string_alloc(q, &s); | |
1940 | if (r < 0) | |
1941 | return r; | |
1942 | ||
1943 | c->ioprio = IOPRIO_PRIO_VALUE(q, IOPRIO_PRIO_DATA(c->ioprio)); | |
1944 | c->ioprio_set = true; | |
1945 | ||
2e59b241 | 1946 | unit_write_settingf(u, flags, name, "IOSchedulingClass=%s", s); |
7f452159 LP |
1947 | } |
1948 | ||
1949 | return 1; | |
1950 | ||
1951 | } else if (streq(name, "IOSchedulingPriority")) { | |
1952 | int32_t p; | |
1953 | ||
1954 | r = sd_bus_message_read(message, "i", &p); | |
1955 | if (r < 0) | |
1956 | return r; | |
1957 | ||
1958 | if (!ioprio_priority_is_valid(p)) | |
1959 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling priority: %i", p); | |
1960 | ||
2e59b241 | 1961 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7f452159 LP |
1962 | c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), p); |
1963 | c->ioprio_set = true; | |
1964 | ||
2e59b241 | 1965 | unit_write_settingf(u, flags, name, "IOSchedulingPriority=%i", p); |
7f452159 LP |
1966 | } |
1967 | ||
1968 | return 1; | |
1969 | ||
5f5d8eab LP |
1970 | } else if (streq(name, "WorkingDirectory")) { |
1971 | const char *s; | |
1972 | bool missing_ok; | |
1973 | ||
1974 | r = sd_bus_message_read(message, "s", &s); | |
1975 | if (r < 0) | |
1976 | return r; | |
1977 | ||
1978 | if (s[0] == '-') { | |
1979 | missing_ok = true; | |
1980 | s++; | |
1981 | } else | |
1982 | missing_ok = false; | |
1983 | ||
d6ff82d3 | 1984 | if (!isempty(s) && !streq(s, "~") && !path_is_absolute(s)) |
5f5d8eab LP |
1985 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'"); |
1986 | ||
2e59b241 | 1987 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
5f5d8eab LP |
1988 | if (streq(s, "~")) { |
1989 | c->working_directory = mfree(c->working_directory); | |
1990 | c->working_directory_home = true; | |
1991 | } else { | |
d6ff82d3 | 1992 | r = free_and_strdup(&c->working_directory, empty_to_null(s)); |
5f5d8eab LP |
1993 | if (r < 0) |
1994 | return r; | |
1995 | ||
1996 | c->working_directory_home = false; | |
1997 | } | |
1998 | ||
1999 | c->working_directory_missing_ok = missing_ok; | |
2e59b241 | 2000 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s); |
5f5d8eab LP |
2001 | } |
2002 | ||
2003 | return 1; | |
2004 | ||
52c239d7 LB |
2005 | } else if (STR_IN_SET(name, |
2006 | "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) { | |
2007 | const char *s; | |
2008 | ||
2009 | r = sd_bus_message_read(message, "s", &s); | |
2010 | if (r < 0) | |
2011 | return r; | |
2012 | ||
d6ff82d3 | 2013 | if (!isempty(s) && !fdname_is_valid(s)) |
52c239d7 LB |
2014 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid file descriptor name"); |
2015 | ||
2e59b241 | 2016 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
5073ff6b | 2017 | |
52c239d7 | 2018 | if (streq(name, "StandardInputFileDescriptorName")) { |
d6ff82d3 | 2019 | r = free_and_strdup(c->stdio_fdname + STDIN_FILENO, empty_to_null(s)); |
52c239d7 LB |
2020 | if (r < 0) |
2021 | return r; | |
5073ff6b | 2022 | |
0664775c | 2023 | c->std_input = EXEC_INPUT_NAMED_FD; |
2e59b241 | 2024 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=fd:%s", exec_context_fdname(c, STDIN_FILENO)); |
5073ff6b | 2025 | |
52c239d7 | 2026 | } else if (streq(name, "StandardOutputFileDescriptorName")) { |
d6ff82d3 | 2027 | r = free_and_strdup(c->stdio_fdname + STDOUT_FILENO, empty_to_null(s)); |
52c239d7 LB |
2028 | if (r < 0) |
2029 | return r; | |
5073ff6b | 2030 | |
52c239d7 | 2031 | c->std_output = EXEC_OUTPUT_NAMED_FD; |
2e59b241 | 2032 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=fd:%s", exec_context_fdname(c, STDOUT_FILENO)); |
0664775c LP |
2033 | |
2034 | } else { | |
2035 | assert(streq(name, "StandardErrorFileDescriptorName")); | |
5073ff6b | 2036 | |
d6ff82d3 | 2037 | r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], empty_to_null(s)); |
52c239d7 LB |
2038 | if (r < 0) |
2039 | return r; | |
5073ff6b | 2040 | |
52c239d7 | 2041 | c->std_error = EXEC_OUTPUT_NAMED_FD; |
2e59b241 | 2042 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=fd:%s", exec_context_fdname(c, STDERR_FILENO)); |
52c239d7 LB |
2043 | } |
2044 | } | |
2045 | ||
2046 | return 1; | |
2047 | ||
566b7d23 ZD |
2048 | } else if (STR_IN_SET(name, |
2049 | "StandardInputFile", | |
922ce049 LP |
2050 | "StandardOutputFile", "StandardOutputFileToAppend", |
2051 | "StandardErrorFile", "StandardErrorFileToAppend")) { | |
2038c3f5 LP |
2052 | const char *s; |
2053 | ||
2054 | r = sd_bus_message_read(message, "s", &s); | |
2055 | if (r < 0) | |
2056 | return r; | |
2057 | ||
d6ff82d3 YW |
2058 | if (!isempty(s)) { |
2059 | if (!path_is_absolute(s)) | |
2060 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute", s); | |
2061 | if (!path_is_normalized(s)) | |
2062 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not normalized", s); | |
2063 | } | |
2038c3f5 | 2064 | |
2e59b241 | 2065 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
2038c3f5 LP |
2066 | |
2067 | if (streq(name, "StandardInputFile")) { | |
d6ff82d3 | 2068 | r = free_and_strdup(&c->stdio_file[STDIN_FILENO], empty_to_null(s)); |
52c239d7 LB |
2069 | if (r < 0) |
2070 | return r; | |
2038c3f5 LP |
2071 | |
2072 | c->std_input = EXEC_INPUT_FILE; | |
2e59b241 | 2073 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=file:%s", s); |
2038c3f5 | 2074 | |
566b7d23 | 2075 | } else if (STR_IN_SET(name, "StandardOutputFile", "StandardOutputFileToAppend")) { |
d6ff82d3 | 2076 | r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], empty_to_null(s)); |
2038c3f5 LP |
2077 | if (r < 0) |
2078 | return r; | |
2079 | ||
566b7d23 ZD |
2080 | if (streq(name, "StandardOutputFile")) { |
2081 | c->std_output = EXEC_OUTPUT_FILE; | |
2082 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=file:%s", s); | |
2083 | } else { | |
2084 | assert(streq(name, "StandardOutputFileToAppend")); | |
2085 | c->std_output = EXEC_OUTPUT_FILE_APPEND; | |
2086 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=append:%s", s); | |
2087 | } | |
2038c3f5 | 2088 | } else { |
566b7d23 | 2089 | assert(STR_IN_SET(name, "StandardErrorFile", "StandardErrorFileToAppend")); |
2038c3f5 | 2090 | |
d6ff82d3 | 2091 | r = free_and_strdup(&c->stdio_file[STDERR_FILENO], empty_to_null(s)); |
2038c3f5 LP |
2092 | if (r < 0) |
2093 | return r; | |
2094 | ||
566b7d23 ZD |
2095 | if (streq(name, "StandardErrorFile")) { |
2096 | c->std_error = EXEC_OUTPUT_FILE; | |
1704fba9 | 2097 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=file:%s", s); |
566b7d23 | 2098 | } else { |
dbe6c4b6 LP |
2099 | assert(streq(name, "StandardErrorFileToAppend")); |
2100 | c->std_error = EXEC_OUTPUT_FILE_APPEND; | |
1704fba9 | 2101 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=append:%s", s); |
566b7d23 | 2102 | } |
2038c3f5 LP |
2103 | } |
2104 | } | |
2105 | ||
2106 | return 1; | |
2107 | ||
08f3be7a LP |
2108 | } else if (streq(name, "StandardInputData")) { |
2109 | const void *p; | |
2110 | size_t sz; | |
2111 | ||
2112 | r = sd_bus_message_read_array(message, 'y', &p, &sz); | |
2113 | if (r < 0) | |
2114 | return r; | |
2115 | ||
2e59b241 | 2116 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
08f3be7a LP |
2117 | _cleanup_free_ char *encoded = NULL; |
2118 | ||
2119 | if (sz == 0) { | |
2120 | c->stdin_data = mfree(c->stdin_data); | |
2121 | c->stdin_data_size = 0; | |
2122 | ||
2e59b241 | 2123 | unit_write_settingf(u, flags, name, "StandardInputData="); |
08f3be7a LP |
2124 | } else { |
2125 | void *q; | |
2126 | ssize_t n; | |
2127 | ||
2128 | if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */ | |
2129 | c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX) | |
2130 | return -E2BIG; | |
2131 | ||
2132 | n = base64mem(p, sz, &encoded); | |
2133 | if (n < 0) | |
2134 | return (int) n; | |
2135 | ||
2136 | q = realloc(c->stdin_data, c->stdin_data_size + sz); | |
2137 | if (!q) | |
2138 | return -ENOMEM; | |
2139 | ||
2140 | memcpy((uint8_t*) q + c->stdin_data_size, p, sz); | |
2141 | ||
2142 | c->stdin_data = q; | |
2143 | c->stdin_data_size += sz; | |
2144 | ||
2e59b241 | 2145 | unit_write_settingf(u, flags, name, "StandardInputData=%s", encoded); |
52c239d7 LB |
2146 | } |
2147 | } | |
2148 | ||
2149 | return 1; | |
2150 | ||
c7040b5d LP |
2151 | } else if (streq(name, "Environment")) { |
2152 | ||
6171b822 | 2153 | _cleanup_strv_free_ char **l = NULL; |
c7040b5d LP |
2154 | |
2155 | r = sd_bus_message_read_strv(message, &l); | |
2156 | if (r < 0) | |
2157 | return r; | |
2158 | ||
6171b822 | 2159 | if (!strv_env_is_valid(l)) |
1c68232e LP |
2160 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block."); |
2161 | ||
2e59b241 | 2162 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7b943bb7 | 2163 | if (strv_isempty(l)) { |
e9876fc9 | 2164 | c->environment = strv_free(c->environment); |
2e59b241 | 2165 | unit_write_setting(u, flags, name, "Environment="); |
e9876fc9 | 2166 | } else { |
f900f582 ZJS |
2167 | _cleanup_free_ char *joined = NULL; |
2168 | char **e; | |
2169 | ||
2e59b241 LP |
2170 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C); |
2171 | if (!joined) | |
2172 | return -ENOMEM; | |
2173 | ||
6171b822 | 2174 | e = strv_env_merge(2, c->environment, l); |
e9876fc9 EV |
2175 | if (!e) |
2176 | return -ENOMEM; | |
c7040b5d | 2177 | |
130d3d22 | 2178 | strv_free_and_replace(c->environment, e); |
2e59b241 | 2179 | unit_write_settingf(u, flags, name, "Environment=%s", joined); |
e9876fc9 | 2180 | } |
c7040b5d LP |
2181 | } |
2182 | ||
d584f638 LP |
2183 | return 1; |
2184 | ||
00819cc1 LP |
2185 | } else if (streq(name, "UnsetEnvironment")) { |
2186 | ||
6171b822 | 2187 | _cleanup_strv_free_ char **l = NULL; |
00819cc1 LP |
2188 | |
2189 | r = sd_bus_message_read_strv(message, &l); | |
2190 | if (r < 0) | |
2191 | return r; | |
2192 | ||
6171b822 | 2193 | if (!strv_env_name_or_assignment_is_valid(l)) |
00819cc1 LP |
2194 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list."); |
2195 | ||
2e59b241 | 2196 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7b943bb7 | 2197 | if (strv_isempty(l)) { |
00819cc1 | 2198 | c->unset_environment = strv_free(c->unset_environment); |
2e59b241 | 2199 | unit_write_setting(u, flags, name, "UnsetEnvironment="); |
00819cc1 LP |
2200 | } else { |
2201 | _cleanup_free_ char *joined = NULL; | |
2202 | char **e; | |
2203 | ||
2e59b241 LP |
2204 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C); |
2205 | if (!joined) | |
2206 | return -ENOMEM; | |
2207 | ||
6171b822 | 2208 | e = strv_env_merge(2, c->unset_environment, l); |
00819cc1 LP |
2209 | if (!e) |
2210 | return -ENOMEM; | |
2211 | ||
130d3d22 | 2212 | strv_free_and_replace(c->unset_environment, e); |
2e59b241 | 2213 | unit_write_settingf(u, flags, name, "UnsetEnvironment=%s", joined); |
00819cc1 LP |
2214 | } |
2215 | } | |
2216 | ||
2217 | return 1; | |
2218 | ||
6b862936 EV |
2219 | } else if (streq(name, "OOMScoreAdjust")) { |
2220 | int oa; | |
2221 | ||
2222 | r = sd_bus_message_read(message, "i", &oa); | |
2223 | if (r < 0) | |
2224 | return r; | |
2225 | ||
2226 | if (!oom_score_adjust_is_valid(oa)) | |
2227 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range"); | |
2228 | ||
2e59b241 | 2229 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
6b862936 EV |
2230 | c->oom_score_adjust = oa; |
2231 | c->oom_score_adjust_set = true; | |
2e59b241 | 2232 | unit_write_settingf(u, flags, name, "OOMScoreAdjust=%i", oa); |
6b862936 EV |
2233 | } |
2234 | ||
2235 | return 1; | |
2236 | ||
ad21e542 ZJS |
2237 | } else if (streq(name, "CoredumpFilter")) { |
2238 | uint64_t f; | |
2239 | ||
2240 | r = sd_bus_message_read(message, "t", &f); | |
2241 | if (r < 0) | |
2242 | return r; | |
2243 | ||
2244 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2245 | c->coredump_filter = f; | |
2246 | c->coredump_filter_set = true; | |
2247 | unit_write_settingf(u, flags, name, "CoredumpFilter=0x%"PRIx64, f); | |
2248 | } | |
2249 | ||
2250 | return 1; | |
2251 | ||
ceb728cf NC |
2252 | } else if (streq(name, "EnvironmentFiles")) { |
2253 | ||
2254 | _cleanup_free_ char *joined = NULL; | |
2255 | _cleanup_fclose_ FILE *f = NULL; | |
9b531f04 | 2256 | _cleanup_strv_free_ char **l = NULL; |
ceb728cf | 2257 | size_t size = 0; |
2229f656 | 2258 | char **i; |
ceb728cf NC |
2259 | |
2260 | r = sd_bus_message_enter_container(message, 'a', "(sb)"); | |
2261 | if (r < 0) | |
2262 | return r; | |
2263 | ||
2fe21124 | 2264 | f = open_memstream_unlocked(&joined, &size); |
ceb728cf NC |
2265 | if (!f) |
2266 | return -ENOMEM; | |
2267 | ||
2e59b241 LP |
2268 | fputs("EnvironmentFile=\n", f); |
2269 | ||
2270 | STRV_FOREACH(i, c->environment_files) { | |
2271 | _cleanup_free_ char *q = NULL; | |
2272 | ||
2273 | q = specifier_escape(*i); | |
2274 | if (!q) | |
2275 | return -ENOMEM; | |
2276 | ||
2277 | fprintf(f, "EnvironmentFile=%s\n", q); | |
2278 | } | |
ceb728cf NC |
2279 | |
2280 | while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) { | |
2281 | const char *path; | |
2282 | int b; | |
2283 | ||
ceb728cf NC |
2284 | r = sd_bus_message_read(message, "sb", &path, &b); |
2285 | if (r < 0) | |
2286 | return r; | |
2287 | ||
2288 | r = sd_bus_message_exit_container(message); | |
2289 | if (r < 0) | |
2290 | return r; | |
2291 | ||
d2d6c096 LP |
2292 | if (!path_is_absolute(path)) |
2293 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path); | |
ceb728cf | 2294 | |
2e59b241 | 2295 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
6abdec98 | 2296 | _cleanup_free_ char *q = NULL, *buf = NULL; |
ceb728cf | 2297 | |
605405c6 | 2298 | buf = strjoin(b ? "-" : "", path); |
2229f656 | 2299 | if (!buf) |
ceb728cf NC |
2300 | return -ENOMEM; |
2301 | ||
2e59b241 | 2302 | q = specifier_escape(buf); |
6abdec98 | 2303 | if (!q) |
2e59b241 | 2304 | return -ENOMEM; |
2e59b241 LP |
2305 | |
2306 | fprintf(f, "EnvironmentFile=%s\n", q); | |
ceb728cf | 2307 | |
6abdec98 | 2308 | r = strv_consume(&l, TAKE_PTR(buf)); |
ceb728cf NC |
2309 | if (r < 0) |
2310 | return r; | |
2311 | } | |
2312 | } | |
2313 | if (r < 0) | |
2314 | return r; | |
2315 | ||
b0830e21 LP |
2316 | r = sd_bus_message_exit_container(message); |
2317 | if (r < 0) | |
2318 | return r; | |
2319 | ||
2229f656 LP |
2320 | r = fflush_and_check(f); |
2321 | if (r < 0) | |
2322 | return r; | |
ceb728cf | 2323 | |
2e59b241 | 2324 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
2229f656 LP |
2325 | if (strv_isempty(l)) { |
2326 | c->environment_files = strv_free(c->environment_files); | |
2e59b241 | 2327 | unit_write_setting(u, flags, name, "EnvironmentFile="); |
2229f656 LP |
2328 | } else { |
2329 | r = strv_extend_strv(&c->environment_files, l, true); | |
2330 | if (r < 0) | |
2331 | return r; | |
2332 | ||
2e59b241 | 2333 | unit_write_setting(u, flags, name, joined); |
2229f656 LP |
2334 | } |
2335 | } | |
ceb728cf | 2336 | |
ceb728cf NC |
2337 | return 1; |
2338 | ||
b4c14404 FB |
2339 | } else if (streq(name, "PassEnvironment")) { |
2340 | ||
6171b822 | 2341 | _cleanup_strv_free_ char **l = NULL; |
b4c14404 FB |
2342 | |
2343 | r = sd_bus_message_read_strv(message, &l); | |
2344 | if (r < 0) | |
2345 | return r; | |
2346 | ||
6171b822 | 2347 | if (!strv_env_name_is_valid(l)) |
00819cc1 | 2348 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment= block."); |
b4c14404 | 2349 | |
2e59b241 | 2350 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
b4c14404 FB |
2351 | if (strv_isempty(l)) { |
2352 | c->pass_environment = strv_free(c->pass_environment); | |
2e59b241 | 2353 | unit_write_setting(u, flags, name, "PassEnvironment="); |
b4c14404 FB |
2354 | } else { |
2355 | _cleanup_free_ char *joined = NULL; | |
2356 | ||
9d4f242a YW |
2357 | r = strv_extend_strv(&c->pass_environment, l, true); |
2358 | if (r < 0) | |
2359 | return r; | |
2360 | ||
41de9cc2 | 2361 | /* We write just the new settings out to file, with unresolved specifiers. */ |
2e59b241 | 2362 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS); |
b4c14404 FB |
2363 | if (!joined) |
2364 | return -ENOMEM; | |
2365 | ||
2e59b241 | 2366 | unit_write_settingf(u, flags, name, "PassEnvironment=%s", joined); |
b4c14404 FB |
2367 | } |
2368 | } | |
2369 | ||
2370 | return 1; | |
2371 | ||
2a624c36 AP |
2372 | } else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories", |
2373 | "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) { | |
08596068 EV |
2374 | _cleanup_strv_free_ char **l = NULL; |
2375 | char ***dirs; | |
2376 | char **p; | |
2377 | ||
2378 | r = sd_bus_message_read_strv(message, &l); | |
2379 | if (r < 0) | |
2380 | return r; | |
2381 | ||
2382 | STRV_FOREACH(p, l) { | |
e7bcff4e | 2383 | char *i = *p; |
20b7a007 LP |
2384 | size_t offset; |
2385 | ||
20b7a007 LP |
2386 | offset = i[0] == '-'; |
2387 | offset += i[offset] == '+'; | |
2388 | if (!path_is_absolute(i + offset)) | |
08596068 | 2389 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name); |
e7bcff4e | 2390 | |
858d36c1 | 2391 | path_simplify(i + offset, false); |
08596068 EV |
2392 | } |
2393 | ||
2e59b241 | 2394 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
c4b41707 AP |
2395 | if (STR_IN_SET(name, "ReadWriteDirectories", "ReadWritePaths")) |
2396 | dirs = &c->read_write_paths; | |
2397 | else if (STR_IN_SET(name, "ReadOnlyDirectories", "ReadOnlyPaths")) | |
2398 | dirs = &c->read_only_paths; | |
2399 | else /* "InaccessiblePaths" */ | |
2400 | dirs = &c->inaccessible_paths; | |
08596068 | 2401 | |
7b943bb7 | 2402 | if (strv_isempty(l)) { |
08596068 | 2403 | *dirs = strv_free(*dirs); |
2e59b241 | 2404 | unit_write_settingf(u, flags, name, "%s=", name); |
08596068 | 2405 | } else { |
2e59b241 | 2406 | _cleanup_free_ char *joined = NULL; |
08596068 | 2407 | |
2e59b241 | 2408 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS); |
08596068 EV |
2409 | if (!joined) |
2410 | return -ENOMEM; | |
2411 | ||
2e59b241 LP |
2412 | r = strv_extend_strv(dirs, l, true); |
2413 | if (r < 0) | |
2414 | return -ENOMEM; | |
08596068 | 2415 | |
2e59b241 LP |
2416 | unit_write_settingf(u, flags, name, "%s=%s", name, joined); |
2417 | } | |
08596068 EV |
2418 | } |
2419 | ||
2420 | return 1; | |
2421 | ||
3536f49e | 2422 | } else if (STR_IN_SET(name, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) { |
fa21b5e3 EV |
2423 | _cleanup_strv_free_ char **l = NULL; |
2424 | char **p; | |
2425 | ||
2426 | r = sd_bus_message_read_strv(message, &l); | |
2427 | if (r < 0) | |
2428 | return r; | |
2429 | ||
2430 | STRV_FOREACH(p, l) { | |
8994a117 YW |
2431 | if (!path_is_normalized(*p)) |
2432 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is not normalized: %s", name, *p); | |
2433 | ||
2434 | if (path_is_absolute(*p)) | |
2435 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is absolute: %s", name, *p); | |
2436 | ||
2437 | if (path_startswith(*p, "private")) | |
2438 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path can't be 'private': %s", name, *p); | |
fa21b5e3 EV |
2439 | } |
2440 | ||
2e59b241 | 2441 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
3536f49e | 2442 | ExecDirectoryType i; |
b1ea85dc | 2443 | ExecDirectory *d; |
3536f49e | 2444 | |
b1ea85dc LP |
2445 | assert_se((i = exec_directory_type_from_string(name)) >= 0); |
2446 | d = c->directories + i; | |
fa21b5e3 EV |
2447 | |
2448 | if (strv_isempty(l)) { | |
b1ea85dc | 2449 | d->paths = strv_free(d->paths); |
2e59b241 | 2450 | unit_write_settingf(u, flags, name, "%s=", name); |
fa21b5e3 | 2451 | } else { |
2e59b241 LP |
2452 | _cleanup_free_ char *joined = NULL; |
2453 | ||
b1ea85dc | 2454 | r = strv_extend_strv(&d->paths, l, true); |
fa21b5e3 | 2455 | if (r < 0) |
c425c7c2 | 2456 | return r; |
fa21b5e3 | 2457 | |
2e59b241 | 2458 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS); |
fa21b5e3 EV |
2459 | if (!joined) |
2460 | return -ENOMEM; | |
2461 | ||
2e59b241 | 2462 | unit_write_settingf(u, flags, name, "%s=%s", name, joined); |
fa21b5e3 EV |
2463 | } |
2464 | } | |
2465 | ||
2466 | return 1; | |
2467 | ||
cffaed83 YW |
2468 | } else if (STR_IN_SET(name, "AppArmorProfile", "SmackProcessLabel")) { |
2469 | int ignore; | |
2470 | const char *s; | |
2471 | ||
280921f2 | 2472 | r = sd_bus_message_read(message, "(bs)", &ignore, &s); |
cffaed83 YW |
2473 | if (r < 0) |
2474 | return r; | |
2475 | ||
2e59b241 | 2476 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 YW |
2477 | char **p; |
2478 | bool *b; | |
2479 | ||
2480 | if (streq(name, "AppArmorProfile")) { | |
2481 | p = &c->apparmor_profile; | |
2482 | b = &c->apparmor_profile_ignore; | |
2483 | } else { /* "SmackProcessLabel" */ | |
2484 | p = &c->smack_process_label; | |
2485 | b = &c->smack_process_label_ignore; | |
2486 | } | |
2487 | ||
2488 | if (isempty(s)) { | |
2489 | *p = mfree(*p); | |
2490 | *b = false; | |
2491 | } else { | |
2492 | if (free_and_strdup(p, s) < 0) | |
2493 | return -ENOMEM; | |
2494 | *b = ignore; | |
2495 | } | |
2496 | ||
2e59b241 | 2497 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s%s", name, ignore ? "-" : "", strempty(s)); |
cffaed83 YW |
2498 | } |
2499 | ||
2500 | return 1; | |
2501 | ||
d2d6c096 | 2502 | } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) { |
ec04aef4 | 2503 | char *source, *destination; |
4ff4c98a YW |
2504 | int ignore_enoent; |
2505 | uint64_t mount_flags; | |
2506 | bool empty = true; | |
d2d6c096 LP |
2507 | |
2508 | r = sd_bus_message_enter_container(message, 'a', "(ssbt)"); | |
2509 | if (r < 0) | |
2510 | return r; | |
2511 | ||
4ff4c98a | 2512 | while ((r = sd_bus_message_read(message, "(ssbt)", &source, &destination, &ignore_enoent, &mount_flags)) > 0) { |
d2d6c096 LP |
2513 | |
2514 | if (!path_is_absolute(source)) | |
2515 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source); | |
2516 | if (!path_is_absolute(destination)) | |
91d910e3 | 2517 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination); |
d2d6c096 LP |
2518 | if (!IN_SET(mount_flags, 0, MS_REC)) |
2519 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount flags."); | |
2520 | ||
2e59b241 | 2521 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
d2d6c096 LP |
2522 | r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts, |
2523 | &(BindMount) { | |
ec04aef4 TM |
2524 | .source = source, |
2525 | .destination = destination, | |
d2d6c096 LP |
2526 | .read_only = !!strstr(name, "ReadOnly"), |
2527 | .recursive = !!(mount_flags & MS_REC), | |
2528 | .ignore_enoent = ignore_enoent, | |
2529 | }); | |
2530 | if (r < 0) | |
2531 | return r; | |
2532 | ||
2e59b241 LP |
2533 | unit_write_settingf( |
2534 | u, flags|UNIT_ESCAPE_SPECIFIERS, name, | |
d2d6c096 LP |
2535 | "%s=%s%s:%s:%s", |
2536 | name, | |
2537 | ignore_enoent ? "-" : "", | |
2538 | source, | |
2539 | destination, | |
2540 | (mount_flags & MS_REC) ? "rbind" : "norbind"); | |
2541 | } | |
2542 | ||
2543 | empty = false; | |
2544 | } | |
2545 | if (r < 0) | |
2546 | return r; | |
2547 | ||
2548 | r = sd_bus_message_exit_container(message); | |
2549 | if (r < 0) | |
2550 | return r; | |
2551 | ||
2552 | if (empty) { | |
2553 | bind_mount_free_many(c->bind_mounts, c->n_bind_mounts); | |
2554 | c->bind_mounts = NULL; | |
2555 | c->n_bind_mounts = 0; | |
2e59b241 LP |
2556 | |
2557 | unit_write_settingf(u, flags, name, "%s=", name); | |
d2d6c096 LP |
2558 | } |
2559 | ||
784ad252 YW |
2560 | return 1; |
2561 | ||
2562 | } else if (streq(name, "TemporaryFileSystem")) { | |
2563 | const char *path, *options; | |
2564 | bool empty = true; | |
2565 | ||
2566 | r = sd_bus_message_enter_container(message, 'a', "(ss)"); | |
2567 | if (r < 0) | |
2568 | return r; | |
2569 | ||
2570 | while ((r = sd_bus_message_read(message, "(ss)", &path, &options)) > 0) { | |
2571 | ||
2572 | if (!path_is_absolute(path)) | |
2573 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Mount point %s is not absolute.", path); | |
2574 | ||
2575 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2576 | r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options); | |
2577 | if (r < 0) | |
2578 | return r; | |
2579 | ||
2580 | unit_write_settingf( | |
2581 | u, flags|UNIT_ESCAPE_SPECIFIERS, name, | |
2582 | "%s=%s:%s", | |
2583 | name, | |
2584 | path, | |
2585 | options); | |
2586 | } | |
2587 | ||
2588 | empty = false; | |
2589 | } | |
2590 | if (r < 0) | |
2591 | return r; | |
2592 | ||
2593 | r = sd_bus_message_exit_container(message); | |
2594 | if (r < 0) | |
2595 | return r; | |
2596 | ||
2597 | if (empty) { | |
2598 | temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems); | |
2599 | c->temporary_filesystems = NULL; | |
2600 | c->n_temporary_filesystems = 0; | |
2601 | ||
2602 | unit_write_settingf(u, flags, name, "%s=", name); | |
2603 | } | |
2604 | ||
83555251 | 2605 | return 1; |
d2d6c096 | 2606 | |
6550c24c LP |
2607 | } else if ((suffix = startswith(name, "Limit"))) { |
2608 | const char *soft = NULL; | |
2609 | int ri; | |
cab2aca3 | 2610 | |
6550c24c LP |
2611 | ri = rlimit_from_string(suffix); |
2612 | if (ri < 0) { | |
2613 | soft = endswith(suffix, "Soft"); | |
2614 | if (soft) { | |
2615 | const char *n; | |
cab2aca3 | 2616 | |
6550c24c LP |
2617 | n = strndupa(suffix, soft - suffix); |
2618 | ri = rlimit_from_string(n); | |
2619 | if (ri >= 0) | |
2620 | name = strjoina("Limit", n); | |
2621 | } | |
cab2aca3 | 2622 | } |
d584f638 | 2623 | |
6550c24c LP |
2624 | if (ri >= 0) { |
2625 | uint64_t rl; | |
2626 | rlim_t x; | |
d584f638 | 2627 | |
6550c24c | 2628 | r = sd_bus_message_read(message, "t", &rl); |
cab2aca3 LP |
2629 | if (r < 0) |
2630 | return r; | |
d584f638 | 2631 | |
6550c24c LP |
2632 | if (rl == (uint64_t) -1) |
2633 | x = RLIM_INFINITY; | |
cab2aca3 | 2634 | else { |
6550c24c LP |
2635 | x = (rlim_t) rl; |
2636 | ||
2637 | if ((uint64_t) x != rl) | |
2638 | return -ERANGE; | |
d584f638 LP |
2639 | } |
2640 | ||
6550c24c LP |
2641 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
2642 | _cleanup_free_ char *f = NULL; | |
2643 | struct rlimit nl; | |
2644 | ||
2645 | if (c->rlimit[ri]) { | |
2646 | nl = *c->rlimit[ri]; | |
2647 | ||
2648 | if (soft) | |
2649 | nl.rlim_cur = x; | |
2650 | else | |
2651 | nl.rlim_max = x; | |
2652 | } else | |
2653 | /* When the resource limit is not initialized yet, then assign the value to both fields */ | |
2654 | nl = (struct rlimit) { | |
2655 | .rlim_cur = x, | |
2656 | .rlim_max = x, | |
2657 | }; | |
2658 | ||
2659 | r = rlimit_format(&nl, &f); | |
2660 | if (r < 0) | |
2661 | return r; | |
2662 | ||
2663 | if (c->rlimit[ri]) | |
2664 | *c->rlimit[ri] = nl; | |
2665 | else { | |
2666 | c->rlimit[ri] = newdup(struct rlimit, &nl, 1); | |
2667 | if (!c->rlimit[ri]) | |
2668 | return -ENOMEM; | |
2669 | } | |
2670 | ||
2671 | unit_write_settingf(u, flags, name, "%s=%s", name, f); | |
2672 | } | |
2673 | ||
2674 | return 1; | |
d584f638 LP |
2675 | } |
2676 | ||
c7040b5d LP |
2677 | } |
2678 | ||
2679 | return 0; | |
2680 | } |