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