1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
10 #include <stdio_ext.h>
17 #include "alloc-util.h"
20 #include "capability-util.h"
21 #include "cpu-set-util.h"
22 #include "dbus-execute.h"
23 #include "dbus-util.h"
25 #include "errno-list.h"
30 #include "hexdecoct.h"
33 #include "journal-util.h"
35 #include "mount-util.h"
36 #include "namespace.h"
37 #include "parse-util.h"
38 #include "path-util.h"
39 #include "process-util.h"
40 #include "rlimit-util.h"
42 #include "seccomp-util.h"
44 #include "securebits-util.h"
45 #include "specifier.h"
47 #include "syslog-util.h"
48 #include "unit-printf.h"
49 #include "user-util.h"
52 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output
, exec_output
, ExecOutput
);
53 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input
, exec_input
, ExecInput
);
54 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
);
55 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
);
56 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
);
57 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home
, protect_home
, ProtectHome
);
58 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system
, protect_system
, ProtectSystem
);
59 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality
, personality
, unsigned long);
60 static BUS_DEFINE_PROPERTY_GET(property_get_ioprio
, "i", ExecContext
, exec_context_get_effective_ioprio
);
61 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class
, "i", ExecContext
, exec_context_get_effective_ioprio
, IOPRIO_PRIO_CLASS
);
62 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority
, "i", ExecContext
, exec_context_get_effective_ioprio
, IOPRIO_PRIO_DATA
);
63 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string
, "s", NULL
);
64 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level
, "i", int, LOG_PRI
);
65 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility
, "i", int, LOG_FAC
);
67 static int property_get_environment_files(
70 const char *interface
,
72 sd_bus_message
*reply
,
74 sd_bus_error
*error
) {
76 ExecContext
*c
= userdata
;
84 r
= sd_bus_message_open_container(reply
, 'a', "(sb)");
88 STRV_FOREACH(j
, c
->environment_files
) {
91 r
= sd_bus_message_append(reply
, "(sb)", fn
[0] == '-' ? fn
+ 1 : fn
, fn
[0] == '-');
96 return sd_bus_message_close_container(reply
);
99 static int property_get_oom_score_adjust(
102 const char *interface
,
103 const char *property
,
104 sd_bus_message
*reply
,
106 sd_bus_error
*error
) {
108 ExecContext
*c
= userdata
;
115 if (c
->oom_score_adjust_set
)
116 n
= c
->oom_score_adjust
;
118 _cleanup_free_
char *t
= NULL
;
121 if (read_one_line_file("/proc/self/oom_score_adj", &t
) >= 0)
125 return sd_bus_message_append(reply
, "i", n
);
128 static int property_get_nice(
131 const char *interface
,
132 const char *property
,
133 sd_bus_message
*reply
,
135 sd_bus_error
*error
) {
137 ExecContext
*c
= userdata
;
148 n
= getpriority(PRIO_PROCESS
, 0);
153 return sd_bus_message_append(reply
, "i", n
);
156 static int property_get_cpu_sched_policy(
159 const char *interface
,
160 const char *property
,
161 sd_bus_message
*reply
,
163 sd_bus_error
*error
) {
165 ExecContext
*c
= userdata
;
172 if (c
->cpu_sched_set
)
173 n
= c
->cpu_sched_policy
;
175 n
= sched_getscheduler(0);
180 return sd_bus_message_append(reply
, "i", n
);
183 static int property_get_cpu_sched_priority(
186 const char *interface
,
187 const char *property
,
188 sd_bus_message
*reply
,
190 sd_bus_error
*error
) {
192 ExecContext
*c
= userdata
;
199 if (c
->cpu_sched_set
)
200 n
= c
->cpu_sched_priority
;
202 struct sched_param p
= {};
204 if (sched_getparam(0, &p
) >= 0)
205 n
= p
.sched_priority
;
210 return sd_bus_message_append(reply
, "i", n
);
213 static int property_get_cpu_affinity(
216 const char *interface
,
217 const char *property
,
218 sd_bus_message
*reply
,
220 sd_bus_error
*error
) {
222 ExecContext
*c
= userdata
;
228 return sd_bus_message_append_array(reply
, 'y', c
->cpuset
, CPU_ALLOC_SIZE(c
->cpuset_ncpus
));
231 static int property_get_timer_slack_nsec(
234 const char *interface
,
235 const char *property
,
236 sd_bus_message
*reply
,
238 sd_bus_error
*error
) {
240 ExecContext
*c
= userdata
;
247 if (c
->timer_slack_nsec
!= NSEC_INFINITY
)
248 u
= (uint64_t) c
->timer_slack_nsec
;
250 u
= (uint64_t) prctl(PR_GET_TIMERSLACK
);
252 return sd_bus_message_append(reply
, "t", u
);
255 static int property_get_syscall_filter(
258 const char *interface
,
259 const char *property
,
260 sd_bus_message
*reply
,
262 sd_bus_error
*error
) {
264 ExecContext
*c
= userdata
;
265 _cleanup_strv_free_
char **l
= NULL
;
277 r
= sd_bus_message_open_container(reply
, 'r', "bas");
281 r
= sd_bus_message_append(reply
, "b", c
->syscall_whitelist
);
286 HASHMAP_FOREACH_KEY(val
, id
, c
->syscall_filter
, i
) {
287 _cleanup_free_
char *name
= NULL
;
288 const char *e
= NULL
;
290 int num
= PTR_TO_INT(val
);
292 name
= seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE
, PTR_TO_INT(id
) - 1);
297 e
= errno_to_name(num
);
299 s
= strjoin(name
, ":", e
);
303 r
= asprintf(&s
, "%s:%d", name
, num
);
310 r
= strv_consume(&l
, s
);
318 r
= sd_bus_message_append_strv(reply
, l
);
322 return sd_bus_message_close_container(reply
);
325 static int property_get_syscall_archs(
328 const char *interface
,
329 const char *property
,
330 sd_bus_message
*reply
,
332 sd_bus_error
*error
) {
334 ExecContext
*c
= userdata
;
335 _cleanup_strv_free_
char **l
= NULL
;
348 SET_FOREACH(id
, c
->syscall_archs
, i
) {
351 name
= seccomp_arch_to_string(PTR_TO_UINT32(id
) - 1);
355 r
= strv_extend(&l
, name
);
363 r
= sd_bus_message_append_strv(reply
, l
);
370 static int property_get_selinux_context(
373 const char *interface
,
374 const char *property
,
375 sd_bus_message
*reply
,
377 sd_bus_error
*error
) {
379 ExecContext
*c
= userdata
;
385 return sd_bus_message_append(reply
, "(bs)", c
->selinux_context_ignore
, c
->selinux_context
);
388 static int property_get_apparmor_profile(
391 const char *interface
,
392 const char *property
,
393 sd_bus_message
*reply
,
395 sd_bus_error
*error
) {
397 ExecContext
*c
= userdata
;
403 return sd_bus_message_append(reply
, "(bs)", c
->apparmor_profile_ignore
, c
->apparmor_profile
);
406 static int property_get_smack_process_label(
409 const char *interface
,
410 const char *property
,
411 sd_bus_message
*reply
,
413 sd_bus_error
*error
) {
415 ExecContext
*c
= userdata
;
421 return sd_bus_message_append(reply
, "(bs)", c
->smack_process_label_ignore
, c
->smack_process_label
);
424 static int property_get_address_families(
427 const char *interface
,
428 const char *property
,
429 sd_bus_message
*reply
,
431 sd_bus_error
*error
) {
433 ExecContext
*c
= userdata
;
434 _cleanup_strv_free_
char **l
= NULL
;
443 r
= sd_bus_message_open_container(reply
, 'r', "bas");
447 r
= sd_bus_message_append(reply
, "b", c
->address_families_whitelist
);
451 SET_FOREACH(af
, c
->address_families
, i
) {
454 name
= af_to_name(PTR_TO_INT(af
));
458 r
= strv_extend(&l
, name
);
465 r
= sd_bus_message_append_strv(reply
, l
);
469 return sd_bus_message_close_container(reply
);
472 static int property_get_working_directory(
475 const char *interface
,
476 const char *property
,
477 sd_bus_message
*reply
,
479 sd_bus_error
*error
) {
481 ExecContext
*c
= userdata
;
488 if (c
->working_directory_home
)
491 wd
= c
->working_directory
;
493 if (c
->working_directory_missing_ok
)
494 wd
= strjoina("!", wd
);
496 return sd_bus_message_append(reply
, "s", wd
);
499 static int property_get_stdio_fdname(
502 const char *interface
,
503 const char *property
,
504 sd_bus_message
*reply
,
506 sd_bus_error
*error
) {
508 ExecContext
*c
= userdata
;
516 if (streq(property
, "StandardInputFileDescriptorName"))
517 fileno
= STDIN_FILENO
;
518 else if (streq(property
, "StandardOutputFileDescriptorName"))
519 fileno
= STDOUT_FILENO
;
521 assert(streq(property
, "StandardErrorFileDescriptorName"));
522 fileno
= STDERR_FILENO
;
525 return sd_bus_message_append(reply
, "s", exec_context_fdname(c
, fileno
));
528 static int property_get_input_data(
531 const char *interface
,
532 const char *property
,
533 sd_bus_message
*reply
,
535 sd_bus_error
*error
) {
537 ExecContext
*c
= userdata
;
544 return sd_bus_message_append_array(reply
, 'y', c
->stdin_data
, c
->stdin_data_size
);
547 static int property_get_bind_paths(
550 const char *interface
,
551 const char *property
,
552 sd_bus_message
*reply
,
554 sd_bus_error
*error
) {
556 ExecContext
*c
= userdata
;
566 ro
= !!strstr(property
, "ReadOnly");
568 r
= sd_bus_message_open_container(reply
, 'a', "(ssbt)");
572 for (i
= 0; i
< c
->n_bind_mounts
; i
++) {
574 if (ro
!= c
->bind_mounts
[i
].read_only
)
577 r
= sd_bus_message_append(
579 c
->bind_mounts
[i
].source
,
580 c
->bind_mounts
[i
].destination
,
581 c
->bind_mounts
[i
].ignore_enoent
,
582 c
->bind_mounts
[i
].recursive
? (uint64_t) MS_REC
: (uint64_t) 0);
587 return sd_bus_message_close_container(reply
);
590 static int property_get_temporary_filesystems(
593 const char *interface
,
594 const char *property
,
595 sd_bus_message
*reply
,
597 sd_bus_error
*error
) {
599 ExecContext
*c
= userdata
;
608 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
612 for (i
= 0; i
< c
->n_temporary_filesystems
; i
++) {
613 TemporaryFileSystem
*t
= c
->temporary_filesystems
+ i
;
615 r
= sd_bus_message_append(
623 return sd_bus_message_close_container(reply
);
626 static int property_get_log_extra_fields(
629 const char *interface
,
630 const char *property
,
631 sd_bus_message
*reply
,
633 sd_bus_error
*error
) {
635 ExecContext
*c
= userdata
;
644 r
= sd_bus_message_open_container(reply
, 'a', "ay");
648 for (i
= 0; i
< c
->n_log_extra_fields
; i
++) {
649 r
= sd_bus_message_append_array(reply
, 'y', c
->log_extra_fields
[i
].iov_base
, c
->log_extra_fields
[i
].iov_len
);
654 return sd_bus_message_close_container(reply
);
657 const sd_bus_vtable bus_exec_vtable
[] = {
658 SD_BUS_VTABLE_START(0),
659 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(ExecContext
, environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
660 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
661 SD_BUS_PROPERTY("PassEnvironment", "as", NULL
, offsetof(ExecContext
, pass_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
662 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL
, offsetof(ExecContext
, unset_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
663 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode
, offsetof(ExecContext
, umask
), SD_BUS_VTABLE_PROPERTY_CONST
),
664 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
665 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
666 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
667 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
668 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
669 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
670 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
671 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
672 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
673 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
674 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
675 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
676 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
677 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
678 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
679 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
680 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
681 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
682 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
683 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
684 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
685 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
686 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
687 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
688 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
689 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
690 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
691 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
692 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
693 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
694 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
695 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
696 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
697 SD_BUS_PROPERTY("RootDirectory", "s", NULL
, offsetof(ExecContext
, root_directory
), SD_BUS_VTABLE_PROPERTY_CONST
),
698 SD_BUS_PROPERTY("RootImage", "s", NULL
, offsetof(ExecContext
, root_image
), SD_BUS_VTABLE_PROPERTY_CONST
),
699 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
700 SD_BUS_PROPERTY("Nice", "i", property_get_nice
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
701 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
702 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
703 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
704 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
705 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
706 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
707 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool
, offsetof(ExecContext
, cpu_sched_reset_on_fork
), SD_BUS_VTABLE_PROPERTY_CONST
),
708 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool
, offsetof(ExecContext
, non_blocking
), SD_BUS_VTABLE_PROPERTY_CONST
),
709 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input
, offsetof(ExecContext
, std_input
), SD_BUS_VTABLE_PROPERTY_CONST
),
710 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
711 SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
712 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
713 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
714 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_error
), SD_BUS_VTABLE_PROPERTY_CONST
),
715 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
716 SD_BUS_PROPERTY("TTYPath", "s", NULL
, offsetof(ExecContext
, tty_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
717 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_reset
), SD_BUS_VTABLE_PROPERTY_CONST
),
718 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vhangup
), SD_BUS_VTABLE_PROPERTY_CONST
),
719 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vt_disallocate
), SD_BUS_VTABLE_PROPERTY_CONST
),
720 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
721 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL
, offsetof(ExecContext
, syslog_identifier
), SD_BUS_VTABLE_PROPERTY_CONST
),
722 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool
, offsetof(ExecContext
, syslog_level_prefix
), SD_BUS_VTABLE_PROPERTY_CONST
),
723 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
724 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
725 SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int
, offsetof(ExecContext
, log_level_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
726 SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
727 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int
, offsetof(ExecContext
, secure_bits
), SD_BUS_VTABLE_PROPERTY_CONST
),
728 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL
, offsetof(ExecContext
, capability_bounding_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
729 SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL
, offsetof(ExecContext
, capability_ambient_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
730 SD_BUS_PROPERTY("User", "s", NULL
, offsetof(ExecContext
, user
), SD_BUS_VTABLE_PROPERTY_CONST
),
731 SD_BUS_PROPERTY("Group", "s", NULL
, offsetof(ExecContext
, group
), SD_BUS_VTABLE_PROPERTY_CONST
),
732 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool
, offsetof(ExecContext
, dynamic_user
), SD_BUS_VTABLE_PROPERTY_CONST
),
733 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, remove_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
734 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL
, offsetof(ExecContext
, supplementary_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
735 SD_BUS_PROPERTY("PAMName", "s", NULL
, offsetof(ExecContext
, pam_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
736 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
737 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
738 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
739 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong
, offsetof(ExecContext
, mount_flags
), SD_BUS_VTABLE_PROPERTY_CONST
),
740 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool
, offsetof(ExecContext
, private_tmp
), SD_BUS_VTABLE_PROPERTY_CONST
),
741 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool
, offsetof(ExecContext
, private_devices
), SD_BUS_VTABLE_PROPERTY_CONST
),
742 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_tunables
), SD_BUS_VTABLE_PROPERTY_CONST
),
743 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_modules
), SD_BUS_VTABLE_PROPERTY_CONST
),
744 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_control_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
745 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool
, offsetof(ExecContext
, private_network
), SD_BUS_VTABLE_PROPERTY_CONST
),
746 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool
, offsetof(ExecContext
, private_users
), SD_BUS_VTABLE_PROPERTY_CONST
),
747 SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_bool
, offsetof(ExecContext
, private_mounts
), SD_BUS_VTABLE_PROPERTY_CONST
),
748 SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home
, offsetof(ExecContext
, protect_home
), SD_BUS_VTABLE_PROPERTY_CONST
),
749 SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system
, offsetof(ExecContext
, protect_system
), SD_BUS_VTABLE_PROPERTY_CONST
),
750 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool
, offsetof(ExecContext
, same_pgrp
), SD_BUS_VTABLE_PROPERTY_CONST
),
751 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL
, offsetof(ExecContext
, utmp_id
), SD_BUS_VTABLE_PROPERTY_CONST
),
752 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode
, offsetof(ExecContext
, utmp_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
753 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
754 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
755 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
756 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool
, offsetof(ExecContext
, ignore_sigpipe
), SD_BUS_VTABLE_PROPERTY_CONST
),
757 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool
, offsetof(ExecContext
, no_new_privileges
), SD_BUS_VTABLE_PROPERTY_CONST
),
758 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
759 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
760 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int
, offsetof(ExecContext
, syscall_errno
), SD_BUS_VTABLE_PROPERTY_CONST
),
761 SD_BUS_PROPERTY("Personality", "s", property_get_personality
, offsetof(ExecContext
, personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
762 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool
, offsetof(ExecContext
, lock_personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
763 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
764 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode
, offsetof(ExecContext
, runtime_directory_preserve_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
765 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
766 SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
767 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
768 SD_BUS_PROPERTY("StateDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
769 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
770 SD_BUS_PROPERTY("CacheDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
771 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
772 SD_BUS_PROPERTY("LogsDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
773 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
774 SD_BUS_PROPERTY("ConfigurationDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
775 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool
, offsetof(ExecContext
, memory_deny_write_execute
), SD_BUS_VTABLE_PROPERTY_CONST
),
776 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_realtime
), SD_BUS_VTABLE_PROPERTY_CONST
),
777 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong
, offsetof(ExecContext
, restrict_namespaces
), SD_BUS_VTABLE_PROPERTY_CONST
),
778 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
779 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
780 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
781 SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool
, offsetof(ExecContext
, mount_apivfs
), SD_BUS_VTABLE_PROPERTY_CONST
),
782 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode
, offsetof(ExecContext
, keyring_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
784 /* Obsolete/redundant properties: */
785 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
786 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
787 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
788 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
789 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
794 static int append_exec_command(sd_bus_message
*reply
, ExecCommand
*c
) {
803 r
= sd_bus_message_open_container(reply
, 'r', "sasbttttuii");
807 r
= sd_bus_message_append(reply
, "s", c
->path
);
811 r
= sd_bus_message_append_strv(reply
, c
->argv
);
815 r
= sd_bus_message_append(reply
, "bttttuii",
816 !!(c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
),
817 c
->exec_status
.start_timestamp
.realtime
,
818 c
->exec_status
.start_timestamp
.monotonic
,
819 c
->exec_status
.exit_timestamp
.realtime
,
820 c
->exec_status
.exit_timestamp
.monotonic
,
821 (uint32_t) c
->exec_status
.pid
,
822 (int32_t) c
->exec_status
.code
,
823 (int32_t) c
->exec_status
.status
);
827 return sd_bus_message_close_container(reply
);
830 int bus_property_get_exec_command(
833 const char *interface
,
834 const char *property
,
835 sd_bus_message
*reply
,
837 sd_bus_error
*ret_error
) {
839 ExecCommand
*c
= (ExecCommand
*) userdata
;
845 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
849 r
= append_exec_command(reply
, c
);
853 return sd_bus_message_close_container(reply
);
856 int bus_property_get_exec_command_list(
859 const char *interface
,
860 const char *property
,
861 sd_bus_message
*reply
,
863 sd_bus_error
*ret_error
) {
865 ExecCommand
*c
= *(ExecCommand
**) userdata
;
871 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
875 LIST_FOREACH(command
, c
, c
) {
876 r
= append_exec_command(reply
, c
);
881 return sd_bus_message_close_container(reply
);
884 int bus_set_transient_exec_command(
887 ExecCommand
**exec_command
,
888 sd_bus_message
*message
,
889 UnitWriteFlags flags
,
890 sd_bus_error
*error
) {
894 r
= sd_bus_message_enter_container(message
, 'a', "(sasb)");
898 while ((r
= sd_bus_message_enter_container(message
, 'r', "sasb")) > 0) {
899 _cleanup_strv_free_
char **argv
= NULL
;
903 r
= sd_bus_message_read(message
, "s", &path
);
907 if (!path_is_absolute(path
))
908 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
910 r
= sd_bus_message_read_strv(message
, &argv
);
914 r
= sd_bus_message_read(message
, "b", &b
);
918 r
= sd_bus_message_exit_container(message
);
922 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
925 c
= new0(ExecCommand
, 1);
929 c
->path
= strdup(path
);
935 c
->argv
= TAKE_PTR(argv
);
937 c
->flags
= b
? EXEC_COMMAND_IGNORE_FAILURE
: 0;
939 path_simplify(c
->path
, false);
940 exec_command_append_list(exec_command
, c
);
948 r
= sd_bus_message_exit_container(message
);
952 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
953 _cleanup_free_
char *buf
= NULL
;
954 _cleanup_fclose_
FILE *f
= NULL
;
959 *exec_command
= exec_command_free_list(*exec_command
);
961 f
= open_memstream(&buf
, &size
);
965 (void) __fsetlocking(f
, FSETLOCKING_BYCALLER
);
967 fputs("ExecStart=\n", f
);
969 LIST_FOREACH(command
, c
, *exec_command
) {
970 _cleanup_free_
char *a
= NULL
, *t
= NULL
;
973 p
= unit_escape_setting(c
->path
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
, &t
);
977 a
= unit_concat_strv(c
->argv
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
);
981 fprintf(f
, "%s=%s@%s %s\n",
983 c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
? "-" : "",
988 r
= fflush_and_check(f
);
992 unit_write_setting(u
, flags
, name
, buf
);
998 static int parse_personality(const char *s
, unsigned long *p
) {
1003 v
= personality_from_string(s
);
1004 if (v
== PERSONALITY_INVALID
)
1011 static const char* mount_propagation_flags_to_string_with_check(unsigned long n
) {
1012 if (!IN_SET(n
, 0, MS_SHARED
, MS_PRIVATE
, MS_SLAVE
))
1015 return mount_propagation_flags_to_string(n
);
1018 static BUS_DEFINE_SET_TRANSIENT(nsec
, "t", uint64_t, nsec_t
, NSEC_FMT
);
1019 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level
, "i", int32_t, int, "%" PRIi32
, log_level_is_valid
);
1021 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno
, "i", int32_t, int, "%" PRIi32
, errno_is_valid
);
1023 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(sched_priority
, "i", int32_t, int, "%" PRIi32
, sched_priority_is_valid
);
1024 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(nice
, "i", int32_t, int, "%" PRIi32
, nice_is_valid
);
1025 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input
, ExecInput
, exec_input_from_string
);
1026 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output
, ExecOutput
, exec_output_from_string
);
1027 static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode
, ExecUtmpMode
, exec_utmp_mode_from_string
);
1028 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system
, ProtectSystem
, protect_system_or_bool_from_string
);
1029 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home
, ProtectHome
, protect_home_or_bool_from_string
);
1030 static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode
, ExecKeyringMode
, exec_keyring_mode_from_string
);
1031 static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode
, ExecPreserveMode
, exec_preserve_mode_from_string
);
1032 static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality
, unsigned long, parse_personality
);
1033 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits
, "i", int32_t, int, "%" PRIi32
, secure_bits_to_string_alloc_with_check
);
1034 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability
, "t", uint64_t, uint64_t, "%" PRIu64
, capability_set_to_string_alloc
);
1035 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(sched_policy
, "i", int32_t, int, "%" PRIi32
, sched_policy_to_string_alloc_with_check
);
1036 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag
, "t", uint64_t, unsigned long, "%" PRIu64
, namespace_flags_to_string
);
1037 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags
, "t", uint64_t, unsigned long, "%" PRIu64
, mount_propagation_flags_to_string_with_check
);
1039 int bus_exec_context_set_transient_property(
1043 sd_bus_message
*message
,
1044 UnitWriteFlags flags
,
1045 sd_bus_error
*error
) {
1055 flags
|= UNIT_PRIVATE
;
1057 if (streq(name
, "User"))
1058 return bus_set_transient_user(u
, name
, &c
->user
, message
, flags
, error
);
1060 if (streq(name
, "Group"))
1061 return bus_set_transient_user(u
, name
, &c
->group
, message
, flags
, error
);
1063 if (streq(name
, "TTYPath"))
1064 return bus_set_transient_path(u
, name
, &c
->tty_path
, message
, flags
, error
);
1066 if (streq(name
, "RootImage"))
1067 return bus_set_transient_path(u
, name
, &c
->root_image
, message
, flags
, error
);
1069 if (streq(name
, "RootDirectory"))
1070 return bus_set_transient_path(u
, name
, &c
->root_directory
, message
, flags
, error
);
1072 if (streq(name
, "SyslogIdentifier"))
1073 return bus_set_transient_string(u
, name
, &c
->syslog_identifier
, message
, flags
, error
);
1075 if (streq(name
, "LogLevelMax"))
1076 return bus_set_transient_log_level(u
, name
, &c
->log_level_max
, message
, flags
, error
);
1078 if (streq(name
, "CPUSchedulingPriority"))
1079 return bus_set_transient_sched_priority(u
, name
, &c
->cpu_sched_priority
, message
, flags
, error
);
1081 if (streq(name
, "Personality"))
1082 return bus_set_transient_personality(u
, name
, &c
->personality
, message
, flags
, error
);
1084 if (streq(name
, "Nice"))
1085 return bus_set_transient_nice(u
, name
, &c
->nice
, message
, flags
, error
);
1087 if (streq(name
, "StandardInput"))
1088 return bus_set_transient_std_input(u
, name
, &c
->std_input
, message
, flags
, error
);
1090 if (streq(name
, "StandardOutput"))
1091 return bus_set_transient_std_output(u
, name
, &c
->std_output
, message
, flags
, error
);
1093 if (streq(name
, "StandardError"))
1094 return bus_set_transient_std_output(u
, name
, &c
->std_error
, message
, flags
, error
);
1096 if (streq(name
, "IgnoreSIGPIPE"))
1097 return bus_set_transient_bool(u
, name
, &c
->ignore_sigpipe
, message
, flags
, error
);
1099 if (streq(name
, "TTYVHangup"))
1100 return bus_set_transient_bool(u
, name
, &c
->tty_vhangup
, message
, flags
, error
);
1102 if (streq(name
, "TTYReset"))
1103 return bus_set_transient_bool(u
, name
, &c
->tty_reset
, message
, flags
, error
);
1105 if (streq(name
, "TTYVTDisallocate"))
1106 return bus_set_transient_bool(u
, name
, &c
->tty_vt_disallocate
, message
, flags
, error
);
1108 if (streq(name
, "PrivateTmp"))
1109 return bus_set_transient_bool(u
, name
, &c
->private_tmp
, message
, flags
, error
);
1111 if (streq(name
, "PrivateDevices"))
1112 return bus_set_transient_bool(u
, name
, &c
->private_devices
, message
, flags
, error
);
1114 if (streq(name
, "PrivateMounts"))
1115 return bus_set_transient_bool(u
, name
, &c
->private_mounts
, message
, flags
, error
);
1117 if (streq(name
, "PrivateNetwork"))
1118 return bus_set_transient_bool(u
, name
, &c
->private_network
, message
, flags
, error
);
1120 if (streq(name
, "PrivateUsers"))
1121 return bus_set_transient_bool(u
, name
, &c
->private_users
, message
, flags
, error
);
1123 if (streq(name
, "NoNewPrivileges"))
1124 return bus_set_transient_bool(u
, name
, &c
->no_new_privileges
, message
, flags
, error
);
1126 if (streq(name
, "SyslogLevelPrefix"))
1127 return bus_set_transient_bool(u
, name
, &c
->syslog_level_prefix
, message
, flags
, error
);
1129 if (streq(name
, "MemoryDenyWriteExecute"))
1130 return bus_set_transient_bool(u
, name
, &c
->memory_deny_write_execute
, message
, flags
, error
);
1132 if (streq(name
, "RestrictRealtime"))
1133 return bus_set_transient_bool(u
, name
, &c
->restrict_realtime
, message
, flags
, error
);
1135 if (streq(name
, "DynamicUser"))
1136 return bus_set_transient_bool(u
, name
, &c
->dynamic_user
, message
, flags
, error
);
1138 if (streq(name
, "RemoveIPC"))
1139 return bus_set_transient_bool(u
, name
, &c
->remove_ipc
, message
, flags
, error
);
1141 if (streq(name
, "ProtectKernelTunables"))
1142 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_tunables
, message
, flags
, error
);
1144 if (streq(name
, "ProtectKernelModules"))
1145 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_modules
, message
, flags
, error
);
1147 if (streq(name
, "ProtectControlGroups"))
1148 return bus_set_transient_bool(u
, name
, &c
->protect_control_groups
, message
, flags
, error
);
1150 if (streq(name
, "MountAPIVFS"))
1151 return bus_set_transient_bool(u
, name
, &c
->mount_apivfs
, message
, flags
, error
);
1153 if (streq(name
, "CPUSchedulingResetOnFork"))
1154 return bus_set_transient_bool(u
, name
, &c
->cpu_sched_reset_on_fork
, message
, flags
, error
);
1156 if (streq(name
, "NonBlocking"))
1157 return bus_set_transient_bool(u
, name
, &c
->non_blocking
, message
, flags
, error
);
1159 if (streq(name
, "LockPersonality"))
1160 return bus_set_transient_bool(u
, name
, &c
->lock_personality
, message
, flags
, error
);
1162 if (streq(name
, "UtmpIdentifier"))
1163 return bus_set_transient_string(u
, name
, &c
->utmp_id
, message
, flags
, error
);
1165 if (streq(name
, "UtmpMode"))
1166 return bus_set_transient_utmp_mode(u
, name
, &c
->utmp_mode
, message
, flags
, error
);
1168 if (streq(name
, "PAMName"))
1169 return bus_set_transient_string(u
, name
, &c
->pam_name
, message
, flags
, error
);
1171 if (streq(name
, "TimerSlackNSec"))
1172 return bus_set_transient_nsec(u
, name
, &c
->timer_slack_nsec
, message
, flags
, error
);
1174 if (streq(name
, "ProtectSystem"))
1175 return bus_set_transient_protect_system(u
, name
, &c
->protect_system
, message
, flags
, error
);
1177 if (streq(name
, "ProtectHome"))
1178 return bus_set_transient_protect_home(u
, name
, &c
->protect_home
, message
, flags
, error
);
1180 if (streq(name
, "KeyringMode"))
1181 return bus_set_transient_keyring_mode(u
, name
, &c
->keyring_mode
, message
, flags
, error
);
1183 if (streq(name
, "RuntimeDirectoryPreserve"))
1184 return bus_set_transient_preserve_mode(u
, name
, &c
->runtime_directory_preserve_mode
, message
, flags
, error
);
1186 if (streq(name
, "UMask"))
1187 return bus_set_transient_mode_t(u
, name
, &c
->umask
, message
, flags
, error
);
1189 if (streq(name
, "RuntimeDirectoryMode"))
1190 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_RUNTIME
].mode
, message
, flags
, error
);
1192 if (streq(name
, "StateDirectoryMode"))
1193 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_STATE
].mode
, message
, flags
, error
);
1195 if (streq(name
, "CacheDirectoryMode"))
1196 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CACHE
].mode
, message
, flags
, error
);
1198 if (streq(name
, "LogsDirectoryMode"))
1199 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_LOGS
].mode
, message
, flags
, error
);
1201 if (streq(name
, "ConfigurationDirectoryMode"))
1202 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
, message
, flags
, error
);
1204 if (streq(name
, "SELinuxContext"))
1205 return bus_set_transient_string(u
, name
, &c
->selinux_context
, message
, flags
, error
);
1207 if (streq(name
, "SecureBits"))
1208 return bus_set_transient_secure_bits(u
, name
, &c
->secure_bits
, message
, flags
, error
);
1210 if (streq(name
, "CapabilityBoundingSet"))
1211 return bus_set_transient_capability(u
, name
, &c
->capability_bounding_set
, message
, flags
, error
);
1213 if (streq(name
, "AmbientCapabilities"))
1214 return bus_set_transient_capability(u
, name
, &c
->capability_ambient_set
, message
, flags
, error
);
1216 if (streq(name
, "CPUSchedulingPolicy"))
1217 return bus_set_transient_sched_policy(u
, name
, &c
->cpu_sched_policy
, message
, flags
, error
);
1219 if (streq(name
, "RestrictNamespaces"))
1220 return bus_set_transient_namespace_flag(u
, name
, &c
->restrict_namespaces
, message
, flags
, error
);
1222 if (streq(name
, "MountFlags"))
1223 return bus_set_transient_mount_flags(u
, name
, &c
->mount_flags
, message
, flags
, error
);
1225 if (streq(name
, "SupplementaryGroups")) {
1226 _cleanup_strv_free_
char **l
= NULL
;
1229 r
= sd_bus_message_read_strv(message
, &l
);
1233 STRV_FOREACH(p
, l
) {
1234 if (!isempty(*p
) && !valid_user_group_name_or_id(*p
))
1235 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid supplementary group names");
1238 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1239 if (strv_isempty(l
)) {
1240 c
->supplementary_groups
= strv_free(c
->supplementary_groups
);
1241 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1243 _cleanup_free_
char *joined
= NULL
;
1245 r
= strv_extend_strv(&c
->supplementary_groups
, l
, true);
1249 joined
= strv_join(c
->supplementary_groups
, " ");
1253 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s", name
, joined
);
1259 } else if (streq(name
, "SyslogLevel")) {
1262 r
= sd_bus_message_read(message
, "i", &level
);
1266 if (!log_level_is_valid(level
))
1267 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log level value out of range");
1269 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1270 c
->syslog_priority
= (c
->syslog_priority
& LOG_FACMASK
) | level
;
1271 unit_write_settingf(u
, flags
, name
, "SyslogLevel=%i", level
);
1276 } else if (streq(name
, "SyslogFacility")) {
1279 r
= sd_bus_message_read(message
, "i", &facility
);
1283 if (!log_facility_unshifted_is_valid(facility
))
1284 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log facility value out of range");
1286 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1287 c
->syslog_priority
= (facility
<< 3) | LOG_PRI(c
->syslog_priority
);
1288 unit_write_settingf(u
, flags
, name
, "SyslogFacility=%i", facility
);
1293 } else if (streq(name
, "LogExtraFields")) {
1296 r
= sd_bus_message_enter_container(message
, 'a', "ay");
1301 _cleanup_free_
void *copy
= NULL
;
1307 /* Note that we expect a byte array for each field, instead of a string. That's because on the
1308 * lower-level journal fields can actually contain binary data and are not restricted to text,
1309 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
1310 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
1311 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
1312 * limitation, should a good, valid usecase arise. */
1314 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
1320 if (memchr(p
, 0, sz
))
1321 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains zero byte");
1323 eq
= memchr(p
, '=', sz
);
1325 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains no '=' character");
1326 if (!journal_field_valid(p
, eq
- (const char*) p
, false))
1327 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field invalid");
1329 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1330 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
1333 c
->log_extra_fields
= t
;
1336 copy
= malloc(sz
+ 1);
1340 memcpy(copy
, p
, sz
);
1341 ((uint8_t*) copy
)[sz
] = 0;
1343 if (!utf8_is_valid(copy
))
1344 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field is not valid UTF-8");
1346 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1347 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE(copy
, sz
);
1348 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
, name
, "LogExtraFields=%s", (char*) copy
);
1356 r
= sd_bus_message_exit_container(message
);
1360 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && n
== 0) {
1361 exec_context_free_log_extra_fields(c
);
1362 unit_write_setting(u
, flags
, name
, "LogExtraFields=");
1370 if (streq(name
, "SystemCallErrorNumber"))
1371 return bus_set_transient_errno(u
, name
, &c
->syscall_errno
, message
, flags
, error
);
1373 if (streq(name
, "SystemCallFilter")) {
1375 _cleanup_strv_free_
char **l
= NULL
;
1377 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1381 r
= sd_bus_message_read(message
, "b", &whitelist
);
1385 r
= sd_bus_message_read_strv(message
, &l
);
1389 r
= sd_bus_message_exit_container(message
);
1393 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1394 _cleanup_free_
char *joined
= NULL
;
1395 bool invert
= !whitelist
;
1398 if (strv_isempty(l
)) {
1399 c
->syscall_whitelist
= false;
1400 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
1402 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=");
1406 if (!c
->syscall_filter
) {
1407 c
->syscall_filter
= hashmap_new(NULL
);
1408 if (!c
->syscall_filter
)
1411 c
->syscall_whitelist
= whitelist
;
1413 if (c
->syscall_whitelist
) {
1414 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
| (invert
? SECCOMP_PARSE_INVERT
: 0));
1420 STRV_FOREACH(s
, l
) {
1421 _cleanup_free_
char *n
= NULL
;
1424 r
= parse_syscall_and_errno(*s
, &n
, &e
);
1428 r
= seccomp_parse_syscall_filter(n
, e
, c
->syscall_filter
, (invert
? SECCOMP_PARSE_INVERT
: 0) | (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0));
1433 joined
= strv_join(l
, " ");
1437 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=%s%s", whitelist
? "" : "~", joined
);
1442 } else if (streq(name
, "SystemCallArchitectures")) {
1443 _cleanup_strv_free_
char **l
= NULL
;
1445 r
= sd_bus_message_read_strv(message
, &l
);
1449 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1450 _cleanup_free_
char *joined
= NULL
;
1452 if (strv_isempty(l
))
1453 c
->syscall_archs
= set_free(c
->syscall_archs
);
1457 r
= set_ensure_allocated(&c
->syscall_archs
, NULL
);
1461 STRV_FOREACH(s
, l
) {
1464 r
= seccomp_arch_from_string(*s
, &a
);
1468 r
= set_put(c
->syscall_archs
, UINT32_TO_PTR(a
+ 1));
1475 joined
= strv_join(l
, " ");
1479 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
1484 } else if (streq(name
, "RestrictAddressFamilies")) {
1486 _cleanup_strv_free_
char **l
= NULL
;
1488 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1492 r
= sd_bus_message_read(message
, "b", &whitelist
);
1496 r
= sd_bus_message_read_strv(message
, &l
);
1500 r
= sd_bus_message_exit_container(message
);
1504 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1505 _cleanup_free_
char *joined
= NULL
;
1506 bool invert
= !whitelist
;
1509 if (strv_isempty(l
)) {
1510 c
->address_families_whitelist
= false;
1511 c
->address_families
= set_free(c
->address_families
);
1513 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=");
1517 if (!c
->address_families
) {
1518 c
->address_families
= set_new(NULL
);
1519 if (!c
->address_families
)
1522 c
->address_families_whitelist
= whitelist
;
1525 STRV_FOREACH(s
, l
) {
1528 af
= af_from_name(*s
);
1532 if (!invert
== c
->address_families_whitelist
) {
1533 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
1537 (void) set_remove(c
->address_families
, INT_TO_PTR(af
));
1540 joined
= strv_join(l
, " ");
1544 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=%s%s", whitelist
? "" : "~", joined
);
1550 if (streq(name
, "CPUAffinity")) {
1554 r
= sd_bus_message_read_array(message
, 'y', &a
, &n
);
1558 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1560 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1561 c
->cpuset_ncpus
= 0;
1562 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1564 _cleanup_free_
char *str
= NULL
;
1565 size_t allocated
= 0, len
= 0, i
, ncpus
;
1567 ncpus
= CPU_SIZE_TO_NUM(n
);
1569 for (i
= 0; i
< ncpus
; i
++) {
1570 _cleanup_free_
char *p
= NULL
;
1573 if (!CPU_ISSET_S(i
, n
, (cpu_set_t
*) a
))
1576 r
= asprintf(&p
, "%zu", i
);
1582 if (!GREEDY_REALLOC(str
, allocated
, len
+ add
+ 2))
1585 strcpy(mempcpy(str
+ len
, p
, add
), " ");
1590 str
[len
- 1] = '\0';
1592 if (!c
->cpuset
|| c
->cpuset_ncpus
< ncpus
) {
1595 cpuset
= CPU_ALLOC(ncpus
);
1599 CPU_ZERO_S(n
, cpuset
);
1601 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, (cpu_set_t
*) a
);
1602 CPU_FREE(c
->cpuset
);
1604 CPU_OR_S(n
, cpuset
, cpuset
, (cpu_set_t
*) a
);
1607 c
->cpuset_ncpus
= ncpus
;
1609 CPU_OR_S(n
, c
->cpuset
, c
->cpuset
, (cpu_set_t
*) a
);
1611 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, str
);
1617 } else if (streq(name
, "IOSchedulingClass")) {
1620 r
= sd_bus_message_read(message
, "i", &q
);
1624 if (!ioprio_class_is_valid(q
))
1625 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling class: %i", q
);
1627 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1628 _cleanup_free_
char *s
= NULL
;
1630 r
= ioprio_class_to_string_alloc(q
, &s
);
1634 c
->ioprio
= IOPRIO_PRIO_VALUE(q
, IOPRIO_PRIO_DATA(c
->ioprio
));
1635 c
->ioprio_set
= true;
1637 unit_write_settingf(u
, flags
, name
, "IOSchedulingClass=%s", s
);
1642 } else if (streq(name
, "IOSchedulingPriority")) {
1645 r
= sd_bus_message_read(message
, "i", &p
);
1649 if (!ioprio_priority_is_valid(p
))
1650 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling priority: %i", p
);
1652 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1653 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), p
);
1654 c
->ioprio_set
= true;
1656 unit_write_settingf(u
, flags
, name
, "IOSchedulingPriority=%i", p
);
1661 } else if (streq(name
, "WorkingDirectory")) {
1665 r
= sd_bus_message_read(message
, "s", &s
);
1675 if (!isempty(s
) && !streq(s
, "~") && !path_is_absolute(s
))
1676 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "WorkingDirectory= expects an absolute path or '~'");
1678 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1679 if (streq(s
, "~")) {
1680 c
->working_directory
= mfree(c
->working_directory
);
1681 c
->working_directory_home
= true;
1683 r
= free_and_strdup(&c
->working_directory
, empty_to_null(s
));
1687 c
->working_directory_home
= false;
1690 c
->working_directory_missing_ok
= missing_ok
;
1691 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "WorkingDirectory=%s%s", missing_ok
? "-" : "", s
);
1696 } else if (STR_IN_SET(name
,
1697 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
1700 r
= sd_bus_message_read(message
, "s", &s
);
1704 if (!isempty(s
) && !fdname_is_valid(s
))
1705 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid file descriptor name");
1707 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1709 if (streq(name
, "StandardInputFileDescriptorName")) {
1710 r
= free_and_strdup(c
->stdio_fdname
+ STDIN_FILENO
, empty_to_null(s
));
1714 c
->std_input
= EXEC_INPUT_NAMED_FD
;
1715 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=fd:%s", exec_context_fdname(c
, STDIN_FILENO
));
1717 } else if (streq(name
, "StandardOutputFileDescriptorName")) {
1718 r
= free_and_strdup(c
->stdio_fdname
+ STDOUT_FILENO
, empty_to_null(s
));
1722 c
->std_output
= EXEC_OUTPUT_NAMED_FD
;
1723 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=fd:%s", exec_context_fdname(c
, STDOUT_FILENO
));
1726 assert(streq(name
, "StandardErrorFileDescriptorName"));
1728 r
= free_and_strdup(&c
->stdio_fdname
[STDERR_FILENO
], empty_to_null(s
));
1732 c
->std_error
= EXEC_OUTPUT_NAMED_FD
;
1733 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=fd:%s", exec_context_fdname(c
, STDERR_FILENO
));
1739 } else if (STR_IN_SET(name
, "StandardInputFile", "StandardOutputFile", "StandardErrorFile")) {
1742 r
= sd_bus_message_read(message
, "s", &s
);
1747 if (!path_is_absolute(s
))
1748 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute", s
);
1749 if (!path_is_normalized(s
))
1750 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not normalized", s
);
1753 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1755 if (streq(name
, "StandardInputFile")) {
1756 r
= free_and_strdup(&c
->stdio_file
[STDIN_FILENO
], empty_to_null(s
));
1760 c
->std_input
= EXEC_INPUT_FILE
;
1761 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=file:%s", s
);
1763 } else if (streq(name
, "StandardOutputFile")) {
1764 r
= free_and_strdup(&c
->stdio_file
[STDOUT_FILENO
], empty_to_null(s
));
1768 c
->std_output
= EXEC_OUTPUT_FILE
;
1769 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=file:%s", s
);
1772 assert(streq(name
, "StandardErrorFile"));
1774 r
= free_and_strdup(&c
->stdio_file
[STDERR_FILENO
], empty_to_null(s
));
1778 c
->std_error
= EXEC_OUTPUT_FILE
;
1779 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=file:%s", s
);
1785 } else if (streq(name
, "StandardInputData")) {
1789 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
1793 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1794 _cleanup_free_
char *encoded
= NULL
;
1797 c
->stdin_data
= mfree(c
->stdin_data
);
1798 c
->stdin_data_size
= 0;
1800 unit_write_settingf(u
, flags
, name
, "StandardInputData=");
1805 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1806 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
)
1809 n
= base64mem(p
, sz
, &encoded
);
1813 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1817 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1820 c
->stdin_data_size
+= sz
;
1822 unit_write_settingf(u
, flags
, name
, "StandardInputData=%s", encoded
);
1828 } else if (streq(name
, "Environment")) {
1830 _cleanup_strv_free_
char **l
= NULL
;
1832 r
= sd_bus_message_read_strv(message
, &l
);
1836 if (!strv_env_is_valid(l
))
1837 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment block.");
1839 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1840 if (strv_isempty(l
)) {
1841 c
->environment
= strv_free(c
->environment
);
1842 unit_write_setting(u
, flags
, name
, "Environment=");
1844 _cleanup_free_
char *joined
= NULL
;
1847 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
1851 e
= strv_env_merge(2, c
->environment
, l
);
1855 strv_free_and_replace(c
->environment
, e
);
1856 unit_write_settingf(u
, flags
, name
, "Environment=%s", joined
);
1862 } else if (streq(name
, "UnsetEnvironment")) {
1864 _cleanup_strv_free_
char **l
= NULL
;
1866 r
= sd_bus_message_read_strv(message
, &l
);
1870 if (!strv_env_name_or_assignment_is_valid(l
))
1871 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid UnsetEnvironment= list.");
1873 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1874 if (strv_isempty(l
)) {
1875 c
->unset_environment
= strv_free(c
->unset_environment
);
1876 unit_write_setting(u
, flags
, name
, "UnsetEnvironment=");
1878 _cleanup_free_
char *joined
= NULL
;
1881 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
1885 e
= strv_env_merge(2, c
->unset_environment
, l
);
1889 strv_free_and_replace(c
->unset_environment
, e
);
1890 unit_write_settingf(u
, flags
, name
, "UnsetEnvironment=%s", joined
);
1896 } else if (streq(name
, "OOMScoreAdjust")) {
1899 r
= sd_bus_message_read(message
, "i", &oa
);
1903 if (!oom_score_adjust_is_valid(oa
))
1904 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "OOM score adjust value out of range");
1906 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1907 c
->oom_score_adjust
= oa
;
1908 c
->oom_score_adjust_set
= true;
1909 unit_write_settingf(u
, flags
, name
, "OOMScoreAdjust=%i", oa
);
1914 } else if (streq(name
, "EnvironmentFiles")) {
1916 _cleanup_free_
char *joined
= NULL
;
1917 _cleanup_fclose_
FILE *f
= NULL
;
1918 _cleanup_strv_free_
char **l
= NULL
;
1922 r
= sd_bus_message_enter_container(message
, 'a', "(sb)");
1926 f
= open_memstream(&joined
, &size
);
1930 (void) __fsetlocking(f
, FSETLOCKING_BYCALLER
);
1932 fputs("EnvironmentFile=\n", f
);
1934 STRV_FOREACH(i
, c
->environment_files
) {
1935 _cleanup_free_
char *q
= NULL
;
1937 q
= specifier_escape(*i
);
1941 fprintf(f
, "EnvironmentFile=%s\n", q
);
1944 while ((r
= sd_bus_message_enter_container(message
, 'r', "sb")) > 0) {
1948 r
= sd_bus_message_read(message
, "sb", &path
, &b
);
1952 r
= sd_bus_message_exit_container(message
);
1956 if (!path_is_absolute(path
))
1957 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
1959 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1960 _cleanup_free_
char *q
= NULL
;
1963 buf
= strjoin(b
? "-" : "", path
);
1967 q
= specifier_escape(buf
);
1973 fprintf(f
, "EnvironmentFile=%s\n", q
);
1975 r
= strv_consume(&l
, buf
);
1983 r
= sd_bus_message_exit_container(message
);
1987 r
= fflush_and_check(f
);
1991 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1992 if (strv_isempty(l
)) {
1993 c
->environment_files
= strv_free(c
->environment_files
);
1994 unit_write_setting(u
, flags
, name
, "EnvironmentFile=");
1996 r
= strv_extend_strv(&c
->environment_files
, l
, true);
2000 unit_write_setting(u
, flags
, name
, joined
);
2006 } else if (streq(name
, "PassEnvironment")) {
2008 _cleanup_strv_free_
char **l
= NULL
;
2010 r
= sd_bus_message_read_strv(message
, &l
);
2014 if (!strv_env_name_is_valid(l
))
2015 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PassEnvironment= block.");
2017 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2018 if (strv_isempty(l
)) {
2019 c
->pass_environment
= strv_free(c
->pass_environment
);
2020 unit_write_setting(u
, flags
, name
, "PassEnvironment=");
2022 _cleanup_free_
char *joined
= NULL
;
2024 r
= strv_extend_strv(&c
->pass_environment
, l
, true);
2028 /* We write just the new settings out to file, with unresolved specifiers. */
2029 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2033 unit_write_settingf(u
, flags
, name
, "PassEnvironment=%s", joined
);
2039 } else if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
2040 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) {
2041 _cleanup_strv_free_
char **l
= NULL
;
2045 r
= sd_bus_message_read_strv(message
, &l
);
2049 STRV_FOREACH(p
, l
) {
2053 offset
= i
[0] == '-';
2054 offset
+= i
[offset
] == '+';
2055 if (!path_is_absolute(i
+ offset
))
2056 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
2058 path_simplify(i
+ offset
, false);
2061 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2062 if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadWritePaths"))
2063 dirs
= &c
->read_write_paths
;
2064 else if (STR_IN_SET(name
, "ReadOnlyDirectories", "ReadOnlyPaths"))
2065 dirs
= &c
->read_only_paths
;
2066 else /* "InaccessiblePaths" */
2067 dirs
= &c
->inaccessible_paths
;
2069 if (strv_isempty(l
)) {
2070 *dirs
= strv_free(*dirs
);
2071 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2073 _cleanup_free_
char *joined
= NULL
;
2075 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2079 r
= strv_extend_strv(dirs
, l
, true);
2083 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2089 } else if (STR_IN_SET(name
, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
2090 _cleanup_strv_free_
char **l
= NULL
;
2093 r
= sd_bus_message_read_strv(message
, &l
);
2097 STRV_FOREACH(p
, l
) {
2098 if (!path_is_normalized(*p
))
2099 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is not normalized: %s", name
, *p
);
2101 if (path_is_absolute(*p
))
2102 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is absolute: %s", name
, *p
);
2104 if (path_startswith(*p
, "private"))
2105 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path can't be 'private': %s", name
, *p
);
2108 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2109 char ***dirs
= NULL
;
2110 ExecDirectoryType i
;
2112 for (i
= 0; i
< _EXEC_DIRECTORY_TYPE_MAX
; i
++)
2113 if (streq(name
, exec_directory_type_to_string(i
))) {
2114 dirs
= &c
->directories
[i
].paths
;
2120 if (strv_isempty(l
)) {
2121 *dirs
= strv_free(*dirs
);
2122 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2124 _cleanup_free_
char *joined
= NULL
;
2126 r
= strv_extend_strv(dirs
, l
, true);
2130 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2134 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2140 } else if (STR_IN_SET(name
, "AppArmorProfile", "SmackProcessLabel")) {
2144 r
= sd_bus_message_read(message
, "(bs)", &ignore
, &s
);
2148 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2152 if (streq(name
, "AppArmorProfile")) {
2153 p
= &c
->apparmor_profile
;
2154 b
= &c
->apparmor_profile_ignore
;
2155 } else { /* "SmackProcessLabel" */
2156 p
= &c
->smack_process_label
;
2157 b
= &c
->smack_process_label_ignore
;
2164 if (free_and_strdup(p
, s
) < 0)
2169 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s%s", name
, ignore
? "-" : "", strempty(s
));
2174 } else if (STR_IN_SET(name
, "BindPaths", "BindReadOnlyPaths")) {
2175 const char *source
, *destination
;
2177 uint64_t mount_flags
;
2180 r
= sd_bus_message_enter_container(message
, 'a', "(ssbt)");
2184 while ((r
= sd_bus_message_read(message
, "(ssbt)", &source
, &destination
, &ignore_enoent
, &mount_flags
)) > 0) {
2186 if (!path_is_absolute(source
))
2187 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
2188 if (!path_is_absolute(destination
))
2189 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
2190 if (!IN_SET(mount_flags
, 0, MS_REC
))
2191 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount flags.");
2193 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2194 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
2196 .source
= strdup(source
),
2197 .destination
= strdup(destination
),
2198 .read_only
= !!strstr(name
, "ReadOnly"),
2199 .recursive
= !!(mount_flags
& MS_REC
),
2200 .ignore_enoent
= ignore_enoent
,
2205 unit_write_settingf(
2206 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2209 ignore_enoent
? "-" : "",
2212 (mount_flags
& MS_REC
) ? "rbind" : "norbind");
2220 r
= sd_bus_message_exit_container(message
);
2225 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
2226 c
->bind_mounts
= NULL
;
2227 c
->n_bind_mounts
= 0;
2229 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2234 } else if (streq(name
, "TemporaryFileSystem")) {
2235 const char *path
, *options
;
2238 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
2242 while ((r
= sd_bus_message_read(message
, "(ss)", &path
, &options
)) > 0) {
2244 if (!path_is_absolute(path
))
2245 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Mount point %s is not absolute.", path
);
2247 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2248 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, options
);
2252 unit_write_settingf(
2253 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2265 r
= sd_bus_message_exit_container(message
);
2270 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
2271 c
->temporary_filesystems
= NULL
;
2272 c
->n_temporary_filesystems
= 0;
2274 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2279 } else if ((suffix
= startswith(name
, "Limit"))) {
2280 const char *soft
= NULL
;
2283 ri
= rlimit_from_string(suffix
);
2285 soft
= endswith(suffix
, "Soft");
2289 n
= strndupa(suffix
, soft
- suffix
);
2290 ri
= rlimit_from_string(n
);
2292 name
= strjoina("Limit", n
);
2300 r
= sd_bus_message_read(message
, "t", &rl
);
2304 if (rl
== (uint64_t) -1)
2309 if ((uint64_t) x
!= rl
)
2313 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2314 _cleanup_free_
char *f
= NULL
;
2317 if (c
->rlimit
[ri
]) {
2318 nl
= *c
->rlimit
[ri
];
2325 /* When the resource limit is not initialized yet, then assign the value to both fields */
2326 nl
= (struct rlimit
) {
2331 r
= rlimit_format(&nl
, &f
);
2336 *c
->rlimit
[ri
] = nl
;
2338 c
->rlimit
[ri
] = newdup(struct rlimit
, &nl
, 1);
2343 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, f
);