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
);
62 static int property_get_environment_files(
65 const char *interface
,
67 sd_bus_message
*reply
,
69 sd_bus_error
*error
) {
71 ExecContext
*c
= userdata
;
79 r
= sd_bus_message_open_container(reply
, 'a', "(sb)");
83 STRV_FOREACH(j
, c
->environment_files
) {
86 r
= sd_bus_message_append(reply
, "(sb)", fn
[0] == '-' ? fn
+ 1 : fn
, fn
[0] == '-');
91 return sd_bus_message_close_container(reply
);
94 static int property_get_oom_score_adjust(
97 const char *interface
,
99 sd_bus_message
*reply
,
101 sd_bus_error
*error
) {
103 ExecContext
*c
= userdata
;
111 if (c
->oom_score_adjust_set
)
112 n
= c
->oom_score_adjust
;
114 _cleanup_free_
char *t
= NULL
;
117 r
= read_one_line_file("/proc/self/oom_score_adj", &t
);
119 log_debug_errno(r
, "Failed to read /proc/self/oom_score_adj, ignoring: %m");
121 r
= safe_atoi32(t
, &n
);
123 log_debug_errno(r
, "Failed to parse \"%s\" from /proc/self/oom_score_adj, ignoring: %m", t
);
127 return sd_bus_message_append(reply
, "i", n
);
130 static int property_get_coredump_filter(
133 const char *interface
,
134 const char *property
,
135 sd_bus_message
*reply
,
137 sd_bus_error
*error
) {
139 ExecContext
*c
= userdata
;
147 if (c
->coredump_filter_set
)
148 n
= c
->coredump_filter
;
150 _cleanup_free_
char *t
= NULL
;
152 n
= COREDUMP_FILTER_MASK_DEFAULT
;
153 r
= read_one_line_file("/proc/self/coredump_filter", &t
);
155 log_debug_errno(r
, "Failed to read /proc/self/coredump_filter, ignoring: %m");
157 r
= safe_atoux64(t
, &n
);
159 log_debug_errno(r
, "Failed to parse \"%s\" from /proc/self/coredump_filter, ignoring: %m", t
);
163 return sd_bus_message_append(reply
, "t", n
);
166 static int property_get_nice(
169 const char *interface
,
170 const char *property
,
171 sd_bus_message
*reply
,
173 sd_bus_error
*error
) {
175 ExecContext
*c
= userdata
;
186 n
= getpriority(PRIO_PROCESS
, 0);
191 return sd_bus_message_append(reply
, "i", n
);
194 static int property_get_cpu_sched_policy(
197 const char *interface
,
198 const char *property
,
199 sd_bus_message
*reply
,
201 sd_bus_error
*error
) {
203 ExecContext
*c
= userdata
;
210 if (c
->cpu_sched_set
)
211 n
= c
->cpu_sched_policy
;
213 n
= sched_getscheduler(0);
218 return sd_bus_message_append(reply
, "i", n
);
221 static int property_get_cpu_sched_priority(
224 const char *interface
,
225 const char *property
,
226 sd_bus_message
*reply
,
228 sd_bus_error
*error
) {
230 ExecContext
*c
= userdata
;
237 if (c
->cpu_sched_set
)
238 n
= c
->cpu_sched_priority
;
240 struct sched_param p
= {};
242 if (sched_getparam(0, &p
) >= 0)
243 n
= p
.sched_priority
;
248 return sd_bus_message_append(reply
, "i", n
);
251 static int property_get_cpu_affinity(
254 const char *interface
,
255 const char *property
,
256 sd_bus_message
*reply
,
258 sd_bus_error
*error
) {
260 ExecContext
*c
= userdata
;
261 _cleanup_(cpu_set_reset
) CPUSet s
= {};
262 _cleanup_free_
uint8_t *array
= NULL
;
269 if (c
->cpu_affinity_from_numa
) {
272 r
= numa_to_cpu_set(&c
->numa_policy
, &s
);
277 (void) cpu_set_to_dbus(c
->cpu_affinity_from_numa
? &s
: &c
->cpu_set
, &array
, &allocated
);
279 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
282 static int property_get_numa_mask(
285 const char *interface
,
286 const char *property
,
287 sd_bus_message
*reply
,
289 sd_bus_error
*error
) {
291 ExecContext
*c
= userdata
;
292 _cleanup_free_
uint8_t *array
= NULL
;
299 (void) cpu_set_to_dbus(&c
->numa_policy
.nodes
, &array
, &allocated
);
301 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
304 static int property_get_numa_policy(
307 const char *interface
,
308 const char *property
,
309 sd_bus_message
*reply
,
311 sd_bus_error
*error
) {
312 ExecContext
*c
= userdata
;
319 policy
= numa_policy_get_type(&c
->numa_policy
);
321 return sd_bus_message_append_basic(reply
, 'i', &policy
);
324 static int property_get_timer_slack_nsec(
327 const char *interface
,
328 const char *property
,
329 sd_bus_message
*reply
,
331 sd_bus_error
*error
) {
333 ExecContext
*c
= userdata
;
340 if (c
->timer_slack_nsec
!= NSEC_INFINITY
)
341 u
= (uint64_t) c
->timer_slack_nsec
;
343 u
= (uint64_t) prctl(PR_GET_TIMERSLACK
);
345 return sd_bus_message_append(reply
, "t", u
);
348 static int property_get_syscall_filter(
351 const char *interface
,
352 const char *property
,
353 sd_bus_message
*reply
,
355 sd_bus_error
*error
) {
357 ExecContext
*c
= userdata
;
358 _cleanup_strv_free_
char **l
= NULL
;
370 r
= sd_bus_message_open_container(reply
, 'r', "bas");
374 r
= sd_bus_message_append(reply
, "b", c
->syscall_whitelist
);
379 HASHMAP_FOREACH_KEY(val
, id
, c
->syscall_filter
, i
) {
380 _cleanup_free_
char *name
= NULL
;
381 const char *e
= NULL
;
383 int num
= PTR_TO_INT(val
);
385 name
= seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE
, PTR_TO_INT(id
) - 1);
390 e
= errno_to_name(num
);
392 s
= strjoin(name
, ":", e
);
396 r
= asprintf(&s
, "%s:%d", name
, num
);
403 r
= strv_consume(&l
, s
);
411 r
= sd_bus_message_append_strv(reply
, l
);
415 return sd_bus_message_close_container(reply
);
418 static int property_get_syscall_archs(
421 const char *interface
,
422 const char *property
,
423 sd_bus_message
*reply
,
425 sd_bus_error
*error
) {
427 ExecContext
*c
= userdata
;
428 _cleanup_strv_free_
char **l
= NULL
;
441 SET_FOREACH(id
, c
->syscall_archs
, i
) {
444 name
= seccomp_arch_to_string(PTR_TO_UINT32(id
) - 1);
448 r
= strv_extend(&l
, name
);
456 r
= sd_bus_message_append_strv(reply
, l
);
463 static int property_get_selinux_context(
466 const char *interface
,
467 const char *property
,
468 sd_bus_message
*reply
,
470 sd_bus_error
*error
) {
472 ExecContext
*c
= userdata
;
478 return sd_bus_message_append(reply
, "(bs)", c
->selinux_context_ignore
, c
->selinux_context
);
481 static int property_get_apparmor_profile(
484 const char *interface
,
485 const char *property
,
486 sd_bus_message
*reply
,
488 sd_bus_error
*error
) {
490 ExecContext
*c
= userdata
;
496 return sd_bus_message_append(reply
, "(bs)", c
->apparmor_profile_ignore
, c
->apparmor_profile
);
499 static int property_get_smack_process_label(
502 const char *interface
,
503 const char *property
,
504 sd_bus_message
*reply
,
506 sd_bus_error
*error
) {
508 ExecContext
*c
= userdata
;
514 return sd_bus_message_append(reply
, "(bs)", c
->smack_process_label_ignore
, c
->smack_process_label
);
517 static int property_get_address_families(
520 const char *interface
,
521 const char *property
,
522 sd_bus_message
*reply
,
524 sd_bus_error
*error
) {
526 ExecContext
*c
= userdata
;
527 _cleanup_strv_free_
char **l
= NULL
;
536 r
= sd_bus_message_open_container(reply
, 'r', "bas");
540 r
= sd_bus_message_append(reply
, "b", c
->address_families_whitelist
);
544 SET_FOREACH(af
, c
->address_families
, i
) {
547 name
= af_to_name(PTR_TO_INT(af
));
551 r
= strv_extend(&l
, name
);
558 r
= sd_bus_message_append_strv(reply
, l
);
562 return sd_bus_message_close_container(reply
);
565 static int property_get_working_directory(
568 const char *interface
,
569 const char *property
,
570 sd_bus_message
*reply
,
572 sd_bus_error
*error
) {
574 ExecContext
*c
= userdata
;
581 if (c
->working_directory_home
)
584 wd
= c
->working_directory
;
586 if (c
->working_directory_missing_ok
)
587 wd
= strjoina("!", wd
);
589 return sd_bus_message_append(reply
, "s", wd
);
592 static int property_get_stdio_fdname(
595 const char *interface
,
596 const char *property
,
597 sd_bus_message
*reply
,
599 sd_bus_error
*error
) {
601 ExecContext
*c
= userdata
;
609 if (streq(property
, "StandardInputFileDescriptorName"))
610 fileno
= STDIN_FILENO
;
611 else if (streq(property
, "StandardOutputFileDescriptorName"))
612 fileno
= STDOUT_FILENO
;
614 assert(streq(property
, "StandardErrorFileDescriptorName"));
615 fileno
= STDERR_FILENO
;
618 return sd_bus_message_append(reply
, "s", exec_context_fdname(c
, fileno
));
621 static int property_get_input_data(
624 const char *interface
,
625 const char *property
,
626 sd_bus_message
*reply
,
628 sd_bus_error
*error
) {
630 ExecContext
*c
= userdata
;
637 return sd_bus_message_append_array(reply
, 'y', c
->stdin_data
, c
->stdin_data_size
);
640 static int property_get_bind_paths(
643 const char *interface
,
644 const char *property
,
645 sd_bus_message
*reply
,
647 sd_bus_error
*error
) {
649 ExecContext
*c
= userdata
;
659 ro
= strstr(property
, "ReadOnly");
661 r
= sd_bus_message_open_container(reply
, 'a', "(ssbt)");
665 for (i
= 0; i
< c
->n_bind_mounts
; i
++) {
667 if (ro
!= c
->bind_mounts
[i
].read_only
)
670 r
= sd_bus_message_append(
672 c
->bind_mounts
[i
].source
,
673 c
->bind_mounts
[i
].destination
,
674 c
->bind_mounts
[i
].ignore_enoent
,
675 c
->bind_mounts
[i
].recursive
? (uint64_t) MS_REC
: (uint64_t) 0);
680 return sd_bus_message_close_container(reply
);
683 static int property_get_temporary_filesystems(
686 const char *interface
,
687 const char *property
,
688 sd_bus_message
*reply
,
690 sd_bus_error
*error
) {
692 ExecContext
*c
= userdata
;
701 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
705 for (i
= 0; i
< c
->n_temporary_filesystems
; i
++) {
706 TemporaryFileSystem
*t
= c
->temporary_filesystems
+ i
;
708 r
= sd_bus_message_append(
716 return sd_bus_message_close_container(reply
);
719 static int property_get_log_extra_fields(
722 const char *interface
,
723 const char *property
,
724 sd_bus_message
*reply
,
726 sd_bus_error
*error
) {
728 ExecContext
*c
= userdata
;
737 r
= sd_bus_message_open_container(reply
, 'a', "ay");
741 for (i
= 0; i
< c
->n_log_extra_fields
; i
++) {
742 r
= sd_bus_message_append_array(reply
, 'y', c
->log_extra_fields
[i
].iov_base
, c
->log_extra_fields
[i
].iov_len
);
747 return sd_bus_message_close_container(reply
);
750 const sd_bus_vtable bus_exec_vtable
[] = {
751 SD_BUS_VTABLE_START(0),
752 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(ExecContext
, environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
753 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
754 SD_BUS_PROPERTY("PassEnvironment", "as", NULL
, offsetof(ExecContext
, pass_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
755 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL
, offsetof(ExecContext
, unset_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
756 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode
, offsetof(ExecContext
, umask
), SD_BUS_VTABLE_PROPERTY_CONST
),
757 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
758 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
759 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
760 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
761 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
762 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
763 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
764 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
765 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
766 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
767 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
768 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
769 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
770 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
771 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
772 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
773 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
774 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
775 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
776 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
777 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
778 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
779 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
780 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
781 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
782 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
783 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
784 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
785 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
786 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
787 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
788 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
789 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
790 SD_BUS_PROPERTY("RootDirectory", "s", NULL
, offsetof(ExecContext
, root_directory
), SD_BUS_VTABLE_PROPERTY_CONST
),
791 SD_BUS_PROPERTY("RootImage", "s", NULL
, offsetof(ExecContext
, root_image
), SD_BUS_VTABLE_PROPERTY_CONST
),
792 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
793 SD_BUS_PROPERTY("CoredumpFilter", "t", property_get_coredump_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
794 SD_BUS_PROPERTY("Nice", "i", property_get_nice
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
795 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
796 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
797 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
798 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
799 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
800 SD_BUS_PROPERTY("CPUAffinityFromNUMA", "b", property_get_cpu_affinity_from_numa
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
801 SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
802 SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
803 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
804 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool
, offsetof(ExecContext
, cpu_sched_reset_on_fork
), SD_BUS_VTABLE_PROPERTY_CONST
),
805 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool
, offsetof(ExecContext
, non_blocking
), SD_BUS_VTABLE_PROPERTY_CONST
),
806 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input
, offsetof(ExecContext
, std_input
), SD_BUS_VTABLE_PROPERTY_CONST
),
807 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
808 SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
809 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
810 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
811 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_error
), SD_BUS_VTABLE_PROPERTY_CONST
),
812 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
813 SD_BUS_PROPERTY("TTYPath", "s", NULL
, offsetof(ExecContext
, tty_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
814 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_reset
), SD_BUS_VTABLE_PROPERTY_CONST
),
815 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vhangup
), SD_BUS_VTABLE_PROPERTY_CONST
),
816 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vt_disallocate
), SD_BUS_VTABLE_PROPERTY_CONST
),
817 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
818 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL
, offsetof(ExecContext
, syslog_identifier
), SD_BUS_VTABLE_PROPERTY_CONST
),
819 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool
, offsetof(ExecContext
, syslog_level_prefix
), SD_BUS_VTABLE_PROPERTY_CONST
),
820 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
821 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
822 SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int
, offsetof(ExecContext
, log_level_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
823 SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec
, offsetof(ExecContext
, log_ratelimit_interval_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
824 SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned
, offsetof(ExecContext
, log_ratelimit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
825 SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
826 SD_BUS_PROPERTY("LogNamespace", "s", NULL
, offsetof(ExecContext
, log_namespace
), SD_BUS_VTABLE_PROPERTY_CONST
),
827 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int
, offsetof(ExecContext
, secure_bits
), SD_BUS_VTABLE_PROPERTY_CONST
),
828 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL
, offsetof(ExecContext
, capability_bounding_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
829 SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL
, offsetof(ExecContext
, capability_ambient_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
830 SD_BUS_PROPERTY("User", "s", NULL
, offsetof(ExecContext
, user
), SD_BUS_VTABLE_PROPERTY_CONST
),
831 SD_BUS_PROPERTY("Group", "s", NULL
, offsetof(ExecContext
, group
), SD_BUS_VTABLE_PROPERTY_CONST
),
832 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool
, offsetof(ExecContext
, dynamic_user
), SD_BUS_VTABLE_PROPERTY_CONST
),
833 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, remove_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
834 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL
, offsetof(ExecContext
, supplementary_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
835 SD_BUS_PROPERTY("PAMName", "s", NULL
, offsetof(ExecContext
, pam_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
836 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
837 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
838 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
839 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong
, offsetof(ExecContext
, mount_flags
), SD_BUS_VTABLE_PROPERTY_CONST
),
840 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool
, offsetof(ExecContext
, private_tmp
), SD_BUS_VTABLE_PROPERTY_CONST
),
841 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool
, offsetof(ExecContext
, private_devices
), SD_BUS_VTABLE_PROPERTY_CONST
),
842 SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_clock
), SD_BUS_VTABLE_PROPERTY_CONST
),
843 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_tunables
), SD_BUS_VTABLE_PROPERTY_CONST
),
844 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_modules
), SD_BUS_VTABLE_PROPERTY_CONST
),
845 SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_logs
), SD_BUS_VTABLE_PROPERTY_CONST
),
846 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_control_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
847 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool
, offsetof(ExecContext
, private_network
), SD_BUS_VTABLE_PROPERTY_CONST
),
848 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool
, offsetof(ExecContext
, private_users
), SD_BUS_VTABLE_PROPERTY_CONST
),
849 SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_bool
, offsetof(ExecContext
, private_mounts
), SD_BUS_VTABLE_PROPERTY_CONST
),
850 SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home
, offsetof(ExecContext
, protect_home
), SD_BUS_VTABLE_PROPERTY_CONST
),
851 SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system
, offsetof(ExecContext
, protect_system
), SD_BUS_VTABLE_PROPERTY_CONST
),
852 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool
, offsetof(ExecContext
, same_pgrp
), SD_BUS_VTABLE_PROPERTY_CONST
),
853 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL
, offsetof(ExecContext
, utmp_id
), SD_BUS_VTABLE_PROPERTY_CONST
),
854 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode
, offsetof(ExecContext
, utmp_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
855 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
856 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
857 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
858 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool
, offsetof(ExecContext
, ignore_sigpipe
), SD_BUS_VTABLE_PROPERTY_CONST
),
859 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool
, offsetof(ExecContext
, no_new_privileges
), SD_BUS_VTABLE_PROPERTY_CONST
),
860 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
861 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
862 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int
, offsetof(ExecContext
, syscall_errno
), SD_BUS_VTABLE_PROPERTY_CONST
),
863 SD_BUS_PROPERTY("Personality", "s", property_get_personality
, offsetof(ExecContext
, personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
864 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool
, offsetof(ExecContext
, lock_personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
865 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
866 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode
, offsetof(ExecContext
, runtime_directory_preserve_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
867 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
868 SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
869 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
870 SD_BUS_PROPERTY("StateDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
871 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
872 SD_BUS_PROPERTY("CacheDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
873 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
874 SD_BUS_PROPERTY("LogsDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
875 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
876 SD_BUS_PROPERTY("ConfigurationDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
877 SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec
, offsetof(ExecContext
, timeout_clean_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
878 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool
, offsetof(ExecContext
, memory_deny_write_execute
), SD_BUS_VTABLE_PROPERTY_CONST
),
879 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_realtime
), SD_BUS_VTABLE_PROPERTY_CONST
),
880 SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_suid_sgid
), SD_BUS_VTABLE_PROPERTY_CONST
),
881 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong
, offsetof(ExecContext
, restrict_namespaces
), SD_BUS_VTABLE_PROPERTY_CONST
),
882 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
883 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
884 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
885 SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool
, offsetof(ExecContext
, mount_apivfs
), SD_BUS_VTABLE_PROPERTY_CONST
),
886 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode
, offsetof(ExecContext
, keyring_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
887 SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_hostname
), SD_BUS_VTABLE_PROPERTY_CONST
),
888 SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL
, offsetof(ExecContext
, network_namespace_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
890 /* Obsolete/redundant properties: */
891 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
892 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
893 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
894 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
895 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
900 static int append_exec_command(sd_bus_message
*reply
, ExecCommand
*c
) {
909 r
= sd_bus_message_open_container(reply
, 'r', "sasbttttuii");
913 r
= sd_bus_message_append(reply
, "s", c
->path
);
917 r
= sd_bus_message_append_strv(reply
, c
->argv
);
921 r
= sd_bus_message_append(reply
, "bttttuii",
922 !!(c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
),
923 c
->exec_status
.start_timestamp
.realtime
,
924 c
->exec_status
.start_timestamp
.monotonic
,
925 c
->exec_status
.exit_timestamp
.realtime
,
926 c
->exec_status
.exit_timestamp
.monotonic
,
927 (uint32_t) c
->exec_status
.pid
,
928 (int32_t) c
->exec_status
.code
,
929 (int32_t) c
->exec_status
.status
);
933 return sd_bus_message_close_container(reply
);
936 static int append_exec_ex_command(sd_bus_message
*reply
, ExecCommand
*c
) {
937 _cleanup_strv_free_
char **ex_opts
= NULL
;
946 r
= sd_bus_message_open_container(reply
, 'r', "sasasttttuii");
950 r
= sd_bus_message_append(reply
, "s", c
->path
);
954 r
= sd_bus_message_append_strv(reply
, c
->argv
);
958 r
= exec_command_flags_to_strv(c
->flags
, &ex_opts
);
962 r
= sd_bus_message_append_strv(reply
, ex_opts
);
966 r
= sd_bus_message_append(reply
, "ttttuii",
967 c
->exec_status
.start_timestamp
.realtime
,
968 c
->exec_status
.start_timestamp
.monotonic
,
969 c
->exec_status
.exit_timestamp
.realtime
,
970 c
->exec_status
.exit_timestamp
.monotonic
,
971 (uint32_t) c
->exec_status
.pid
,
972 (int32_t) c
->exec_status
.code
,
973 (int32_t) c
->exec_status
.status
);
977 return sd_bus_message_close_container(reply
);
980 int bus_property_get_exec_command(
983 const char *interface
,
984 const char *property
,
985 sd_bus_message
*reply
,
987 sd_bus_error
*ret_error
) {
989 ExecCommand
*c
= (ExecCommand
*) userdata
;
995 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
999 r
= append_exec_command(reply
, c
);
1003 return sd_bus_message_close_container(reply
);
1006 int bus_property_get_exec_command_list(
1009 const char *interface
,
1010 const char *property
,
1011 sd_bus_message
*reply
,
1013 sd_bus_error
*ret_error
) {
1015 ExecCommand
*c
= *(ExecCommand
**) userdata
;
1021 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
1025 LIST_FOREACH(command
, c
, c
) {
1026 r
= append_exec_command(reply
, c
);
1031 return sd_bus_message_close_container(reply
);
1034 int bus_property_get_exec_ex_command_list(
1037 const char *interface
,
1038 const char *property
,
1039 sd_bus_message
*reply
,
1041 sd_bus_error
*ret_error
) {
1043 ExecCommand
*c
, *exec_command
= *(ExecCommand
**) userdata
;
1049 r
= sd_bus_message_open_container(reply
, 'a', "(sasasttttuii)");
1053 LIST_FOREACH(command
, c
, exec_command
) {
1054 r
= append_exec_ex_command(reply
, c
);
1059 return sd_bus_message_close_container(reply
);
1062 static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags
) {
1063 return strjoin(FLAGS_SET(flags
, EXEC_COMMAND_IGNORE_FAILURE
) ? "-" : "",
1064 FLAGS_SET(flags
, EXEC_COMMAND_NO_ENV_EXPAND
) ? ":" : "",
1065 FLAGS_SET(flags
, EXEC_COMMAND_FULLY_PRIVILEGED
) ? "+" : "",
1066 FLAGS_SET(flags
, EXEC_COMMAND_NO_SETUID
) ? "!" : "",
1067 FLAGS_SET(flags
, EXEC_COMMAND_AMBIENT_MAGIC
) ? "!!" : "");
1070 int bus_set_transient_exec_command(
1073 ExecCommand
**exec_command
,
1074 sd_bus_message
*message
,
1075 UnitWriteFlags flags
,
1076 sd_bus_error
*error
) {
1077 bool is_ex_prop
= endswith(name
, "Ex");
1081 r
= sd_bus_message_enter_container(message
, 'a', is_ex_prop
? "(sasas)" : "(sasb)");
1085 while ((r
= sd_bus_message_enter_container(message
, 'r', is_ex_prop
? "sasas" : "sasb")) > 0) {
1086 _cleanup_strv_free_
char **argv
= NULL
, **ex_opts
= NULL
;
1090 r
= sd_bus_message_read(message
, "s", &path
);
1094 if (!path_is_absolute(path
))
1095 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
1097 r
= sd_bus_message_read_strv(message
, &argv
);
1101 r
= is_ex_prop
? sd_bus_message_read_strv(message
, &ex_opts
) : sd_bus_message_read(message
, "b", &b
);
1105 r
= sd_bus_message_exit_container(message
);
1109 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1112 c
= new0(ExecCommand
, 1);
1116 c
->path
= strdup(path
);
1122 c
->argv
= TAKE_PTR(argv
);
1125 r
= exec_command_flags_from_strv(ex_opts
, &c
->flags
);
1129 c
->flags
= b
? EXEC_COMMAND_IGNORE_FAILURE
: 0;
1131 path_simplify(c
->path
, false);
1132 exec_command_append_list(exec_command
, c
);
1140 r
= sd_bus_message_exit_container(message
);
1144 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1145 _cleanup_free_
char *buf
= NULL
;
1146 _cleanup_fclose_
FILE *f
= NULL
;
1151 *exec_command
= exec_command_free_list(*exec_command
);
1153 f
= open_memstream_unlocked(&buf
, &size
);
1157 fprintf(f
, "%s=\n", name
);
1159 LIST_FOREACH(command
, c
, *exec_command
) {
1160 _cleanup_free_
char *a
= NULL
, *exec_chars
= NULL
;
1162 exec_chars
= exec_command_flags_to_exec_chars(c
->flags
);
1166 a
= unit_concat_strv(c
->argv
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
);
1170 if (streq_ptr(c
->path
, c
->argv
? c
->argv
[0] : NULL
))
1171 fprintf(f
, "%s=%s%s\n", name
, exec_chars
, a
);
1173 _cleanup_free_
char *t
= NULL
;
1176 p
= unit_escape_setting(c
->path
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
, &t
);
1180 fprintf(f
, "%s=%s@%s %s\n", name
, exec_chars
, p
, a
);
1184 r
= fflush_and_check(f
);
1188 unit_write_setting(u
, flags
, name
, buf
);
1194 static int parse_personality(const char *s
, unsigned long *p
) {
1199 v
= personality_from_string(s
);
1200 if (v
== PERSONALITY_INVALID
)
1207 static const char* mount_propagation_flags_to_string_with_check(unsigned long n
) {
1208 if (!IN_SET(n
, 0, MS_SHARED
, MS_PRIVATE
, MS_SLAVE
))
1211 return mount_propagation_flags_to_string(n
);
1214 static BUS_DEFINE_SET_TRANSIENT(nsec
, "t", uint64_t, nsec_t
, NSEC_FMT
);
1215 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level
, "i", int32_t, int, "%" PRIi32
, log_level_is_valid
);
1217 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno
, "i", int32_t, int, "%" PRIi32
, errno_is_valid
);
1219 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input
, ExecInput
, exec_input_from_string
);
1220 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output
, ExecOutput
, exec_output_from_string
);
1221 static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode
, ExecUtmpMode
, exec_utmp_mode_from_string
);
1222 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system
, ProtectSystem
, protect_system_from_string
);
1223 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home
, ProtectHome
, protect_home_from_string
);
1224 static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode
, ExecKeyringMode
, exec_keyring_mode_from_string
);
1225 static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode
, ExecPreserveMode
, exec_preserve_mode_from_string
);
1226 static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality
, unsigned long, parse_personality
);
1227 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits
, "i", int32_t, int, "%" PRIi32
, secure_bits_to_string_alloc_with_check
);
1228 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability
, "t", uint64_t, uint64_t, "%" PRIu64
, capability_set_to_string_alloc
);
1229 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag
, "t", uint64_t, unsigned long, "%" PRIu64
, namespace_flags_to_string
);
1230 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags
, "t", uint64_t, unsigned long, "%" PRIu64
, mount_propagation_flags_to_string_with_check
);
1232 int bus_exec_context_set_transient_property(
1236 sd_bus_message
*message
,
1237 UnitWriteFlags flags
,
1238 sd_bus_error
*error
) {
1248 flags
|= UNIT_PRIVATE
;
1250 if (streq(name
, "User"))
1251 return bus_set_transient_user_compat(u
, name
, &c
->user
, message
, flags
, error
);
1253 if (streq(name
, "Group"))
1254 return bus_set_transient_user_compat(u
, name
, &c
->group
, message
, flags
, error
);
1256 if (streq(name
, "TTYPath"))
1257 return bus_set_transient_path(u
, name
, &c
->tty_path
, message
, flags
, error
);
1259 if (streq(name
, "RootImage"))
1260 return bus_set_transient_path(u
, name
, &c
->root_image
, message
, flags
, error
);
1262 if (streq(name
, "RootDirectory"))
1263 return bus_set_transient_path(u
, name
, &c
->root_directory
, message
, flags
, error
);
1265 if (streq(name
, "SyslogIdentifier"))
1266 return bus_set_transient_string(u
, name
, &c
->syslog_identifier
, message
, flags
, error
);
1268 if (streq(name
, "LogLevelMax"))
1269 return bus_set_transient_log_level(u
, name
, &c
->log_level_max
, message
, flags
, error
);
1271 if (streq(name
, "LogRateLimitIntervalUSec"))
1272 return bus_set_transient_usec(u
, name
, &c
->log_ratelimit_interval_usec
, message
, flags
, error
);
1274 if (streq(name
, "LogRateLimitBurst"))
1275 return bus_set_transient_unsigned(u
, name
, &c
->log_ratelimit_burst
, message
, flags
, error
);
1277 if (streq(name
, "Personality"))
1278 return bus_set_transient_personality(u
, name
, &c
->personality
, message
, flags
, error
);
1280 if (streq(name
, "StandardInput"))
1281 return bus_set_transient_std_input(u
, name
, &c
->std_input
, message
, flags
, error
);
1283 if (streq(name
, "StandardOutput"))
1284 return bus_set_transient_std_output(u
, name
, &c
->std_output
, message
, flags
, error
);
1286 if (streq(name
, "StandardError"))
1287 return bus_set_transient_std_output(u
, name
, &c
->std_error
, message
, flags
, error
);
1289 if (streq(name
, "IgnoreSIGPIPE"))
1290 return bus_set_transient_bool(u
, name
, &c
->ignore_sigpipe
, message
, flags
, error
);
1292 if (streq(name
, "TTYVHangup"))
1293 return bus_set_transient_bool(u
, name
, &c
->tty_vhangup
, message
, flags
, error
);
1295 if (streq(name
, "TTYReset"))
1296 return bus_set_transient_bool(u
, name
, &c
->tty_reset
, message
, flags
, error
);
1298 if (streq(name
, "TTYVTDisallocate"))
1299 return bus_set_transient_bool(u
, name
, &c
->tty_vt_disallocate
, message
, flags
, error
);
1301 if (streq(name
, "PrivateTmp"))
1302 return bus_set_transient_bool(u
, name
, &c
->private_tmp
, message
, flags
, error
);
1304 if (streq(name
, "PrivateDevices"))
1305 return bus_set_transient_bool(u
, name
, &c
->private_devices
, message
, flags
, error
);
1307 if (streq(name
, "PrivateMounts"))
1308 return bus_set_transient_bool(u
, name
, &c
->private_mounts
, message
, flags
, error
);
1310 if (streq(name
, "PrivateNetwork"))
1311 return bus_set_transient_bool(u
, name
, &c
->private_network
, message
, flags
, error
);
1313 if (streq(name
, "PrivateUsers"))
1314 return bus_set_transient_bool(u
, name
, &c
->private_users
, message
, flags
, error
);
1316 if (streq(name
, "NoNewPrivileges"))
1317 return bus_set_transient_bool(u
, name
, &c
->no_new_privileges
, message
, flags
, error
);
1319 if (streq(name
, "SyslogLevelPrefix"))
1320 return bus_set_transient_bool(u
, name
, &c
->syslog_level_prefix
, message
, flags
, error
);
1322 if (streq(name
, "MemoryDenyWriteExecute"))
1323 return bus_set_transient_bool(u
, name
, &c
->memory_deny_write_execute
, message
, flags
, error
);
1325 if (streq(name
, "RestrictRealtime"))
1326 return bus_set_transient_bool(u
, name
, &c
->restrict_realtime
, message
, flags
, error
);
1328 if (streq(name
, "RestrictSUIDSGID"))
1329 return bus_set_transient_bool(u
, name
, &c
->restrict_suid_sgid
, message
, flags
, error
);
1331 if (streq(name
, "DynamicUser"))
1332 return bus_set_transient_bool(u
, name
, &c
->dynamic_user
, message
, flags
, error
);
1334 if (streq(name
, "RemoveIPC"))
1335 return bus_set_transient_bool(u
, name
, &c
->remove_ipc
, message
, flags
, error
);
1337 if (streq(name
, "ProtectKernelTunables"))
1338 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_tunables
, message
, flags
, error
);
1340 if (streq(name
, "ProtectKernelModules"))
1341 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_modules
, message
, flags
, error
);
1343 if (streq(name
, "ProtectKernelLogs"))
1344 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_logs
, message
, flags
, error
);
1346 if (streq(name
, "ProtectClock"))
1347 return bus_set_transient_bool(u
, name
, &c
->protect_clock
, message
, flags
, error
);
1349 if (streq(name
, "ProtectControlGroups"))
1350 return bus_set_transient_bool(u
, name
, &c
->protect_control_groups
, message
, flags
, error
);
1352 if (streq(name
, "MountAPIVFS"))
1353 return bus_set_transient_bool(u
, name
, &c
->mount_apivfs
, message
, flags
, error
);
1355 if (streq(name
, "CPUSchedulingResetOnFork"))
1356 return bus_set_transient_bool(u
, name
, &c
->cpu_sched_reset_on_fork
, message
, flags
, error
);
1358 if (streq(name
, "NonBlocking"))
1359 return bus_set_transient_bool(u
, name
, &c
->non_blocking
, message
, flags
, error
);
1361 if (streq(name
, "LockPersonality"))
1362 return bus_set_transient_bool(u
, name
, &c
->lock_personality
, message
, flags
, error
);
1364 if (streq(name
, "ProtectHostname"))
1365 return bus_set_transient_bool(u
, name
, &c
->protect_hostname
, message
, flags
, error
);
1367 if (streq(name
, "UtmpIdentifier"))
1368 return bus_set_transient_string(u
, name
, &c
->utmp_id
, message
, flags
, error
);
1370 if (streq(name
, "UtmpMode"))
1371 return bus_set_transient_utmp_mode(u
, name
, &c
->utmp_mode
, message
, flags
, error
);
1373 if (streq(name
, "PAMName"))
1374 return bus_set_transient_string(u
, name
, &c
->pam_name
, message
, flags
, error
);
1376 if (streq(name
, "TimerSlackNSec"))
1377 return bus_set_transient_nsec(u
, name
, &c
->timer_slack_nsec
, message
, flags
, error
);
1379 if (streq(name
, "ProtectSystem"))
1380 return bus_set_transient_protect_system(u
, name
, &c
->protect_system
, message
, flags
, error
);
1382 if (streq(name
, "ProtectHome"))
1383 return bus_set_transient_protect_home(u
, name
, &c
->protect_home
, message
, flags
, error
);
1385 if (streq(name
, "KeyringMode"))
1386 return bus_set_transient_keyring_mode(u
, name
, &c
->keyring_mode
, message
, flags
, error
);
1388 if (streq(name
, "RuntimeDirectoryPreserve"))
1389 return bus_set_transient_preserve_mode(u
, name
, &c
->runtime_directory_preserve_mode
, message
, flags
, error
);
1391 if (streq(name
, "UMask"))
1392 return bus_set_transient_mode_t(u
, name
, &c
->umask
, message
, flags
, error
);
1394 if (streq(name
, "RuntimeDirectoryMode"))
1395 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_RUNTIME
].mode
, message
, flags
, error
);
1397 if (streq(name
, "StateDirectoryMode"))
1398 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_STATE
].mode
, message
, flags
, error
);
1400 if (streq(name
, "CacheDirectoryMode"))
1401 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CACHE
].mode
, message
, flags
, error
);
1403 if (streq(name
, "LogsDirectoryMode"))
1404 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_LOGS
].mode
, message
, flags
, error
);
1406 if (streq(name
, "ConfigurationDirectoryMode"))
1407 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
, message
, flags
, error
);
1409 if (streq(name
, "SELinuxContext"))
1410 return bus_set_transient_string(u
, name
, &c
->selinux_context
, message
, flags
, error
);
1412 if (streq(name
, "SecureBits"))
1413 return bus_set_transient_secure_bits(u
, name
, &c
->secure_bits
, message
, flags
, error
);
1415 if (streq(name
, "CapabilityBoundingSet"))
1416 return bus_set_transient_capability(u
, name
, &c
->capability_bounding_set
, message
, flags
, error
);
1418 if (streq(name
, "AmbientCapabilities"))
1419 return bus_set_transient_capability(u
, name
, &c
->capability_ambient_set
, message
, flags
, error
);
1421 if (streq(name
, "RestrictNamespaces"))
1422 return bus_set_transient_namespace_flag(u
, name
, &c
->restrict_namespaces
, message
, flags
, error
);
1424 if (streq(name
, "MountFlags"))
1425 return bus_set_transient_mount_flags(u
, name
, &c
->mount_flags
, message
, flags
, error
);
1427 if (streq(name
, "NetworkNamespacePath"))
1428 return bus_set_transient_path(u
, name
, &c
->network_namespace_path
, message
, flags
, error
);
1430 if (streq(name
, "SupplementaryGroups")) {
1431 _cleanup_strv_free_
char **l
= NULL
;
1434 r
= sd_bus_message_read_strv(message
, &l
);
1439 if (!isempty(*p
) && !valid_user_group_name_or_id_compat(*p
))
1440 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
1441 "Invalid supplementary group names");
1443 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1444 if (strv_isempty(l
)) {
1445 c
->supplementary_groups
= strv_free(c
->supplementary_groups
);
1446 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1448 _cleanup_free_
char *joined
= NULL
;
1450 r
= strv_extend_strv(&c
->supplementary_groups
, l
, true);
1454 joined
= strv_join(c
->supplementary_groups
, " ");
1458 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s", name
, joined
);
1464 } else if (streq(name
, "SyslogLevel")) {
1467 r
= sd_bus_message_read(message
, "i", &level
);
1471 if (!log_level_is_valid(level
))
1472 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log level value out of range");
1474 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1475 c
->syslog_priority
= (c
->syslog_priority
& LOG_FACMASK
) | level
;
1476 unit_write_settingf(u
, flags
, name
, "SyslogLevel=%i", level
);
1481 } else if (streq(name
, "SyslogFacility")) {
1484 r
= sd_bus_message_read(message
, "i", &facility
);
1488 if (!log_facility_unshifted_is_valid(facility
))
1489 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log facility value out of range");
1491 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1492 c
->syslog_priority
= (facility
<< 3) | LOG_PRI(c
->syslog_priority
);
1493 unit_write_settingf(u
, flags
, name
, "SyslogFacility=%i", facility
);
1498 } else if (streq(name
, "LogNamespace")) {
1501 r
= sd_bus_message_read(message
, "s", &n
);
1505 if (!isempty(n
) && !log_namespace_name_valid(n
))
1506 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log namespace name not valid");
1508 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1511 c
->log_namespace
= mfree(c
->log_namespace
);
1512 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1514 r
= free_and_strdup(&c
->log_namespace
, n
);
1518 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, n
);
1524 } else if (streq(name
, "LogExtraFields")) {
1527 r
= sd_bus_message_enter_container(message
, 'a', "ay");
1532 _cleanup_free_
void *copy
= NULL
;
1538 /* Note that we expect a byte array for each field, instead of a string. That's because on the
1539 * lower-level journal fields can actually contain binary data and are not restricted to text,
1540 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
1541 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
1542 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
1543 * limitation, should a good, valid usecase arise. */
1545 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
1551 if (memchr(p
, 0, sz
))
1552 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains zero byte");
1554 eq
= memchr(p
, '=', sz
);
1556 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains no '=' character");
1557 if (!journal_field_valid(p
, eq
- (const char*) p
, false))
1558 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field invalid");
1560 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1561 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
1564 c
->log_extra_fields
= t
;
1567 copy
= malloc(sz
+ 1);
1571 memcpy(copy
, p
, sz
);
1572 ((uint8_t*) copy
)[sz
] = 0;
1574 if (!utf8_is_valid(copy
))
1575 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field is not valid UTF-8");
1577 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1578 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE(copy
, sz
);
1579 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
, name
, "LogExtraFields=%s", (char*) copy
);
1587 r
= sd_bus_message_exit_container(message
);
1591 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && n
== 0) {
1592 exec_context_free_log_extra_fields(c
);
1593 unit_write_setting(u
, flags
, name
, "LogExtraFields=");
1601 if (streq(name
, "SystemCallErrorNumber"))
1602 return bus_set_transient_errno(u
, name
, &c
->syscall_errno
, message
, flags
, error
);
1604 if (streq(name
, "SystemCallFilter")) {
1606 _cleanup_strv_free_
char **l
= NULL
;
1608 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1612 r
= sd_bus_message_read(message
, "b", &whitelist
);
1616 r
= sd_bus_message_read_strv(message
, &l
);
1620 r
= sd_bus_message_exit_container(message
);
1624 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1625 _cleanup_free_
char *joined
= NULL
;
1626 SeccompParseFlags invert_flag
= whitelist
? 0 : SECCOMP_PARSE_INVERT
;
1629 if (strv_isempty(l
)) {
1630 c
->syscall_whitelist
= false;
1631 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
1633 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=");
1637 if (!c
->syscall_filter
) {
1638 c
->syscall_filter
= hashmap_new(NULL
);
1639 if (!c
->syscall_filter
)
1642 c
->syscall_whitelist
= whitelist
;
1644 if (c
->syscall_whitelist
) {
1645 r
= seccomp_parse_syscall_filter("@default",
1648 SECCOMP_PARSE_PERMISSIVE
|
1649 SECCOMP_PARSE_WHITELIST
| invert_flag
,
1657 STRV_FOREACH(s
, l
) {
1658 _cleanup_free_
char *n
= NULL
;
1661 r
= parse_syscall_and_errno(*s
, &n
, &e
);
1665 r
= seccomp_parse_syscall_filter(n
,
1668 SECCOMP_PARSE_LOG
| SECCOMP_PARSE_PERMISSIVE
|
1670 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
1677 joined
= strv_join(l
, " ");
1681 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=%s%s", whitelist
? "" : "~", joined
);
1686 } else if (streq(name
, "SystemCallArchitectures")) {
1687 _cleanup_strv_free_
char **l
= NULL
;
1689 r
= sd_bus_message_read_strv(message
, &l
);
1693 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1694 _cleanup_free_
char *joined
= NULL
;
1696 if (strv_isempty(l
))
1697 c
->syscall_archs
= set_free(c
->syscall_archs
);
1701 r
= set_ensure_allocated(&c
->syscall_archs
, NULL
);
1705 STRV_FOREACH(s
, l
) {
1708 r
= seccomp_arch_from_string(*s
, &a
);
1712 r
= set_put(c
->syscall_archs
, UINT32_TO_PTR(a
+ 1));
1719 joined
= strv_join(l
, " ");
1723 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
1728 } else if (streq(name
, "RestrictAddressFamilies")) {
1730 _cleanup_strv_free_
char **l
= NULL
;
1732 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1736 r
= sd_bus_message_read(message
, "b", &whitelist
);
1740 r
= sd_bus_message_read_strv(message
, &l
);
1744 r
= sd_bus_message_exit_container(message
);
1748 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1749 _cleanup_free_
char *joined
= NULL
;
1752 if (strv_isempty(l
)) {
1753 c
->address_families_whitelist
= false;
1754 c
->address_families
= set_free(c
->address_families
);
1756 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=");
1760 if (!c
->address_families
) {
1761 c
->address_families
= set_new(NULL
);
1762 if (!c
->address_families
)
1765 c
->address_families_whitelist
= whitelist
;
1768 STRV_FOREACH(s
, l
) {
1771 af
= af_from_name(*s
);
1775 if (whitelist
== c
->address_families_whitelist
) {
1776 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
1780 (void) set_remove(c
->address_families
, INT_TO_PTR(af
));
1783 joined
= strv_join(l
, " ");
1787 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=%s%s", whitelist
? "" : "~", joined
);
1793 if (STR_IN_SET(name
, "CPUAffinity", "NUMAMask")) {
1796 bool affinity
= streq(name
, "CPUAffinity");
1797 _cleanup_(cpu_set_reset
) CPUSet set
= {};
1799 r
= sd_bus_message_read_array(message
, 'y', &a
, &n
);
1803 r
= cpu_set_from_dbus(a
, n
, &set
);
1807 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1809 cpu_set_reset(affinity
? &c
->cpu_set
: &c
->numa_policy
.nodes
);
1810 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1812 _cleanup_free_
char *str
= NULL
;
1814 str
= cpu_set_to_string(&set
);
1818 /* We forego any optimizations here, and always create the structure using
1819 * cpu_set_add_all(), because we don't want to care if the existing size we
1820 * got over dbus is appropriate. */
1821 r
= cpu_set_add_all(affinity
? &c
->cpu_set
: &c
->numa_policy
.nodes
, &set
);
1825 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, str
);
1831 } else if (streq(name
, "CPUAffinityFromNUMA")) {
1834 r
= sd_bus_message_read_basic(message
, 'b', &q
);
1838 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1839 c
->cpu_affinity_from_numa
= q
;
1840 unit_write_settingf(u
, flags
, name
, "%s=%s", "CPUAffinity", "numa");
1845 } else if (streq(name
, "NUMAPolicy")) {
1848 r
= sd_bus_message_read(message
, "i", &type
);
1852 if (!mpol_is_valid(type
))
1853 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid NUMAPolicy value: %i", type
);
1855 if (!UNIT_WRITE_FLAGS_NOOP(flags
))
1856 c
->numa_policy
.type
= type
;
1860 } else if (streq(name
, "Nice")) {
1863 r
= sd_bus_message_read(message
, "i", &q
);
1867 if (!nice_is_valid(q
))
1868 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid Nice value: %i", q
);
1870 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1874 unit_write_settingf(u
, flags
, name
, "Nice=%i", q
);
1879 } else if (streq(name
, "CPUSchedulingPolicy")) {
1882 r
= sd_bus_message_read(message
, "i", &q
);
1886 if (!sched_policy_is_valid(q
))
1887 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling policy: %i", q
);
1889 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1890 _cleanup_free_
char *s
= NULL
;
1892 r
= sched_policy_to_string_alloc(q
, &s
);
1896 c
->cpu_sched_policy
= q
;
1897 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(q
), sched_get_priority_max(q
));
1898 c
->cpu_sched_set
= true;
1900 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPolicy=%s", s
);
1905 } else if (streq(name
, "CPUSchedulingPriority")) {
1906 int32_t p
, min
, max
;
1908 r
= sd_bus_message_read(message
, "i", &p
);
1912 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1913 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1914 if (p
< min
|| p
> max
)
1915 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling priority: %i", p
);
1917 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1918 c
->cpu_sched_priority
= p
;
1919 c
->cpu_sched_set
= true;
1921 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPriority=%i", p
);
1926 } else if (streq(name
, "IOSchedulingClass")) {
1929 r
= sd_bus_message_read(message
, "i", &q
);
1933 if (!ioprio_class_is_valid(q
))
1934 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling class: %i", q
);
1936 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1937 _cleanup_free_
char *s
= NULL
;
1939 r
= ioprio_class_to_string_alloc(q
, &s
);
1943 c
->ioprio
= IOPRIO_PRIO_VALUE(q
, IOPRIO_PRIO_DATA(c
->ioprio
));
1944 c
->ioprio_set
= true;
1946 unit_write_settingf(u
, flags
, name
, "IOSchedulingClass=%s", s
);
1951 } else if (streq(name
, "IOSchedulingPriority")) {
1954 r
= sd_bus_message_read(message
, "i", &p
);
1958 if (!ioprio_priority_is_valid(p
))
1959 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling priority: %i", p
);
1961 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1962 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), p
);
1963 c
->ioprio_set
= true;
1965 unit_write_settingf(u
, flags
, name
, "IOSchedulingPriority=%i", p
);
1970 } else if (streq(name
, "WorkingDirectory")) {
1974 r
= sd_bus_message_read(message
, "s", &s
);
1984 if (!isempty(s
) && !streq(s
, "~") && !path_is_absolute(s
))
1985 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "WorkingDirectory= expects an absolute path or '~'");
1987 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1988 if (streq(s
, "~")) {
1989 c
->working_directory
= mfree(c
->working_directory
);
1990 c
->working_directory_home
= true;
1992 r
= free_and_strdup(&c
->working_directory
, empty_to_null(s
));
1996 c
->working_directory_home
= false;
1999 c
->working_directory_missing_ok
= missing_ok
;
2000 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "WorkingDirectory=%s%s", missing_ok
? "-" : "", s
);
2005 } else if (STR_IN_SET(name
,
2006 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
2009 r
= sd_bus_message_read(message
, "s", &s
);
2013 if (!isempty(s
) && !fdname_is_valid(s
))
2014 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid file descriptor name");
2016 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2018 if (streq(name
, "StandardInputFileDescriptorName")) {
2019 r
= free_and_strdup(c
->stdio_fdname
+ STDIN_FILENO
, empty_to_null(s
));
2023 c
->std_input
= EXEC_INPUT_NAMED_FD
;
2024 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=fd:%s", exec_context_fdname(c
, STDIN_FILENO
));
2026 } else if (streq(name
, "StandardOutputFileDescriptorName")) {
2027 r
= free_and_strdup(c
->stdio_fdname
+ STDOUT_FILENO
, empty_to_null(s
));
2031 c
->std_output
= EXEC_OUTPUT_NAMED_FD
;
2032 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=fd:%s", exec_context_fdname(c
, STDOUT_FILENO
));
2035 assert(streq(name
, "StandardErrorFileDescriptorName"));
2037 r
= free_and_strdup(&c
->stdio_fdname
[STDERR_FILENO
], empty_to_null(s
));
2041 c
->std_error
= EXEC_OUTPUT_NAMED_FD
;
2042 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=fd:%s", exec_context_fdname(c
, STDERR_FILENO
));
2048 } else if (STR_IN_SET(name
,
2049 "StandardInputFile",
2050 "StandardOutputFile", "StandardOutputFileToAppend",
2051 "StandardErrorFile", "StandardErrorFileToAppend")) {
2054 r
= sd_bus_message_read(message
, "s", &s
);
2059 if (!path_is_absolute(s
))
2060 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute", s
);
2061 if (!path_is_normalized(s
))
2062 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not normalized", s
);
2065 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2067 if (streq(name
, "StandardInputFile")) {
2068 r
= free_and_strdup(&c
->stdio_file
[STDIN_FILENO
], empty_to_null(s
));
2072 c
->std_input
= EXEC_INPUT_FILE
;
2073 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=file:%s", s
);
2075 } else if (STR_IN_SET(name
, "StandardOutputFile", "StandardOutputFileToAppend")) {
2076 r
= free_and_strdup(&c
->stdio_file
[STDOUT_FILENO
], empty_to_null(s
));
2080 if (streq(name
, "StandardOutputFile")) {
2081 c
->std_output
= EXEC_OUTPUT_FILE
;
2082 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=file:%s", s
);
2084 assert(streq(name
, "StandardOutputFileToAppend"));
2085 c
->std_output
= EXEC_OUTPUT_FILE_APPEND
;
2086 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=append:%s", s
);
2089 assert(STR_IN_SET(name
, "StandardErrorFile", "StandardErrorFileToAppend"));
2091 r
= free_and_strdup(&c
->stdio_file
[STDERR_FILENO
], empty_to_null(s
));
2095 if (streq(name
, "StandardErrorFile")) {
2096 c
->std_error
= EXEC_OUTPUT_FILE
;
2097 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=file:%s", s
);
2099 assert(streq(name
, "StandardErrorFileToAppend"));
2100 c
->std_error
= EXEC_OUTPUT_FILE_APPEND
;
2101 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=append:%s", s
);
2108 } else if (streq(name
, "StandardInputData")) {
2112 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
2116 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2117 _cleanup_free_
char *encoded
= NULL
;
2120 c
->stdin_data
= mfree(c
->stdin_data
);
2121 c
->stdin_data_size
= 0;
2123 unit_write_settingf(u
, flags
, name
, "StandardInputData=");
2128 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
2129 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
)
2132 n
= base64mem(p
, sz
, &encoded
);
2136 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
2140 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
2143 c
->stdin_data_size
+= sz
;
2145 unit_write_settingf(u
, flags
, name
, "StandardInputData=%s", encoded
);
2151 } else if (streq(name
, "Environment")) {
2153 _cleanup_strv_free_
char **l
= NULL
;
2155 r
= sd_bus_message_read_strv(message
, &l
);
2159 if (!strv_env_is_valid(l
))
2160 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment block.");
2162 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2163 if (strv_isempty(l
)) {
2164 c
->environment
= strv_free(c
->environment
);
2165 unit_write_setting(u
, flags
, name
, "Environment=");
2167 _cleanup_free_
char *joined
= NULL
;
2170 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
2174 e
= strv_env_merge(2, c
->environment
, l
);
2178 strv_free_and_replace(c
->environment
, e
);
2179 unit_write_settingf(u
, flags
, name
, "Environment=%s", joined
);
2185 } else if (streq(name
, "UnsetEnvironment")) {
2187 _cleanup_strv_free_
char **l
= NULL
;
2189 r
= sd_bus_message_read_strv(message
, &l
);
2193 if (!strv_env_name_or_assignment_is_valid(l
))
2194 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid UnsetEnvironment= list.");
2196 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2197 if (strv_isempty(l
)) {
2198 c
->unset_environment
= strv_free(c
->unset_environment
);
2199 unit_write_setting(u
, flags
, name
, "UnsetEnvironment=");
2201 _cleanup_free_
char *joined
= NULL
;
2204 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
2208 e
= strv_env_merge(2, c
->unset_environment
, l
);
2212 strv_free_and_replace(c
->unset_environment
, e
);
2213 unit_write_settingf(u
, flags
, name
, "UnsetEnvironment=%s", joined
);
2219 } else if (streq(name
, "OOMScoreAdjust")) {
2222 r
= sd_bus_message_read(message
, "i", &oa
);
2226 if (!oom_score_adjust_is_valid(oa
))
2227 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "OOM score adjust value out of range");
2229 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2230 c
->oom_score_adjust
= oa
;
2231 c
->oom_score_adjust_set
= true;
2232 unit_write_settingf(u
, flags
, name
, "OOMScoreAdjust=%i", oa
);
2237 } else if (streq(name
, "CoredumpFilter")) {
2240 r
= sd_bus_message_read(message
, "t", &f
);
2244 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2245 c
->coredump_filter
= f
;
2246 c
->coredump_filter_set
= true;
2247 unit_write_settingf(u
, flags
, name
, "CoredumpFilter=0x%"PRIx64
, f
);
2252 } else if (streq(name
, "EnvironmentFiles")) {
2254 _cleanup_free_
char *joined
= NULL
;
2255 _cleanup_fclose_
FILE *f
= NULL
;
2256 _cleanup_strv_free_
char **l
= NULL
;
2260 r
= sd_bus_message_enter_container(message
, 'a', "(sb)");
2264 f
= open_memstream_unlocked(&joined
, &size
);
2268 fputs("EnvironmentFile=\n", f
);
2270 STRV_FOREACH(i
, c
->environment_files
) {
2271 _cleanup_free_
char *q
= NULL
;
2273 q
= specifier_escape(*i
);
2277 fprintf(f
, "EnvironmentFile=%s\n", q
);
2280 while ((r
= sd_bus_message_enter_container(message
, 'r', "sb")) > 0) {
2284 r
= sd_bus_message_read(message
, "sb", &path
, &b
);
2288 r
= sd_bus_message_exit_container(message
);
2292 if (!path_is_absolute(path
))
2293 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
2295 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2296 _cleanup_free_
char *q
= NULL
, *buf
= NULL
;
2298 buf
= strjoin(b
? "-" : "", path
);
2302 q
= specifier_escape(buf
);
2306 fprintf(f
, "EnvironmentFile=%s\n", q
);
2308 r
= strv_consume(&l
, TAKE_PTR(buf
));
2316 r
= sd_bus_message_exit_container(message
);
2320 r
= fflush_and_check(f
);
2324 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2325 if (strv_isempty(l
)) {
2326 c
->environment_files
= strv_free(c
->environment_files
);
2327 unit_write_setting(u
, flags
, name
, "EnvironmentFile=");
2329 r
= strv_extend_strv(&c
->environment_files
, l
, true);
2333 unit_write_setting(u
, flags
, name
, joined
);
2339 } else if (streq(name
, "PassEnvironment")) {
2341 _cleanup_strv_free_
char **l
= NULL
;
2343 r
= sd_bus_message_read_strv(message
, &l
);
2347 if (!strv_env_name_is_valid(l
))
2348 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PassEnvironment= block.");
2350 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2351 if (strv_isempty(l
)) {
2352 c
->pass_environment
= strv_free(c
->pass_environment
);
2353 unit_write_setting(u
, flags
, name
, "PassEnvironment=");
2355 _cleanup_free_
char *joined
= NULL
;
2357 r
= strv_extend_strv(&c
->pass_environment
, l
, true);
2361 /* We write just the new settings out to file, with unresolved specifiers. */
2362 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2366 unit_write_settingf(u
, flags
, name
, "PassEnvironment=%s", joined
);
2372 } else if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
2373 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) {
2374 _cleanup_strv_free_
char **l
= NULL
;
2378 r
= sd_bus_message_read_strv(message
, &l
);
2382 STRV_FOREACH(p
, l
) {
2386 offset
= i
[0] == '-';
2387 offset
+= i
[offset
] == '+';
2388 if (!path_is_absolute(i
+ offset
))
2389 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
2391 path_simplify(i
+ offset
, false);
2394 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2395 if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadWritePaths"))
2396 dirs
= &c
->read_write_paths
;
2397 else if (STR_IN_SET(name
, "ReadOnlyDirectories", "ReadOnlyPaths"))
2398 dirs
= &c
->read_only_paths
;
2399 else /* "InaccessiblePaths" */
2400 dirs
= &c
->inaccessible_paths
;
2402 if (strv_isempty(l
)) {
2403 *dirs
= strv_free(*dirs
);
2404 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2406 _cleanup_free_
char *joined
= NULL
;
2408 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2412 r
= strv_extend_strv(dirs
, l
, true);
2416 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2422 } else if (STR_IN_SET(name
, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
2423 _cleanup_strv_free_
char **l
= NULL
;
2426 r
= sd_bus_message_read_strv(message
, &l
);
2430 STRV_FOREACH(p
, l
) {
2431 if (!path_is_normalized(*p
))
2432 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is not normalized: %s", name
, *p
);
2434 if (path_is_absolute(*p
))
2435 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is absolute: %s", name
, *p
);
2437 if (path_startswith(*p
, "private"))
2438 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path can't be 'private': %s", name
, *p
);
2441 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2442 ExecDirectoryType i
;
2445 assert_se((i
= exec_directory_type_from_string(name
)) >= 0);
2446 d
= c
->directories
+ i
;
2448 if (strv_isempty(l
)) {
2449 d
->paths
= strv_free(d
->paths
);
2450 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2452 _cleanup_free_
char *joined
= NULL
;
2454 r
= strv_extend_strv(&d
->paths
, l
, true);
2458 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2462 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2468 } else if (STR_IN_SET(name
, "AppArmorProfile", "SmackProcessLabel")) {
2472 r
= sd_bus_message_read(message
, "(bs)", &ignore
, &s
);
2476 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2480 if (streq(name
, "AppArmorProfile")) {
2481 p
= &c
->apparmor_profile
;
2482 b
= &c
->apparmor_profile_ignore
;
2483 } else { /* "SmackProcessLabel" */
2484 p
= &c
->smack_process_label
;
2485 b
= &c
->smack_process_label_ignore
;
2492 if (free_and_strdup(p
, s
) < 0)
2497 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s%s", name
, ignore
? "-" : "", strempty(s
));
2502 } else if (STR_IN_SET(name
, "BindPaths", "BindReadOnlyPaths")) {
2503 char *source
, *destination
;
2505 uint64_t mount_flags
;
2508 r
= sd_bus_message_enter_container(message
, 'a', "(ssbt)");
2512 while ((r
= sd_bus_message_read(message
, "(ssbt)", &source
, &destination
, &ignore_enoent
, &mount_flags
)) > 0) {
2514 if (!path_is_absolute(source
))
2515 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
2516 if (!path_is_absolute(destination
))
2517 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
2518 if (!IN_SET(mount_flags
, 0, MS_REC
))
2519 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount flags.");
2521 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2522 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
2525 .destination
= destination
,
2526 .read_only
= !!strstr(name
, "ReadOnly"),
2527 .recursive
= !!(mount_flags
& MS_REC
),
2528 .ignore_enoent
= ignore_enoent
,
2533 unit_write_settingf(
2534 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2537 ignore_enoent
? "-" : "",
2540 (mount_flags
& MS_REC
) ? "rbind" : "norbind");
2548 r
= sd_bus_message_exit_container(message
);
2553 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
2554 c
->bind_mounts
= NULL
;
2555 c
->n_bind_mounts
= 0;
2557 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2562 } else if (streq(name
, "TemporaryFileSystem")) {
2563 const char *path
, *options
;
2566 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
2570 while ((r
= sd_bus_message_read(message
, "(ss)", &path
, &options
)) > 0) {
2572 if (!path_is_absolute(path
))
2573 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Mount point %s is not absolute.", path
);
2575 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2576 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, options
);
2580 unit_write_settingf(
2581 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2593 r
= sd_bus_message_exit_container(message
);
2598 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
2599 c
->temporary_filesystems
= NULL
;
2600 c
->n_temporary_filesystems
= 0;
2602 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2607 } else if ((suffix
= startswith(name
, "Limit"))) {
2608 const char *soft
= NULL
;
2611 ri
= rlimit_from_string(suffix
);
2613 soft
= endswith(suffix
, "Soft");
2617 n
= strndupa(suffix
, soft
- suffix
);
2618 ri
= rlimit_from_string(n
);
2620 name
= strjoina("Limit", n
);
2628 r
= sd_bus_message_read(message
, "t", &rl
);
2632 if (rl
== (uint64_t) -1)
2637 if ((uint64_t) x
!= rl
)
2641 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2642 _cleanup_free_
char *f
= NULL
;
2645 if (c
->rlimit
[ri
]) {
2646 nl
= *c
->rlimit
[ri
];
2653 /* When the resource limit is not initialized yet, then assign the value to both fields */
2654 nl
= (struct rlimit
) {
2659 r
= rlimit_format(&nl
, &f
);
2664 *c
->rlimit
[ri
] = nl
;
2666 c
->rlimit
[ri
] = newdup(struct rlimit
, &nl
, 1);
2671 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, f
);