1 /* SPDX-License-Identifier: LGPL-2.1+ */
11 #include "alloc-util.h"
14 #include "capability-util.h"
15 #include "cpu-set-util.h"
16 #include "dbus-execute.h"
17 #include "dbus-util.h"
19 #include "errno-list.h"
24 #include "hexdecoct.h"
27 #include "journal-util.h"
28 #include "mountpoint-util.h"
29 #include "namespace.h"
30 #include "parse-util.h"
31 #include "path-util.h"
32 #include "process-util.h"
33 #include "rlimit-util.h"
35 #include "seccomp-util.h"
37 #include "securebits-util.h"
38 #include "specifier.h"
40 #include "syslog-util.h"
41 #include "unit-printf.h"
42 #include "user-util.h"
45 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output
, exec_output
, ExecOutput
);
46 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input
, exec_input
, ExecInput
);
47 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
);
48 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
);
49 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
);
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
);
52 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality
, personality
, unsigned long);
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
);
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
);
59 static BUS_DEFINE_PROPERTY_GET(property_get_cpu_affinity_from_numa
, "b", ExecContext
, exec_context_get_cpu_affinity_from_numa
);
61 static int property_get_environment_files(
64 const char *interface
,
66 sd_bus_message
*reply
,
68 sd_bus_error
*error
) {
70 ExecContext
*c
= userdata
;
78 r
= sd_bus_message_open_container(reply
, 'a', "(sb)");
82 STRV_FOREACH(j
, c
->environment_files
) {
85 r
= sd_bus_message_append(reply
, "(sb)", fn
[0] == '-' ? fn
+ 1 : fn
, fn
[0] == '-');
90 return sd_bus_message_close_container(reply
);
93 static int property_get_oom_score_adjust(
96 const char *interface
,
98 sd_bus_message
*reply
,
100 sd_bus_error
*error
) {
102 ExecContext
*c
= userdata
;
110 if (c
->oom_score_adjust_set
)
111 n
= c
->oom_score_adjust
;
113 _cleanup_free_
char *t
= NULL
;
116 r
= read_one_line_file("/proc/self/oom_score_adj", &t
);
118 log_debug_errno(r
, "Failed to read /proc/self/oom_score_adj, ignoring: %m");
120 r
= safe_atoi32(t
, &n
);
122 log_debug_errno(r
, "Failed to parse \"%s\" from /proc/self/oom_score_adj, ignoring: %m", t
);
126 return sd_bus_message_append(reply
, "i", n
);
129 static int property_get_coredump_filter(
132 const char *interface
,
133 const char *property
,
134 sd_bus_message
*reply
,
136 sd_bus_error
*error
) {
138 ExecContext
*c
= userdata
;
146 if (c
->coredump_filter_set
)
147 n
= c
->coredump_filter
;
149 _cleanup_free_
char *t
= NULL
;
151 n
= COREDUMP_FILTER_MASK_DEFAULT
;
152 r
= read_one_line_file("/proc/self/coredump_filter", &t
);
154 log_debug_errno(r
, "Failed to read /proc/self/coredump_filter, ignoring: %m");
156 r
= safe_atoux64(t
, &n
);
158 log_debug_errno(r
, "Failed to parse \"%s\" from /proc/self/coredump_filter, ignoring: %m", t
);
162 return sd_bus_message_append(reply
, "t", n
);
165 static int property_get_nice(
168 const char *interface
,
169 const char *property
,
170 sd_bus_message
*reply
,
172 sd_bus_error
*error
) {
174 ExecContext
*c
= userdata
;
185 n
= getpriority(PRIO_PROCESS
, 0);
190 return sd_bus_message_append(reply
, "i", n
);
193 static int property_get_cpu_sched_policy(
196 const char *interface
,
197 const char *property
,
198 sd_bus_message
*reply
,
200 sd_bus_error
*error
) {
202 ExecContext
*c
= userdata
;
209 if (c
->cpu_sched_set
)
210 n
= c
->cpu_sched_policy
;
212 n
= sched_getscheduler(0);
217 return sd_bus_message_append(reply
, "i", n
);
220 static int property_get_cpu_sched_priority(
223 const char *interface
,
224 const char *property
,
225 sd_bus_message
*reply
,
227 sd_bus_error
*error
) {
229 ExecContext
*c
= userdata
;
236 if (c
->cpu_sched_set
)
237 n
= c
->cpu_sched_priority
;
239 struct sched_param p
= {};
241 if (sched_getparam(0, &p
) >= 0)
242 n
= p
.sched_priority
;
247 return sd_bus_message_append(reply
, "i", n
);
250 static int property_get_cpu_affinity(
253 const char *interface
,
254 const char *property
,
255 sd_bus_message
*reply
,
257 sd_bus_error
*error
) {
259 ExecContext
*c
= userdata
;
260 _cleanup_(cpu_set_reset
) CPUSet s
= {};
261 _cleanup_free_
uint8_t *array
= NULL
;
268 if (c
->cpu_affinity_from_numa
) {
271 r
= numa_to_cpu_set(&c
->numa_policy
, &s
);
276 (void) cpu_set_to_dbus(c
->cpu_affinity_from_numa
? &s
: &c
->cpu_set
, &array
, &allocated
);
278 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
281 static int property_get_numa_mask(
284 const char *interface
,
285 const char *property
,
286 sd_bus_message
*reply
,
288 sd_bus_error
*error
) {
290 ExecContext
*c
= userdata
;
291 _cleanup_free_
uint8_t *array
= NULL
;
298 (void) cpu_set_to_dbus(&c
->numa_policy
.nodes
, &array
, &allocated
);
300 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
303 static int property_get_numa_policy(
306 const char *interface
,
307 const char *property
,
308 sd_bus_message
*reply
,
310 sd_bus_error
*error
) {
311 ExecContext
*c
= userdata
;
318 policy
= numa_policy_get_type(&c
->numa_policy
);
320 return sd_bus_message_append_basic(reply
, 'i', &policy
);
323 static int property_get_timer_slack_nsec(
326 const char *interface
,
327 const char *property
,
328 sd_bus_message
*reply
,
330 sd_bus_error
*error
) {
332 ExecContext
*c
= userdata
;
339 if (c
->timer_slack_nsec
!= NSEC_INFINITY
)
340 u
= (uint64_t) c
->timer_slack_nsec
;
342 u
= (uint64_t) prctl(PR_GET_TIMERSLACK
);
344 return sd_bus_message_append(reply
, "t", u
);
347 static int property_get_syscall_filter(
350 const char *interface
,
351 const char *property
,
352 sd_bus_message
*reply
,
354 sd_bus_error
*error
) {
356 ExecContext
*c
= userdata
;
357 _cleanup_strv_free_
char **l
= NULL
;
369 r
= sd_bus_message_open_container(reply
, 'r', "bas");
373 r
= sd_bus_message_append(reply
, "b", c
->syscall_whitelist
);
378 HASHMAP_FOREACH_KEY(val
, id
, c
->syscall_filter
, i
) {
379 _cleanup_free_
char *name
= NULL
;
380 const char *e
= NULL
;
382 int num
= PTR_TO_INT(val
);
384 name
= seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE
, PTR_TO_INT(id
) - 1);
389 e
= errno_to_name(num
);
391 s
= strjoin(name
, ":", e
);
395 r
= asprintf(&s
, "%s:%d", name
, num
);
402 r
= strv_consume(&l
, s
);
410 r
= sd_bus_message_append_strv(reply
, l
);
414 return sd_bus_message_close_container(reply
);
417 static int property_get_syscall_archs(
420 const char *interface
,
421 const char *property
,
422 sd_bus_message
*reply
,
424 sd_bus_error
*error
) {
426 ExecContext
*c
= userdata
;
427 _cleanup_strv_free_
char **l
= NULL
;
440 SET_FOREACH(id
, c
->syscall_archs
, i
) {
443 name
= seccomp_arch_to_string(PTR_TO_UINT32(id
) - 1);
447 r
= strv_extend(&l
, name
);
455 r
= sd_bus_message_append_strv(reply
, l
);
462 static int property_get_selinux_context(
465 const char *interface
,
466 const char *property
,
467 sd_bus_message
*reply
,
469 sd_bus_error
*error
) {
471 ExecContext
*c
= userdata
;
477 return sd_bus_message_append(reply
, "(bs)", c
->selinux_context_ignore
, c
->selinux_context
);
480 static int property_get_apparmor_profile(
483 const char *interface
,
484 const char *property
,
485 sd_bus_message
*reply
,
487 sd_bus_error
*error
) {
489 ExecContext
*c
= userdata
;
495 return sd_bus_message_append(reply
, "(bs)", c
->apparmor_profile_ignore
, c
->apparmor_profile
);
498 static int property_get_smack_process_label(
501 const char *interface
,
502 const char *property
,
503 sd_bus_message
*reply
,
505 sd_bus_error
*error
) {
507 ExecContext
*c
= userdata
;
513 return sd_bus_message_append(reply
, "(bs)", c
->smack_process_label_ignore
, c
->smack_process_label
);
516 static int property_get_address_families(
519 const char *interface
,
520 const char *property
,
521 sd_bus_message
*reply
,
523 sd_bus_error
*error
) {
525 ExecContext
*c
= userdata
;
526 _cleanup_strv_free_
char **l
= NULL
;
535 r
= sd_bus_message_open_container(reply
, 'r', "bas");
539 r
= sd_bus_message_append(reply
, "b", c
->address_families_whitelist
);
543 SET_FOREACH(af
, c
->address_families
, i
) {
546 name
= af_to_name(PTR_TO_INT(af
));
550 r
= strv_extend(&l
, name
);
557 r
= sd_bus_message_append_strv(reply
, l
);
561 return sd_bus_message_close_container(reply
);
564 static int property_get_working_directory(
567 const char *interface
,
568 const char *property
,
569 sd_bus_message
*reply
,
571 sd_bus_error
*error
) {
573 ExecContext
*c
= userdata
;
580 if (c
->working_directory_home
)
583 wd
= c
->working_directory
;
585 if (c
->working_directory_missing_ok
)
586 wd
= strjoina("!", wd
);
588 return sd_bus_message_append(reply
, "s", wd
);
591 static int property_get_stdio_fdname(
594 const char *interface
,
595 const char *property
,
596 sd_bus_message
*reply
,
598 sd_bus_error
*error
) {
600 ExecContext
*c
= userdata
;
608 if (streq(property
, "StandardInputFileDescriptorName"))
609 fileno
= STDIN_FILENO
;
610 else if (streq(property
, "StandardOutputFileDescriptorName"))
611 fileno
= STDOUT_FILENO
;
613 assert(streq(property
, "StandardErrorFileDescriptorName"));
614 fileno
= STDERR_FILENO
;
617 return sd_bus_message_append(reply
, "s", exec_context_fdname(c
, fileno
));
620 static int property_get_input_data(
623 const char *interface
,
624 const char *property
,
625 sd_bus_message
*reply
,
627 sd_bus_error
*error
) {
629 ExecContext
*c
= userdata
;
636 return sd_bus_message_append_array(reply
, 'y', c
->stdin_data
, c
->stdin_data_size
);
639 static int property_get_bind_paths(
642 const char *interface
,
643 const char *property
,
644 sd_bus_message
*reply
,
646 sd_bus_error
*error
) {
648 ExecContext
*c
= userdata
;
658 ro
= strstr(property
, "ReadOnly");
660 r
= sd_bus_message_open_container(reply
, 'a', "(ssbt)");
664 for (i
= 0; i
< c
->n_bind_mounts
; i
++) {
666 if (ro
!= c
->bind_mounts
[i
].read_only
)
669 r
= sd_bus_message_append(
671 c
->bind_mounts
[i
].source
,
672 c
->bind_mounts
[i
].destination
,
673 c
->bind_mounts
[i
].ignore_enoent
,
674 c
->bind_mounts
[i
].recursive
? (uint64_t) MS_REC
: (uint64_t) 0);
679 return sd_bus_message_close_container(reply
);
682 static int property_get_temporary_filesystems(
685 const char *interface
,
686 const char *property
,
687 sd_bus_message
*reply
,
689 sd_bus_error
*error
) {
691 ExecContext
*c
= userdata
;
700 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
704 for (i
= 0; i
< c
->n_temporary_filesystems
; i
++) {
705 TemporaryFileSystem
*t
= c
->temporary_filesystems
+ i
;
707 r
= sd_bus_message_append(
715 return sd_bus_message_close_container(reply
);
718 static int property_get_log_extra_fields(
721 const char *interface
,
722 const char *property
,
723 sd_bus_message
*reply
,
725 sd_bus_error
*error
) {
727 ExecContext
*c
= userdata
;
736 r
= sd_bus_message_open_container(reply
, 'a', "ay");
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
);
746 return sd_bus_message_close_container(reply
);
749 static int property_get_root_hash(
752 const char *interface
,
753 const char *property
,
754 sd_bus_message
*reply
,
756 sd_bus_error
*error
) {
758 ExecContext
*c
= userdata
;
765 return sd_bus_message_append_array(reply
, 'y', c
->root_hash
, c
->root_hash_size
);
768 const sd_bus_vtable bus_exec_vtable
[] = {
769 SD_BUS_VTABLE_START(0),
770 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(ExecContext
, environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
771 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
772 SD_BUS_PROPERTY("PassEnvironment", "as", NULL
, offsetof(ExecContext
, pass_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
773 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL
, offsetof(ExecContext
, unset_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
774 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode
, offsetof(ExecContext
, umask
), SD_BUS_VTABLE_PROPERTY_CONST
),
775 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
776 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
777 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
778 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
779 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
780 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
781 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
782 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
783 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
784 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
785 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
786 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
787 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
788 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
789 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
790 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
791 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
792 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
793 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
794 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
795 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
796 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
797 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
798 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
799 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
800 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
801 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
802 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
803 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
804 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
805 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
806 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
807 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
808 SD_BUS_PROPERTY("RootDirectory", "s", NULL
, offsetof(ExecContext
, root_directory
), SD_BUS_VTABLE_PROPERTY_CONST
),
809 SD_BUS_PROPERTY("RootImage", "s", NULL
, offsetof(ExecContext
, root_image
), SD_BUS_VTABLE_PROPERTY_CONST
),
810 SD_BUS_PROPERTY("RootHash", "ay", property_get_root_hash
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
811 SD_BUS_PROPERTY("RootHashPath", "s", NULL
, offsetof(ExecContext
, root_hash_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
812 SD_BUS_PROPERTY("RootVerity", "s", NULL
, offsetof(ExecContext
, root_verity
), SD_BUS_VTABLE_PROPERTY_CONST
),
813 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
814 SD_BUS_PROPERTY("CoredumpFilter", "t", property_get_coredump_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
815 SD_BUS_PROPERTY("Nice", "i", property_get_nice
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
816 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
817 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
818 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
819 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
820 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
821 SD_BUS_PROPERTY("CPUAffinityFromNUMA", "b", property_get_cpu_affinity_from_numa
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
822 SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
823 SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
824 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
825 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool
, offsetof(ExecContext
, cpu_sched_reset_on_fork
), SD_BUS_VTABLE_PROPERTY_CONST
),
826 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool
, offsetof(ExecContext
, non_blocking
), SD_BUS_VTABLE_PROPERTY_CONST
),
827 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input
, offsetof(ExecContext
, std_input
), SD_BUS_VTABLE_PROPERTY_CONST
),
828 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
829 SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
830 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
831 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
832 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_error
), SD_BUS_VTABLE_PROPERTY_CONST
),
833 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
834 SD_BUS_PROPERTY("TTYPath", "s", NULL
, offsetof(ExecContext
, tty_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
835 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_reset
), SD_BUS_VTABLE_PROPERTY_CONST
),
836 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vhangup
), SD_BUS_VTABLE_PROPERTY_CONST
),
837 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vt_disallocate
), SD_BUS_VTABLE_PROPERTY_CONST
),
838 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
839 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL
, offsetof(ExecContext
, syslog_identifier
), SD_BUS_VTABLE_PROPERTY_CONST
),
840 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool
, offsetof(ExecContext
, syslog_level_prefix
), SD_BUS_VTABLE_PROPERTY_CONST
),
841 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
842 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
843 SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int
, offsetof(ExecContext
, log_level_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
844 SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec
, offsetof(ExecContext
, log_ratelimit_interval_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
845 SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned
, offsetof(ExecContext
, log_ratelimit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
846 SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
847 SD_BUS_PROPERTY("LogNamespace", "s", NULL
, offsetof(ExecContext
, log_namespace
), SD_BUS_VTABLE_PROPERTY_CONST
),
848 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int
, offsetof(ExecContext
, secure_bits
), SD_BUS_VTABLE_PROPERTY_CONST
),
849 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL
, offsetof(ExecContext
, capability_bounding_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
850 SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL
, offsetof(ExecContext
, capability_ambient_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
851 SD_BUS_PROPERTY("User", "s", NULL
, offsetof(ExecContext
, user
), SD_BUS_VTABLE_PROPERTY_CONST
),
852 SD_BUS_PROPERTY("Group", "s", NULL
, offsetof(ExecContext
, group
), SD_BUS_VTABLE_PROPERTY_CONST
),
853 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool
, offsetof(ExecContext
, dynamic_user
), SD_BUS_VTABLE_PROPERTY_CONST
),
854 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, remove_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
855 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL
, offsetof(ExecContext
, supplementary_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
856 SD_BUS_PROPERTY("PAMName", "s", NULL
, offsetof(ExecContext
, pam_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
857 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
858 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
859 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
860 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong
, offsetof(ExecContext
, mount_flags
), SD_BUS_VTABLE_PROPERTY_CONST
),
861 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool
, offsetof(ExecContext
, private_tmp
), SD_BUS_VTABLE_PROPERTY_CONST
),
862 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool
, offsetof(ExecContext
, private_devices
), SD_BUS_VTABLE_PROPERTY_CONST
),
863 SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_clock
), SD_BUS_VTABLE_PROPERTY_CONST
),
864 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_tunables
), SD_BUS_VTABLE_PROPERTY_CONST
),
865 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_modules
), SD_BUS_VTABLE_PROPERTY_CONST
),
866 SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_logs
), SD_BUS_VTABLE_PROPERTY_CONST
),
867 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_control_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
868 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool
, offsetof(ExecContext
, private_network
), SD_BUS_VTABLE_PROPERTY_CONST
),
869 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool
, offsetof(ExecContext
, private_users
), SD_BUS_VTABLE_PROPERTY_CONST
),
870 SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_bool
, offsetof(ExecContext
, private_mounts
), SD_BUS_VTABLE_PROPERTY_CONST
),
871 SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home
, offsetof(ExecContext
, protect_home
), SD_BUS_VTABLE_PROPERTY_CONST
),
872 SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system
, offsetof(ExecContext
, protect_system
), SD_BUS_VTABLE_PROPERTY_CONST
),
873 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool
, offsetof(ExecContext
, same_pgrp
), SD_BUS_VTABLE_PROPERTY_CONST
),
874 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL
, offsetof(ExecContext
, utmp_id
), SD_BUS_VTABLE_PROPERTY_CONST
),
875 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode
, offsetof(ExecContext
, utmp_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
876 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
877 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
878 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
879 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool
, offsetof(ExecContext
, ignore_sigpipe
), SD_BUS_VTABLE_PROPERTY_CONST
),
880 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool
, offsetof(ExecContext
, no_new_privileges
), SD_BUS_VTABLE_PROPERTY_CONST
),
881 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
882 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
883 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int
, offsetof(ExecContext
, syscall_errno
), SD_BUS_VTABLE_PROPERTY_CONST
),
884 SD_BUS_PROPERTY("Personality", "s", property_get_personality
, offsetof(ExecContext
, personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
885 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool
, offsetof(ExecContext
, lock_personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
886 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
887 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode
, offsetof(ExecContext
, runtime_directory_preserve_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
888 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
889 SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
890 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
891 SD_BUS_PROPERTY("StateDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
892 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
893 SD_BUS_PROPERTY("CacheDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
894 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
895 SD_BUS_PROPERTY("LogsDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
896 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
897 SD_BUS_PROPERTY("ConfigurationDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
898 SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec
, offsetof(ExecContext
, timeout_clean_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
899 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool
, offsetof(ExecContext
, memory_deny_write_execute
), SD_BUS_VTABLE_PROPERTY_CONST
),
900 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_realtime
), SD_BUS_VTABLE_PROPERTY_CONST
),
901 SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_suid_sgid
), SD_BUS_VTABLE_PROPERTY_CONST
),
902 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong
, offsetof(ExecContext
, restrict_namespaces
), SD_BUS_VTABLE_PROPERTY_CONST
),
903 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
904 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
905 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
906 SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool
, offsetof(ExecContext
, mount_apivfs
), SD_BUS_VTABLE_PROPERTY_CONST
),
907 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode
, offsetof(ExecContext
, keyring_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
908 SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_hostname
), SD_BUS_VTABLE_PROPERTY_CONST
),
909 SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL
, offsetof(ExecContext
, network_namespace_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
911 /* Obsolete/redundant properties: */
912 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
913 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
914 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
915 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
916 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
921 static int append_exec_command(sd_bus_message
*reply
, ExecCommand
*c
) {
930 r
= sd_bus_message_open_container(reply
, 'r', "sasbttttuii");
934 r
= sd_bus_message_append(reply
, "s", c
->path
);
938 r
= sd_bus_message_append_strv(reply
, c
->argv
);
942 r
= sd_bus_message_append(reply
, "bttttuii",
943 !!(c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
),
944 c
->exec_status
.start_timestamp
.realtime
,
945 c
->exec_status
.start_timestamp
.monotonic
,
946 c
->exec_status
.exit_timestamp
.realtime
,
947 c
->exec_status
.exit_timestamp
.monotonic
,
948 (uint32_t) c
->exec_status
.pid
,
949 (int32_t) c
->exec_status
.code
,
950 (int32_t) c
->exec_status
.status
);
954 return sd_bus_message_close_container(reply
);
957 static int append_exec_ex_command(sd_bus_message
*reply
, ExecCommand
*c
) {
958 _cleanup_strv_free_
char **ex_opts
= NULL
;
967 r
= sd_bus_message_open_container(reply
, 'r', "sasasttttuii");
971 r
= sd_bus_message_append(reply
, "s", c
->path
);
975 r
= sd_bus_message_append_strv(reply
, c
->argv
);
979 r
= exec_command_flags_to_strv(c
->flags
, &ex_opts
);
983 r
= sd_bus_message_append_strv(reply
, ex_opts
);
987 r
= sd_bus_message_append(reply
, "ttttuii",
988 c
->exec_status
.start_timestamp
.realtime
,
989 c
->exec_status
.start_timestamp
.monotonic
,
990 c
->exec_status
.exit_timestamp
.realtime
,
991 c
->exec_status
.exit_timestamp
.monotonic
,
992 (uint32_t) c
->exec_status
.pid
,
993 (int32_t) c
->exec_status
.code
,
994 (int32_t) c
->exec_status
.status
);
998 return sd_bus_message_close_container(reply
);
1001 int bus_property_get_exec_command(
1004 const char *interface
,
1005 const char *property
,
1006 sd_bus_message
*reply
,
1008 sd_bus_error
*ret_error
) {
1010 ExecCommand
*c
= (ExecCommand
*) userdata
;
1016 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
1020 r
= append_exec_command(reply
, c
);
1024 return sd_bus_message_close_container(reply
);
1027 int bus_property_get_exec_command_list(
1030 const char *interface
,
1031 const char *property
,
1032 sd_bus_message
*reply
,
1034 sd_bus_error
*ret_error
) {
1036 ExecCommand
*c
= *(ExecCommand
**) userdata
;
1042 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
1046 LIST_FOREACH(command
, c
, c
) {
1047 r
= append_exec_command(reply
, c
);
1052 return sd_bus_message_close_container(reply
);
1055 int bus_property_get_exec_ex_command_list(
1058 const char *interface
,
1059 const char *property
,
1060 sd_bus_message
*reply
,
1062 sd_bus_error
*ret_error
) {
1064 ExecCommand
*c
, *exec_command
= *(ExecCommand
**) userdata
;
1070 r
= sd_bus_message_open_container(reply
, 'a', "(sasasttttuii)");
1074 LIST_FOREACH(command
, c
, exec_command
) {
1075 r
= append_exec_ex_command(reply
, c
);
1080 return sd_bus_message_close_container(reply
);
1083 static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags
) {
1084 return strjoin(FLAGS_SET(flags
, EXEC_COMMAND_IGNORE_FAILURE
) ? "-" : "",
1085 FLAGS_SET(flags
, EXEC_COMMAND_NO_ENV_EXPAND
) ? ":" : "",
1086 FLAGS_SET(flags
, EXEC_COMMAND_FULLY_PRIVILEGED
) ? "+" : "",
1087 FLAGS_SET(flags
, EXEC_COMMAND_NO_SETUID
) ? "!" : "",
1088 FLAGS_SET(flags
, EXEC_COMMAND_AMBIENT_MAGIC
) ? "!!" : "");
1091 int bus_set_transient_exec_command(
1094 ExecCommand
**exec_command
,
1095 sd_bus_message
*message
,
1096 UnitWriteFlags flags
,
1097 sd_bus_error
*error
) {
1098 bool is_ex_prop
= endswith(name
, "Ex");
1102 r
= sd_bus_message_enter_container(message
, 'a', is_ex_prop
? "(sasas)" : "(sasb)");
1106 while ((r
= sd_bus_message_enter_container(message
, 'r', is_ex_prop
? "sasas" : "sasb")) > 0) {
1107 _cleanup_strv_free_
char **argv
= NULL
, **ex_opts
= NULL
;
1111 r
= sd_bus_message_read(message
, "s", &path
);
1115 if (!path_is_absolute(path
))
1116 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
1118 r
= sd_bus_message_read_strv(message
, &argv
);
1122 r
= is_ex_prop
? sd_bus_message_read_strv(message
, &ex_opts
) : sd_bus_message_read(message
, "b", &b
);
1126 r
= sd_bus_message_exit_container(message
);
1130 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1133 c
= new0(ExecCommand
, 1);
1137 c
->path
= strdup(path
);
1143 c
->argv
= TAKE_PTR(argv
);
1146 r
= exec_command_flags_from_strv(ex_opts
, &c
->flags
);
1150 c
->flags
= b
? EXEC_COMMAND_IGNORE_FAILURE
: 0;
1152 path_simplify(c
->path
, false);
1153 exec_command_append_list(exec_command
, c
);
1161 r
= sd_bus_message_exit_container(message
);
1165 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1166 _cleanup_free_
char *buf
= NULL
;
1167 _cleanup_fclose_
FILE *f
= NULL
;
1172 *exec_command
= exec_command_free_list(*exec_command
);
1174 f
= open_memstream_unlocked(&buf
, &size
);
1178 fprintf(f
, "%s=\n", name
);
1180 LIST_FOREACH(command
, c
, *exec_command
) {
1181 _cleanup_free_
char *a
= NULL
, *exec_chars
= NULL
;
1183 exec_chars
= exec_command_flags_to_exec_chars(c
->flags
);
1187 a
= unit_concat_strv(c
->argv
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
);
1191 if (streq_ptr(c
->path
, c
->argv
? c
->argv
[0] : NULL
))
1192 fprintf(f
, "%s=%s%s\n", name
, exec_chars
, a
);
1194 _cleanup_free_
char *t
= NULL
;
1197 p
= unit_escape_setting(c
->path
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
, &t
);
1201 fprintf(f
, "%s=%s@%s %s\n", name
, exec_chars
, p
, a
);
1205 r
= fflush_and_check(f
);
1209 unit_write_setting(u
, flags
, name
, buf
);
1215 static int parse_personality(const char *s
, unsigned long *p
) {
1220 v
= personality_from_string(s
);
1221 if (v
== PERSONALITY_INVALID
)
1228 static const char* mount_propagation_flags_to_string_with_check(unsigned long n
) {
1229 if (!IN_SET(n
, 0, MS_SHARED
, MS_PRIVATE
, MS_SLAVE
))
1232 return mount_propagation_flags_to_string(n
);
1235 static BUS_DEFINE_SET_TRANSIENT(nsec
, "t", uint64_t, nsec_t
, NSEC_FMT
);
1236 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level
, "i", int32_t, int, "%" PRIi32
, log_level_is_valid
);
1238 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno
, "i", int32_t, int, "%" PRIi32
, errno_is_valid
);
1240 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input
, ExecInput
, exec_input_from_string
);
1241 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output
, ExecOutput
, exec_output_from_string
);
1242 static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode
, ExecUtmpMode
, exec_utmp_mode_from_string
);
1243 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system
, ProtectSystem
, protect_system_from_string
);
1244 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home
, ProtectHome
, protect_home_from_string
);
1245 static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode
, ExecKeyringMode
, exec_keyring_mode_from_string
);
1246 static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode
, ExecPreserveMode
, exec_preserve_mode_from_string
);
1247 static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality
, unsigned long, parse_personality
);
1248 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits
, "i", int32_t, int, "%" PRIi32
, secure_bits_to_string_alloc_with_check
);
1249 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability
, "t", uint64_t, uint64_t, "%" PRIu64
, capability_set_to_string_alloc
);
1250 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag
, "t", uint64_t, unsigned long, "%" PRIu64
, namespace_flags_to_string
);
1251 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags
, "t", uint64_t, unsigned long, "%" PRIu64
, mount_propagation_flags_to_string_with_check
);
1253 int bus_exec_context_set_transient_property(
1257 sd_bus_message
*message
,
1258 UnitWriteFlags flags
,
1259 sd_bus_error
*error
) {
1269 flags
|= UNIT_PRIVATE
;
1271 if (streq(name
, "User"))
1272 return bus_set_transient_user_relaxed(u
, name
, &c
->user
, message
, flags
, error
);
1274 if (streq(name
, "Group"))
1275 return bus_set_transient_user_relaxed(u
, name
, &c
->group
, message
, flags
, error
);
1277 if (streq(name
, "TTYPath"))
1278 return bus_set_transient_path(u
, name
, &c
->tty_path
, message
, flags
, error
);
1280 if (streq(name
, "RootImage"))
1281 return bus_set_transient_path(u
, name
, &c
->root_image
, message
, flags
, error
);
1283 if (streq(name
, "RootHash")) {
1284 const void *roothash_decoded
;
1285 size_t roothash_decoded_size
;
1287 r
= sd_bus_message_read_array(message
, 'y', &roothash_decoded
, &roothash_decoded_size
);
1291 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1292 _cleanup_free_
char *encoded
= NULL
;
1294 if (roothash_decoded_size
== 0) {
1295 c
->root_hash_path
= mfree(c
->root_hash_path
);
1296 c
->root_hash
= mfree(c
->root_hash
);
1297 c
->root_hash_size
= 0;
1299 unit_write_settingf(u
, flags
, name
, "RootHash=");
1301 _cleanup_free_
void *p
;
1303 encoded
= hexmem(roothash_decoded
, roothash_decoded_size
);
1307 p
= memdup(roothash_decoded
, roothash_decoded_size
);
1311 free_and_replace(c
->root_hash
, p
);
1312 c
->root_hash_size
= roothash_decoded_size
;
1313 c
->root_hash_path
= mfree(c
->root_hash_path
);
1315 unit_write_settingf(u
, flags
, name
, "RootHash=%s", encoded
);
1322 if (streq(name
, "RootHashPath")) {
1323 c
->root_hash_size
= 0;
1324 c
->root_hash
= mfree(c
->root_hash
);
1326 return bus_set_transient_path(u
, "RootHash", &c
->root_hash_path
, message
, flags
, error
);
1329 if (streq(name
, "RootVerity"))
1330 return bus_set_transient_path(u
, name
, &c
->root_verity
, message
, flags
, error
);
1332 if (streq(name
, "RootDirectory"))
1333 return bus_set_transient_path(u
, name
, &c
->root_directory
, message
, flags
, error
);
1335 if (streq(name
, "SyslogIdentifier"))
1336 return bus_set_transient_string(u
, name
, &c
->syslog_identifier
, message
, flags
, error
);
1338 if (streq(name
, "LogLevelMax"))
1339 return bus_set_transient_log_level(u
, name
, &c
->log_level_max
, message
, flags
, error
);
1341 if (streq(name
, "LogRateLimitIntervalUSec"))
1342 return bus_set_transient_usec(u
, name
, &c
->log_ratelimit_interval_usec
, message
, flags
, error
);
1344 if (streq(name
, "LogRateLimitBurst"))
1345 return bus_set_transient_unsigned(u
, name
, &c
->log_ratelimit_burst
, message
, flags
, error
);
1347 if (streq(name
, "Personality"))
1348 return bus_set_transient_personality(u
, name
, &c
->personality
, message
, flags
, error
);
1350 if (streq(name
, "StandardInput"))
1351 return bus_set_transient_std_input(u
, name
, &c
->std_input
, message
, flags
, error
);
1353 if (streq(name
, "StandardOutput"))
1354 return bus_set_transient_std_output(u
, name
, &c
->std_output
, message
, flags
, error
);
1356 if (streq(name
, "StandardError"))
1357 return bus_set_transient_std_output(u
, name
, &c
->std_error
, message
, flags
, error
);
1359 if (streq(name
, "IgnoreSIGPIPE"))
1360 return bus_set_transient_bool(u
, name
, &c
->ignore_sigpipe
, message
, flags
, error
);
1362 if (streq(name
, "TTYVHangup"))
1363 return bus_set_transient_bool(u
, name
, &c
->tty_vhangup
, message
, flags
, error
);
1365 if (streq(name
, "TTYReset"))
1366 return bus_set_transient_bool(u
, name
, &c
->tty_reset
, message
, flags
, error
);
1368 if (streq(name
, "TTYVTDisallocate"))
1369 return bus_set_transient_bool(u
, name
, &c
->tty_vt_disallocate
, message
, flags
, error
);
1371 if (streq(name
, "PrivateTmp"))
1372 return bus_set_transient_bool(u
, name
, &c
->private_tmp
, message
, flags
, error
);
1374 if (streq(name
, "PrivateDevices"))
1375 return bus_set_transient_bool(u
, name
, &c
->private_devices
, message
, flags
, error
);
1377 if (streq(name
, "PrivateMounts"))
1378 return bus_set_transient_bool(u
, name
, &c
->private_mounts
, message
, flags
, error
);
1380 if (streq(name
, "PrivateNetwork"))
1381 return bus_set_transient_bool(u
, name
, &c
->private_network
, message
, flags
, error
);
1383 if (streq(name
, "PrivateUsers"))
1384 return bus_set_transient_bool(u
, name
, &c
->private_users
, message
, flags
, error
);
1386 if (streq(name
, "NoNewPrivileges"))
1387 return bus_set_transient_bool(u
, name
, &c
->no_new_privileges
, message
, flags
, error
);
1389 if (streq(name
, "SyslogLevelPrefix"))
1390 return bus_set_transient_bool(u
, name
, &c
->syslog_level_prefix
, message
, flags
, error
);
1392 if (streq(name
, "MemoryDenyWriteExecute"))
1393 return bus_set_transient_bool(u
, name
, &c
->memory_deny_write_execute
, message
, flags
, error
);
1395 if (streq(name
, "RestrictRealtime"))
1396 return bus_set_transient_bool(u
, name
, &c
->restrict_realtime
, message
, flags
, error
);
1398 if (streq(name
, "RestrictSUIDSGID"))
1399 return bus_set_transient_bool(u
, name
, &c
->restrict_suid_sgid
, message
, flags
, error
);
1401 if (streq(name
, "DynamicUser"))
1402 return bus_set_transient_bool(u
, name
, &c
->dynamic_user
, message
, flags
, error
);
1404 if (streq(name
, "RemoveIPC"))
1405 return bus_set_transient_bool(u
, name
, &c
->remove_ipc
, message
, flags
, error
);
1407 if (streq(name
, "ProtectKernelTunables"))
1408 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_tunables
, message
, flags
, error
);
1410 if (streq(name
, "ProtectKernelModules"))
1411 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_modules
, message
, flags
, error
);
1413 if (streq(name
, "ProtectKernelLogs"))
1414 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_logs
, message
, flags
, error
);
1416 if (streq(name
, "ProtectClock"))
1417 return bus_set_transient_bool(u
, name
, &c
->protect_clock
, message
, flags
, error
);
1419 if (streq(name
, "ProtectControlGroups"))
1420 return bus_set_transient_bool(u
, name
, &c
->protect_control_groups
, message
, flags
, error
);
1422 if (streq(name
, "MountAPIVFS"))
1423 return bus_set_transient_bool(u
, name
, &c
->mount_apivfs
, message
, flags
, error
);
1425 if (streq(name
, "CPUSchedulingResetOnFork"))
1426 return bus_set_transient_bool(u
, name
, &c
->cpu_sched_reset_on_fork
, message
, flags
, error
);
1428 if (streq(name
, "NonBlocking"))
1429 return bus_set_transient_bool(u
, name
, &c
->non_blocking
, message
, flags
, error
);
1431 if (streq(name
, "LockPersonality"))
1432 return bus_set_transient_bool(u
, name
, &c
->lock_personality
, message
, flags
, error
);
1434 if (streq(name
, "ProtectHostname"))
1435 return bus_set_transient_bool(u
, name
, &c
->protect_hostname
, message
, flags
, error
);
1437 if (streq(name
, "UtmpIdentifier"))
1438 return bus_set_transient_string(u
, name
, &c
->utmp_id
, message
, flags
, error
);
1440 if (streq(name
, "UtmpMode"))
1441 return bus_set_transient_utmp_mode(u
, name
, &c
->utmp_mode
, message
, flags
, error
);
1443 if (streq(name
, "PAMName"))
1444 return bus_set_transient_string(u
, name
, &c
->pam_name
, message
, flags
, error
);
1446 if (streq(name
, "TimerSlackNSec"))
1447 return bus_set_transient_nsec(u
, name
, &c
->timer_slack_nsec
, message
, flags
, error
);
1449 if (streq(name
, "ProtectSystem"))
1450 return bus_set_transient_protect_system(u
, name
, &c
->protect_system
, message
, flags
, error
);
1452 if (streq(name
, "ProtectHome"))
1453 return bus_set_transient_protect_home(u
, name
, &c
->protect_home
, message
, flags
, error
);
1455 if (streq(name
, "KeyringMode"))
1456 return bus_set_transient_keyring_mode(u
, name
, &c
->keyring_mode
, message
, flags
, error
);
1458 if (streq(name
, "RuntimeDirectoryPreserve"))
1459 return bus_set_transient_preserve_mode(u
, name
, &c
->runtime_directory_preserve_mode
, message
, flags
, error
);
1461 if (streq(name
, "UMask"))
1462 return bus_set_transient_mode_t(u
, name
, &c
->umask
, message
, flags
, error
);
1464 if (streq(name
, "RuntimeDirectoryMode"))
1465 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_RUNTIME
].mode
, message
, flags
, error
);
1467 if (streq(name
, "StateDirectoryMode"))
1468 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_STATE
].mode
, message
, flags
, error
);
1470 if (streq(name
, "CacheDirectoryMode"))
1471 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CACHE
].mode
, message
, flags
, error
);
1473 if (streq(name
, "LogsDirectoryMode"))
1474 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_LOGS
].mode
, message
, flags
, error
);
1476 if (streq(name
, "ConfigurationDirectoryMode"))
1477 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
, message
, flags
, error
);
1479 if (streq(name
, "SELinuxContext"))
1480 return bus_set_transient_string(u
, name
, &c
->selinux_context
, message
, flags
, error
);
1482 if (streq(name
, "SecureBits"))
1483 return bus_set_transient_secure_bits(u
, name
, &c
->secure_bits
, message
, flags
, error
);
1485 if (streq(name
, "CapabilityBoundingSet"))
1486 return bus_set_transient_capability(u
, name
, &c
->capability_bounding_set
, message
, flags
, error
);
1488 if (streq(name
, "AmbientCapabilities"))
1489 return bus_set_transient_capability(u
, name
, &c
->capability_ambient_set
, message
, flags
, error
);
1491 if (streq(name
, "RestrictNamespaces"))
1492 return bus_set_transient_namespace_flag(u
, name
, &c
->restrict_namespaces
, message
, flags
, error
);
1494 if (streq(name
, "MountFlags"))
1495 return bus_set_transient_mount_flags(u
, name
, &c
->mount_flags
, message
, flags
, error
);
1497 if (streq(name
, "NetworkNamespacePath"))
1498 return bus_set_transient_path(u
, name
, &c
->network_namespace_path
, message
, flags
, error
);
1500 if (streq(name
, "SupplementaryGroups")) {
1501 _cleanup_strv_free_
char **l
= NULL
;
1504 r
= sd_bus_message_read_strv(message
, &l
);
1509 if (!isempty(*p
) && !valid_user_group_name(*p
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
))
1510 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
1511 "Invalid supplementary group names");
1513 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1514 if (strv_isempty(l
)) {
1515 c
->supplementary_groups
= strv_free(c
->supplementary_groups
);
1516 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1518 _cleanup_free_
char *joined
= NULL
;
1520 r
= strv_extend_strv(&c
->supplementary_groups
, l
, true);
1524 joined
= strv_join(c
->supplementary_groups
, " ");
1528 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s", name
, joined
);
1534 } else if (streq(name
, "SyslogLevel")) {
1537 r
= sd_bus_message_read(message
, "i", &level
);
1541 if (!log_level_is_valid(level
))
1542 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log level value out of range");
1544 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1545 c
->syslog_priority
= (c
->syslog_priority
& LOG_FACMASK
) | level
;
1546 unit_write_settingf(u
, flags
, name
, "SyslogLevel=%i", level
);
1551 } else if (streq(name
, "SyslogFacility")) {
1554 r
= sd_bus_message_read(message
, "i", &facility
);
1558 if (!log_facility_unshifted_is_valid(facility
))
1559 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log facility value out of range");
1561 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1562 c
->syslog_priority
= (facility
<< 3) | LOG_PRI(c
->syslog_priority
);
1563 unit_write_settingf(u
, flags
, name
, "SyslogFacility=%i", facility
);
1568 } else if (streq(name
, "LogNamespace")) {
1571 r
= sd_bus_message_read(message
, "s", &n
);
1575 if (!isempty(n
) && !log_namespace_name_valid(n
))
1576 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log namespace name not valid");
1578 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1581 c
->log_namespace
= mfree(c
->log_namespace
);
1582 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1584 r
= free_and_strdup(&c
->log_namespace
, n
);
1588 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, n
);
1594 } else if (streq(name
, "LogExtraFields")) {
1597 r
= sd_bus_message_enter_container(message
, 'a', "ay");
1602 _cleanup_free_
void *copy
= NULL
;
1608 /* Note that we expect a byte array for each field, instead of a string. That's because on the
1609 * lower-level journal fields can actually contain binary data and are not restricted to text,
1610 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
1611 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
1612 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
1613 * limitation, should a good, valid usecase arise. */
1615 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
1621 if (memchr(p
, 0, sz
))
1622 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains zero byte");
1624 eq
= memchr(p
, '=', sz
);
1626 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains no '=' character");
1627 if (!journal_field_valid(p
, eq
- (const char*) p
, false))
1628 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field invalid");
1630 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1631 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
1634 c
->log_extra_fields
= t
;
1637 copy
= malloc(sz
+ 1);
1641 memcpy(copy
, p
, sz
);
1642 ((uint8_t*) copy
)[sz
] = 0;
1644 if (!utf8_is_valid(copy
))
1645 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field is not valid UTF-8");
1647 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1648 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE(copy
, sz
);
1649 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
, name
, "LogExtraFields=%s", (char*) copy
);
1657 r
= sd_bus_message_exit_container(message
);
1661 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && n
== 0) {
1662 exec_context_free_log_extra_fields(c
);
1663 unit_write_setting(u
, flags
, name
, "LogExtraFields=");
1671 if (streq(name
, "SystemCallErrorNumber"))
1672 return bus_set_transient_errno(u
, name
, &c
->syscall_errno
, message
, flags
, error
);
1674 if (streq(name
, "SystemCallFilter")) {
1676 _cleanup_strv_free_
char **l
= NULL
;
1678 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1682 r
= sd_bus_message_read(message
, "b", &whitelist
);
1686 r
= sd_bus_message_read_strv(message
, &l
);
1690 r
= sd_bus_message_exit_container(message
);
1694 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1695 _cleanup_free_
char *joined
= NULL
;
1696 SeccompParseFlags invert_flag
= whitelist
? 0 : SECCOMP_PARSE_INVERT
;
1699 if (strv_isempty(l
)) {
1700 c
->syscall_whitelist
= false;
1701 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
1703 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=");
1707 if (!c
->syscall_filter
) {
1708 c
->syscall_filter
= hashmap_new(NULL
);
1709 if (!c
->syscall_filter
)
1712 c
->syscall_whitelist
= whitelist
;
1714 if (c
->syscall_whitelist
) {
1715 r
= seccomp_parse_syscall_filter("@default",
1718 SECCOMP_PARSE_PERMISSIVE
|
1719 SECCOMP_PARSE_WHITELIST
| invert_flag
,
1727 STRV_FOREACH(s
, l
) {
1728 _cleanup_free_
char *n
= NULL
;
1731 r
= parse_syscall_and_errno(*s
, &n
, &e
);
1735 r
= seccomp_parse_syscall_filter(n
,
1738 SECCOMP_PARSE_LOG
| SECCOMP_PARSE_PERMISSIVE
|
1740 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
1747 joined
= strv_join(l
, " ");
1751 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=%s%s", whitelist
? "" : "~", joined
);
1756 } else if (streq(name
, "SystemCallArchitectures")) {
1757 _cleanup_strv_free_
char **l
= NULL
;
1759 r
= sd_bus_message_read_strv(message
, &l
);
1763 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1764 _cleanup_free_
char *joined
= NULL
;
1766 if (strv_isempty(l
))
1767 c
->syscall_archs
= set_free(c
->syscall_archs
);
1771 STRV_FOREACH(s
, l
) {
1774 r
= seccomp_arch_from_string(*s
, &a
);
1778 r
= set_ensure_put(&c
->syscall_archs
, NULL
, UINT32_TO_PTR(a
+ 1));
1785 joined
= strv_join(l
, " ");
1789 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
1794 } else if (streq(name
, "RestrictAddressFamilies")) {
1796 _cleanup_strv_free_
char **l
= NULL
;
1798 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1802 r
= sd_bus_message_read(message
, "b", &whitelist
);
1806 r
= sd_bus_message_read_strv(message
, &l
);
1810 r
= sd_bus_message_exit_container(message
);
1814 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1815 _cleanup_free_
char *joined
= NULL
;
1818 if (strv_isempty(l
)) {
1819 c
->address_families_whitelist
= false;
1820 c
->address_families
= set_free(c
->address_families
);
1822 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=");
1826 if (!c
->address_families
) {
1827 c
->address_families
= set_new(NULL
);
1828 if (!c
->address_families
)
1831 c
->address_families_whitelist
= whitelist
;
1834 STRV_FOREACH(s
, l
) {
1837 af
= af_from_name(*s
);
1841 if (whitelist
== c
->address_families_whitelist
) {
1842 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
1846 (void) set_remove(c
->address_families
, INT_TO_PTR(af
));
1849 joined
= strv_join(l
, " ");
1853 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=%s%s", whitelist
? "" : "~", joined
);
1859 if (STR_IN_SET(name
, "CPUAffinity", "NUMAMask")) {
1862 bool affinity
= streq(name
, "CPUAffinity");
1863 _cleanup_(cpu_set_reset
) CPUSet set
= {};
1865 r
= sd_bus_message_read_array(message
, 'y', &a
, &n
);
1869 r
= cpu_set_from_dbus(a
, n
, &set
);
1873 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1875 cpu_set_reset(affinity
? &c
->cpu_set
: &c
->numa_policy
.nodes
);
1876 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1878 _cleanup_free_
char *str
= NULL
;
1880 str
= cpu_set_to_string(&set
);
1884 /* We forego any optimizations here, and always create the structure using
1885 * cpu_set_add_all(), because we don't want to care if the existing size we
1886 * got over dbus is appropriate. */
1887 r
= cpu_set_add_all(affinity
? &c
->cpu_set
: &c
->numa_policy
.nodes
, &set
);
1891 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, str
);
1897 } else if (streq(name
, "CPUAffinityFromNUMA")) {
1900 r
= sd_bus_message_read_basic(message
, 'b', &q
);
1904 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1905 c
->cpu_affinity_from_numa
= q
;
1906 unit_write_settingf(u
, flags
, name
, "%s=%s", "CPUAffinity", "numa");
1911 } else if (streq(name
, "NUMAPolicy")) {
1914 r
= sd_bus_message_read(message
, "i", &type
);
1918 if (!mpol_is_valid(type
))
1919 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid NUMAPolicy value: %i", type
);
1921 if (!UNIT_WRITE_FLAGS_NOOP(flags
))
1922 c
->numa_policy
.type
= type
;
1926 } else if (streq(name
, "Nice")) {
1929 r
= sd_bus_message_read(message
, "i", &q
);
1933 if (!nice_is_valid(q
))
1934 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid Nice value: %i", q
);
1936 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1940 unit_write_settingf(u
, flags
, name
, "Nice=%i", q
);
1945 } else if (streq(name
, "CPUSchedulingPolicy")) {
1948 r
= sd_bus_message_read(message
, "i", &q
);
1952 if (!sched_policy_is_valid(q
))
1953 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling policy: %i", q
);
1955 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1956 _cleanup_free_
char *s
= NULL
;
1958 r
= sched_policy_to_string_alloc(q
, &s
);
1962 c
->cpu_sched_policy
= q
;
1963 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(q
), sched_get_priority_max(q
));
1964 c
->cpu_sched_set
= true;
1966 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPolicy=%s", s
);
1971 } else if (streq(name
, "CPUSchedulingPriority")) {
1972 int32_t p
, min
, max
;
1974 r
= sd_bus_message_read(message
, "i", &p
);
1978 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1979 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1980 if (p
< min
|| p
> max
)
1981 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling priority: %i", p
);
1983 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1984 c
->cpu_sched_priority
= p
;
1985 c
->cpu_sched_set
= true;
1987 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPriority=%i", p
);
1992 } else if (streq(name
, "IOSchedulingClass")) {
1995 r
= sd_bus_message_read(message
, "i", &q
);
1999 if (!ioprio_class_is_valid(q
))
2000 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling class: %i", q
);
2002 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2003 _cleanup_free_
char *s
= NULL
;
2005 r
= ioprio_class_to_string_alloc(q
, &s
);
2009 c
->ioprio
= IOPRIO_PRIO_VALUE(q
, IOPRIO_PRIO_DATA(c
->ioprio
));
2010 c
->ioprio_set
= true;
2012 unit_write_settingf(u
, flags
, name
, "IOSchedulingClass=%s", s
);
2017 } else if (streq(name
, "IOSchedulingPriority")) {
2020 r
= sd_bus_message_read(message
, "i", &p
);
2024 if (!ioprio_priority_is_valid(p
))
2025 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling priority: %i", p
);
2027 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2028 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), p
);
2029 c
->ioprio_set
= true;
2031 unit_write_settingf(u
, flags
, name
, "IOSchedulingPriority=%i", p
);
2036 } else if (streq(name
, "WorkingDirectory")) {
2040 r
= sd_bus_message_read(message
, "s", &s
);
2050 if (!isempty(s
) && !streq(s
, "~") && !path_is_absolute(s
))
2051 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "WorkingDirectory= expects an absolute path or '~'");
2053 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2054 if (streq(s
, "~")) {
2055 c
->working_directory
= mfree(c
->working_directory
);
2056 c
->working_directory_home
= true;
2058 r
= free_and_strdup(&c
->working_directory
, empty_to_null(s
));
2062 c
->working_directory_home
= false;
2065 c
->working_directory_missing_ok
= missing_ok
;
2066 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "WorkingDirectory=%s%s", missing_ok
? "-" : "", s
);
2071 } else if (STR_IN_SET(name
,
2072 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
2075 r
= sd_bus_message_read(message
, "s", &s
);
2079 if (!isempty(s
) && !fdname_is_valid(s
))
2080 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid file descriptor name");
2082 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2084 if (streq(name
, "StandardInputFileDescriptorName")) {
2085 r
= free_and_strdup(c
->stdio_fdname
+ STDIN_FILENO
, empty_to_null(s
));
2089 c
->std_input
= EXEC_INPUT_NAMED_FD
;
2090 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=fd:%s", exec_context_fdname(c
, STDIN_FILENO
));
2092 } else if (streq(name
, "StandardOutputFileDescriptorName")) {
2093 r
= free_and_strdup(c
->stdio_fdname
+ STDOUT_FILENO
, empty_to_null(s
));
2097 c
->std_output
= EXEC_OUTPUT_NAMED_FD
;
2098 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=fd:%s", exec_context_fdname(c
, STDOUT_FILENO
));
2101 assert(streq(name
, "StandardErrorFileDescriptorName"));
2103 r
= free_and_strdup(&c
->stdio_fdname
[STDERR_FILENO
], empty_to_null(s
));
2107 c
->std_error
= EXEC_OUTPUT_NAMED_FD
;
2108 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=fd:%s", exec_context_fdname(c
, STDERR_FILENO
));
2114 } else if (STR_IN_SET(name
,
2115 "StandardInputFile",
2116 "StandardOutputFile", "StandardOutputFileToAppend",
2117 "StandardErrorFile", "StandardErrorFileToAppend")) {
2120 r
= sd_bus_message_read(message
, "s", &s
);
2125 if (!path_is_absolute(s
))
2126 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute", s
);
2127 if (!path_is_normalized(s
))
2128 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not normalized", s
);
2131 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2133 if (streq(name
, "StandardInputFile")) {
2134 r
= free_and_strdup(&c
->stdio_file
[STDIN_FILENO
], empty_to_null(s
));
2138 c
->std_input
= EXEC_INPUT_FILE
;
2139 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=file:%s", s
);
2141 } else if (STR_IN_SET(name
, "StandardOutputFile", "StandardOutputFileToAppend")) {
2142 r
= free_and_strdup(&c
->stdio_file
[STDOUT_FILENO
], empty_to_null(s
));
2146 if (streq(name
, "StandardOutputFile")) {
2147 c
->std_output
= EXEC_OUTPUT_FILE
;
2148 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=file:%s", s
);
2150 assert(streq(name
, "StandardOutputFileToAppend"));
2151 c
->std_output
= EXEC_OUTPUT_FILE_APPEND
;
2152 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=append:%s", s
);
2155 assert(STR_IN_SET(name
, "StandardErrorFile", "StandardErrorFileToAppend"));
2157 r
= free_and_strdup(&c
->stdio_file
[STDERR_FILENO
], empty_to_null(s
));
2161 if (streq(name
, "StandardErrorFile")) {
2162 c
->std_error
= EXEC_OUTPUT_FILE
;
2163 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=file:%s", s
);
2165 assert(streq(name
, "StandardErrorFileToAppend"));
2166 c
->std_error
= EXEC_OUTPUT_FILE_APPEND
;
2167 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=append:%s", s
);
2174 } else if (streq(name
, "StandardInputData")) {
2178 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
2182 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2183 _cleanup_free_
char *encoded
= NULL
;
2186 c
->stdin_data
= mfree(c
->stdin_data
);
2187 c
->stdin_data_size
= 0;
2189 unit_write_settingf(u
, flags
, name
, "StandardInputData=");
2194 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
2195 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
)
2198 n
= base64mem(p
, sz
, &encoded
);
2202 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
2206 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
2209 c
->stdin_data_size
+= sz
;
2211 unit_write_settingf(u
, flags
, name
, "StandardInputData=%s", encoded
);
2217 } else if (streq(name
, "Environment")) {
2219 _cleanup_strv_free_
char **l
= NULL
;
2221 r
= sd_bus_message_read_strv(message
, &l
);
2225 if (!strv_env_is_valid(l
))
2226 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment block.");
2228 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2229 if (strv_isempty(l
)) {
2230 c
->environment
= strv_free(c
->environment
);
2231 unit_write_setting(u
, flags
, name
, "Environment=");
2233 _cleanup_free_
char *joined
= NULL
;
2236 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
2240 e
= strv_env_merge(2, c
->environment
, l
);
2244 strv_free_and_replace(c
->environment
, e
);
2245 unit_write_settingf(u
, flags
, name
, "Environment=%s", joined
);
2251 } else if (streq(name
, "UnsetEnvironment")) {
2253 _cleanup_strv_free_
char **l
= NULL
;
2255 r
= sd_bus_message_read_strv(message
, &l
);
2259 if (!strv_env_name_or_assignment_is_valid(l
))
2260 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid UnsetEnvironment= list.");
2262 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2263 if (strv_isempty(l
)) {
2264 c
->unset_environment
= strv_free(c
->unset_environment
);
2265 unit_write_setting(u
, flags
, name
, "UnsetEnvironment=");
2267 _cleanup_free_
char *joined
= NULL
;
2270 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
2274 e
= strv_env_merge(2, c
->unset_environment
, l
);
2278 strv_free_and_replace(c
->unset_environment
, e
);
2279 unit_write_settingf(u
, flags
, name
, "UnsetEnvironment=%s", joined
);
2285 } else if (streq(name
, "OOMScoreAdjust")) {
2288 r
= sd_bus_message_read(message
, "i", &oa
);
2292 if (!oom_score_adjust_is_valid(oa
))
2293 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "OOM score adjust value out of range");
2295 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2296 c
->oom_score_adjust
= oa
;
2297 c
->oom_score_adjust_set
= true;
2298 unit_write_settingf(u
, flags
, name
, "OOMScoreAdjust=%i", oa
);
2303 } else if (streq(name
, "CoredumpFilter")) {
2306 r
= sd_bus_message_read(message
, "t", &f
);
2310 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2311 c
->coredump_filter
= f
;
2312 c
->coredump_filter_set
= true;
2313 unit_write_settingf(u
, flags
, name
, "CoredumpFilter=0x%"PRIx64
, f
);
2318 } else if (streq(name
, "EnvironmentFiles")) {
2320 _cleanup_free_
char *joined
= NULL
;
2321 _cleanup_fclose_
FILE *f
= NULL
;
2322 _cleanup_strv_free_
char **l
= NULL
;
2326 r
= sd_bus_message_enter_container(message
, 'a', "(sb)");
2330 f
= open_memstream_unlocked(&joined
, &size
);
2334 fputs("EnvironmentFile=\n", f
);
2336 STRV_FOREACH(i
, c
->environment_files
) {
2337 _cleanup_free_
char *q
= NULL
;
2339 q
= specifier_escape(*i
);
2343 fprintf(f
, "EnvironmentFile=%s\n", q
);
2346 while ((r
= sd_bus_message_enter_container(message
, 'r', "sb")) > 0) {
2350 r
= sd_bus_message_read(message
, "sb", &path
, &b
);
2354 r
= sd_bus_message_exit_container(message
);
2358 if (!path_is_absolute(path
))
2359 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
2361 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2362 _cleanup_free_
char *q
= NULL
, *buf
= NULL
;
2364 buf
= strjoin(b
? "-" : "", path
);
2368 q
= specifier_escape(buf
);
2372 fprintf(f
, "EnvironmentFile=%s\n", q
);
2374 r
= strv_consume(&l
, TAKE_PTR(buf
));
2382 r
= sd_bus_message_exit_container(message
);
2386 r
= fflush_and_check(f
);
2390 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2391 if (strv_isempty(l
)) {
2392 c
->environment_files
= strv_free(c
->environment_files
);
2393 unit_write_setting(u
, flags
, name
, "EnvironmentFile=");
2395 r
= strv_extend_strv(&c
->environment_files
, l
, true);
2399 unit_write_setting(u
, flags
, name
, joined
);
2405 } else if (streq(name
, "PassEnvironment")) {
2407 _cleanup_strv_free_
char **l
= NULL
;
2409 r
= sd_bus_message_read_strv(message
, &l
);
2413 if (!strv_env_name_is_valid(l
))
2414 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PassEnvironment= block.");
2416 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2417 if (strv_isempty(l
)) {
2418 c
->pass_environment
= strv_free(c
->pass_environment
);
2419 unit_write_setting(u
, flags
, name
, "PassEnvironment=");
2421 _cleanup_free_
char *joined
= NULL
;
2423 r
= strv_extend_strv(&c
->pass_environment
, l
, true);
2427 /* We write just the new settings out to file, with unresolved specifiers. */
2428 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2432 unit_write_settingf(u
, flags
, name
, "PassEnvironment=%s", joined
);
2438 } else if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
2439 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) {
2440 _cleanup_strv_free_
char **l
= NULL
;
2444 r
= sd_bus_message_read_strv(message
, &l
);
2448 STRV_FOREACH(p
, l
) {
2452 offset
= i
[0] == '-';
2453 offset
+= i
[offset
] == '+';
2454 if (!path_is_absolute(i
+ offset
))
2455 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
2457 path_simplify(i
+ offset
, false);
2460 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2461 if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadWritePaths"))
2462 dirs
= &c
->read_write_paths
;
2463 else if (STR_IN_SET(name
, "ReadOnlyDirectories", "ReadOnlyPaths"))
2464 dirs
= &c
->read_only_paths
;
2465 else /* "InaccessiblePaths" */
2466 dirs
= &c
->inaccessible_paths
;
2468 if (strv_isempty(l
)) {
2469 *dirs
= strv_free(*dirs
);
2470 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2472 _cleanup_free_
char *joined
= NULL
;
2474 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2478 r
= strv_extend_strv(dirs
, l
, true);
2482 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2488 } else if (STR_IN_SET(name
, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
2489 _cleanup_strv_free_
char **l
= NULL
;
2492 r
= sd_bus_message_read_strv(message
, &l
);
2496 STRV_FOREACH(p
, l
) {
2497 if (!path_is_normalized(*p
))
2498 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is not normalized: %s", name
, *p
);
2500 if (path_is_absolute(*p
))
2501 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is absolute: %s", name
, *p
);
2503 if (path_startswith(*p
, "private"))
2504 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path can't be 'private': %s", name
, *p
);
2507 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2508 ExecDirectoryType i
;
2511 assert_se((i
= exec_directory_type_from_string(name
)) >= 0);
2512 d
= c
->directories
+ i
;
2514 if (strv_isempty(l
)) {
2515 d
->paths
= strv_free(d
->paths
);
2516 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2518 _cleanup_free_
char *joined
= NULL
;
2520 r
= strv_extend_strv(&d
->paths
, l
, true);
2524 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2528 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2534 } else if (STR_IN_SET(name
, "AppArmorProfile", "SmackProcessLabel")) {
2538 r
= sd_bus_message_read(message
, "(bs)", &ignore
, &s
);
2542 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2546 if (streq(name
, "AppArmorProfile")) {
2547 p
= &c
->apparmor_profile
;
2548 b
= &c
->apparmor_profile_ignore
;
2549 } else { /* "SmackProcessLabel" */
2550 p
= &c
->smack_process_label
;
2551 b
= &c
->smack_process_label_ignore
;
2558 if (free_and_strdup(p
, s
) < 0)
2563 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s%s", name
, ignore
? "-" : "", strempty(s
));
2568 } else if (STR_IN_SET(name
, "BindPaths", "BindReadOnlyPaths")) {
2569 char *source
, *destination
;
2571 uint64_t mount_flags
;
2574 r
= sd_bus_message_enter_container(message
, 'a', "(ssbt)");
2578 while ((r
= sd_bus_message_read(message
, "(ssbt)", &source
, &destination
, &ignore_enoent
, &mount_flags
)) > 0) {
2580 if (!path_is_absolute(source
))
2581 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
2582 if (!path_is_absolute(destination
))
2583 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
2584 if (!IN_SET(mount_flags
, 0, MS_REC
))
2585 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount flags.");
2587 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2588 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
2591 .destination
= destination
,
2592 .read_only
= !!strstr(name
, "ReadOnly"),
2593 .recursive
= !!(mount_flags
& MS_REC
),
2594 .ignore_enoent
= ignore_enoent
,
2599 unit_write_settingf(
2600 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2603 ignore_enoent
? "-" : "",
2606 (mount_flags
& MS_REC
) ? "rbind" : "norbind");
2614 r
= sd_bus_message_exit_container(message
);
2619 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
2620 c
->bind_mounts
= NULL
;
2621 c
->n_bind_mounts
= 0;
2623 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2628 } else if (streq(name
, "TemporaryFileSystem")) {
2629 const char *path
, *options
;
2632 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
2636 while ((r
= sd_bus_message_read(message
, "(ss)", &path
, &options
)) > 0) {
2638 if (!path_is_absolute(path
))
2639 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Mount point %s is not absolute.", path
);
2641 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2642 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, options
);
2646 unit_write_settingf(
2647 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2659 r
= sd_bus_message_exit_container(message
);
2664 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
2665 c
->temporary_filesystems
= NULL
;
2666 c
->n_temporary_filesystems
= 0;
2668 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2673 } else if ((suffix
= startswith(name
, "Limit"))) {
2674 const char *soft
= NULL
;
2677 ri
= rlimit_from_string(suffix
);
2679 soft
= endswith(suffix
, "Soft");
2683 n
= strndupa(suffix
, soft
- suffix
);
2684 ri
= rlimit_from_string(n
);
2686 name
= strjoina("Limit", n
);
2694 r
= sd_bus_message_read(message
, "t", &rl
);
2698 if (rl
== (uint64_t) -1)
2703 if ((uint64_t) x
!= rl
)
2707 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2708 _cleanup_free_
char *f
= NULL
;
2711 if (c
->rlimit
[ri
]) {
2712 nl
= *c
->rlimit
[ri
];
2719 /* When the resource limit is not initialized yet, then assign the value to both fields */
2720 nl
= (struct rlimit
) {
2725 r
= rlimit_format(&nl
, &f
);
2730 *c
->rlimit
[ri
] = nl
;
2732 c
->rlimit
[ri
] = newdup(struct rlimit
, &nl
, 1);
2737 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, f
);