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"
29 #include "mountpoint-util.h"
30 #include "namespace.h"
31 #include "parse-util.h"
32 #include "path-util.h"
33 #include "process-util.h"
34 #include "rlimit-util.h"
36 #include "seccomp-util.h"
38 #include "securebits-util.h"
39 #include "specifier.h"
41 #include "syslog-util.h"
42 #include "unit-printf.h"
43 #include "user-util.h"
46 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output
, exec_output
, ExecOutput
);
47 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input
, exec_input
, ExecInput
);
48 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
);
49 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
);
50 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
);
51 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home
, protect_home
, ProtectHome
);
52 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system
, protect_system
, ProtectSystem
);
53 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality
, personality
, unsigned long);
54 static BUS_DEFINE_PROPERTY_GET(property_get_ioprio
, "i", ExecContext
, exec_context_get_effective_ioprio
);
55 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class
, "i", ExecContext
, exec_context_get_effective_ioprio
, IOPRIO_PRIO_CLASS
);
56 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority
, "i", ExecContext
, exec_context_get_effective_ioprio
, IOPRIO_PRIO_DATA
);
57 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string
, "s", NULL
);
58 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level
, "i", int, LOG_PRI
);
59 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility
, "i", int, LOG_FAC
);
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
;
109 if (c
->oom_score_adjust_set
)
110 n
= c
->oom_score_adjust
;
112 _cleanup_free_
char *t
= NULL
;
115 if (read_one_line_file("/proc/self/oom_score_adj", &t
) >= 0)
119 return sd_bus_message_append(reply
, "i", n
);
122 static int property_get_nice(
125 const char *interface
,
126 const char *property
,
127 sd_bus_message
*reply
,
129 sd_bus_error
*error
) {
131 ExecContext
*c
= userdata
;
142 n
= getpriority(PRIO_PROCESS
, 0);
147 return sd_bus_message_append(reply
, "i", n
);
150 static int property_get_cpu_sched_policy(
153 const char *interface
,
154 const char *property
,
155 sd_bus_message
*reply
,
157 sd_bus_error
*error
) {
159 ExecContext
*c
= userdata
;
166 if (c
->cpu_sched_set
)
167 n
= c
->cpu_sched_policy
;
169 n
= sched_getscheduler(0);
174 return sd_bus_message_append(reply
, "i", n
);
177 static int property_get_cpu_sched_priority(
180 const char *interface
,
181 const char *property
,
182 sd_bus_message
*reply
,
184 sd_bus_error
*error
) {
186 ExecContext
*c
= userdata
;
193 if (c
->cpu_sched_set
)
194 n
= c
->cpu_sched_priority
;
196 struct sched_param p
= {};
198 if (sched_getparam(0, &p
) >= 0)
199 n
= p
.sched_priority
;
204 return sd_bus_message_append(reply
, "i", n
);
207 static int property_get_cpu_affinity(
210 const char *interface
,
211 const char *property
,
212 sd_bus_message
*reply
,
214 sd_bus_error
*error
) {
216 ExecContext
*c
= userdata
;
217 _cleanup_free_
uint8_t *array
= NULL
;
224 (void) cpu_set_to_dbus(&c
->cpu_set
, &array
, &allocated
);
225 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
228 static int property_get_numa_mask(
231 const char *interface
,
232 const char *property
,
233 sd_bus_message
*reply
,
235 sd_bus_error
*error
) {
237 ExecContext
*c
= userdata
;
238 _cleanup_free_
uint8_t *array
= NULL
;
245 (void) cpu_set_to_dbus(&c
->numa_policy
.nodes
, &array
, &allocated
);
247 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
250 static int property_get_numa_policy(
253 const char *interface
,
254 const char *property
,
255 sd_bus_message
*reply
,
257 sd_bus_error
*error
) {
258 ExecContext
*c
= userdata
;
265 policy
= numa_policy_get_type(&c
->numa_policy
);
267 return sd_bus_message_append_basic(reply
, 'i', &policy
);
270 static int property_get_timer_slack_nsec(
273 const char *interface
,
274 const char *property
,
275 sd_bus_message
*reply
,
277 sd_bus_error
*error
) {
279 ExecContext
*c
= userdata
;
286 if (c
->timer_slack_nsec
!= NSEC_INFINITY
)
287 u
= (uint64_t) c
->timer_slack_nsec
;
289 u
= (uint64_t) prctl(PR_GET_TIMERSLACK
);
291 return sd_bus_message_append(reply
, "t", u
);
294 static int property_get_syscall_filter(
297 const char *interface
,
298 const char *property
,
299 sd_bus_message
*reply
,
301 sd_bus_error
*error
) {
303 ExecContext
*c
= userdata
;
304 _cleanup_strv_free_
char **l
= NULL
;
316 r
= sd_bus_message_open_container(reply
, 'r', "bas");
320 r
= sd_bus_message_append(reply
, "b", c
->syscall_whitelist
);
325 HASHMAP_FOREACH_KEY(val
, id
, c
->syscall_filter
, i
) {
326 _cleanup_free_
char *name
= NULL
;
327 const char *e
= NULL
;
329 int num
= PTR_TO_INT(val
);
331 name
= seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE
, PTR_TO_INT(id
) - 1);
336 e
= errno_to_name(num
);
338 s
= strjoin(name
, ":", e
);
342 r
= asprintf(&s
, "%s:%d", name
, num
);
349 r
= strv_consume(&l
, s
);
357 r
= sd_bus_message_append_strv(reply
, l
);
361 return sd_bus_message_close_container(reply
);
364 static int property_get_syscall_archs(
367 const char *interface
,
368 const char *property
,
369 sd_bus_message
*reply
,
371 sd_bus_error
*error
) {
373 ExecContext
*c
= userdata
;
374 _cleanup_strv_free_
char **l
= NULL
;
387 SET_FOREACH(id
, c
->syscall_archs
, i
) {
390 name
= seccomp_arch_to_string(PTR_TO_UINT32(id
) - 1);
394 r
= strv_extend(&l
, name
);
402 r
= sd_bus_message_append_strv(reply
, l
);
409 static int property_get_selinux_context(
412 const char *interface
,
413 const char *property
,
414 sd_bus_message
*reply
,
416 sd_bus_error
*error
) {
418 ExecContext
*c
= userdata
;
424 return sd_bus_message_append(reply
, "(bs)", c
->selinux_context_ignore
, c
->selinux_context
);
427 static int property_get_apparmor_profile(
430 const char *interface
,
431 const char *property
,
432 sd_bus_message
*reply
,
434 sd_bus_error
*error
) {
436 ExecContext
*c
= userdata
;
442 return sd_bus_message_append(reply
, "(bs)", c
->apparmor_profile_ignore
, c
->apparmor_profile
);
445 static int property_get_smack_process_label(
448 const char *interface
,
449 const char *property
,
450 sd_bus_message
*reply
,
452 sd_bus_error
*error
) {
454 ExecContext
*c
= userdata
;
460 return sd_bus_message_append(reply
, "(bs)", c
->smack_process_label_ignore
, c
->smack_process_label
);
463 static int property_get_address_families(
466 const char *interface
,
467 const char *property
,
468 sd_bus_message
*reply
,
470 sd_bus_error
*error
) {
472 ExecContext
*c
= userdata
;
473 _cleanup_strv_free_
char **l
= NULL
;
482 r
= sd_bus_message_open_container(reply
, 'r', "bas");
486 r
= sd_bus_message_append(reply
, "b", c
->address_families_whitelist
);
490 SET_FOREACH(af
, c
->address_families
, i
) {
493 name
= af_to_name(PTR_TO_INT(af
));
497 r
= strv_extend(&l
, name
);
504 r
= sd_bus_message_append_strv(reply
, l
);
508 return sd_bus_message_close_container(reply
);
511 static int property_get_working_directory(
514 const char *interface
,
515 const char *property
,
516 sd_bus_message
*reply
,
518 sd_bus_error
*error
) {
520 ExecContext
*c
= userdata
;
527 if (c
->working_directory_home
)
530 wd
= c
->working_directory
;
532 if (c
->working_directory_missing_ok
)
533 wd
= strjoina("!", wd
);
535 return sd_bus_message_append(reply
, "s", wd
);
538 static int property_get_stdio_fdname(
541 const char *interface
,
542 const char *property
,
543 sd_bus_message
*reply
,
545 sd_bus_error
*error
) {
547 ExecContext
*c
= userdata
;
555 if (streq(property
, "StandardInputFileDescriptorName"))
556 fileno
= STDIN_FILENO
;
557 else if (streq(property
, "StandardOutputFileDescriptorName"))
558 fileno
= STDOUT_FILENO
;
560 assert(streq(property
, "StandardErrorFileDescriptorName"));
561 fileno
= STDERR_FILENO
;
564 return sd_bus_message_append(reply
, "s", exec_context_fdname(c
, fileno
));
567 static int property_get_input_data(
570 const char *interface
,
571 const char *property
,
572 sd_bus_message
*reply
,
574 sd_bus_error
*error
) {
576 ExecContext
*c
= userdata
;
583 return sd_bus_message_append_array(reply
, 'y', c
->stdin_data
, c
->stdin_data_size
);
586 static int property_get_bind_paths(
589 const char *interface
,
590 const char *property
,
591 sd_bus_message
*reply
,
593 sd_bus_error
*error
) {
595 ExecContext
*c
= userdata
;
605 ro
= strstr(property
, "ReadOnly");
607 r
= sd_bus_message_open_container(reply
, 'a', "(ssbt)");
611 for (i
= 0; i
< c
->n_bind_mounts
; i
++) {
613 if (ro
!= c
->bind_mounts
[i
].read_only
)
616 r
= sd_bus_message_append(
618 c
->bind_mounts
[i
].source
,
619 c
->bind_mounts
[i
].destination
,
620 c
->bind_mounts
[i
].ignore_enoent
,
621 c
->bind_mounts
[i
].recursive
? (uint64_t) MS_REC
: (uint64_t) 0);
626 return sd_bus_message_close_container(reply
);
629 static int property_get_temporary_filesystems(
632 const char *interface
,
633 const char *property
,
634 sd_bus_message
*reply
,
636 sd_bus_error
*error
) {
638 ExecContext
*c
= userdata
;
647 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
651 for (i
= 0; i
< c
->n_temporary_filesystems
; i
++) {
652 TemporaryFileSystem
*t
= c
->temporary_filesystems
+ i
;
654 r
= sd_bus_message_append(
662 return sd_bus_message_close_container(reply
);
665 static int property_get_log_extra_fields(
668 const char *interface
,
669 const char *property
,
670 sd_bus_message
*reply
,
672 sd_bus_error
*error
) {
674 ExecContext
*c
= userdata
;
683 r
= sd_bus_message_open_container(reply
, 'a', "ay");
687 for (i
= 0; i
< c
->n_log_extra_fields
; i
++) {
688 r
= sd_bus_message_append_array(reply
, 'y', c
->log_extra_fields
[i
].iov_base
, c
->log_extra_fields
[i
].iov_len
);
693 return sd_bus_message_close_container(reply
);
696 const sd_bus_vtable bus_exec_vtable
[] = {
697 SD_BUS_VTABLE_START(0),
698 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(ExecContext
, environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
699 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
700 SD_BUS_PROPERTY("PassEnvironment", "as", NULL
, offsetof(ExecContext
, pass_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
701 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL
, offsetof(ExecContext
, unset_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
702 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode
, offsetof(ExecContext
, umask
), SD_BUS_VTABLE_PROPERTY_CONST
),
703 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
704 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
705 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
706 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
707 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
708 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
709 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
710 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
711 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
712 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
713 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
714 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
715 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
716 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
717 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
718 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
719 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
720 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
721 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
722 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
723 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
724 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
725 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
726 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
727 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
728 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
729 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
730 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
731 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
732 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
733 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
734 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
735 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
736 SD_BUS_PROPERTY("RootDirectory", "s", NULL
, offsetof(ExecContext
, root_directory
), SD_BUS_VTABLE_PROPERTY_CONST
),
737 SD_BUS_PROPERTY("RootImage", "s", NULL
, offsetof(ExecContext
, root_image
), SD_BUS_VTABLE_PROPERTY_CONST
),
738 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
739 SD_BUS_PROPERTY("Nice", "i", property_get_nice
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
740 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
741 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
742 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
743 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
744 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
745 SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
746 SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
747 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
748 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool
, offsetof(ExecContext
, cpu_sched_reset_on_fork
), SD_BUS_VTABLE_PROPERTY_CONST
),
749 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool
, offsetof(ExecContext
, non_blocking
), SD_BUS_VTABLE_PROPERTY_CONST
),
750 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input
, offsetof(ExecContext
, std_input
), SD_BUS_VTABLE_PROPERTY_CONST
),
751 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
752 SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
753 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
754 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
755 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_error
), SD_BUS_VTABLE_PROPERTY_CONST
),
756 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
757 SD_BUS_PROPERTY("TTYPath", "s", NULL
, offsetof(ExecContext
, tty_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
758 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_reset
), SD_BUS_VTABLE_PROPERTY_CONST
),
759 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vhangup
), SD_BUS_VTABLE_PROPERTY_CONST
),
760 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vt_disallocate
), SD_BUS_VTABLE_PROPERTY_CONST
),
761 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
762 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL
, offsetof(ExecContext
, syslog_identifier
), SD_BUS_VTABLE_PROPERTY_CONST
),
763 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool
, offsetof(ExecContext
, syslog_level_prefix
), SD_BUS_VTABLE_PROPERTY_CONST
),
764 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
765 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
766 SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int
, offsetof(ExecContext
, log_level_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
767 SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec
, offsetof(ExecContext
, log_rate_limit_interval_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
768 SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned
, offsetof(ExecContext
, log_rate_limit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
769 SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
770 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int
, offsetof(ExecContext
, secure_bits
), SD_BUS_VTABLE_PROPERTY_CONST
),
771 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL
, offsetof(ExecContext
, capability_bounding_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
772 SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL
, offsetof(ExecContext
, capability_ambient_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
773 SD_BUS_PROPERTY("User", "s", NULL
, offsetof(ExecContext
, user
), SD_BUS_VTABLE_PROPERTY_CONST
),
774 SD_BUS_PROPERTY("Group", "s", NULL
, offsetof(ExecContext
, group
), SD_BUS_VTABLE_PROPERTY_CONST
),
775 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool
, offsetof(ExecContext
, dynamic_user
), SD_BUS_VTABLE_PROPERTY_CONST
),
776 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, remove_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
777 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL
, offsetof(ExecContext
, supplementary_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
778 SD_BUS_PROPERTY("PAMName", "s", NULL
, offsetof(ExecContext
, pam_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
779 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
780 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
781 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
782 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong
, offsetof(ExecContext
, mount_flags
), SD_BUS_VTABLE_PROPERTY_CONST
),
783 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool
, offsetof(ExecContext
, private_tmp
), SD_BUS_VTABLE_PROPERTY_CONST
),
784 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool
, offsetof(ExecContext
, private_devices
), SD_BUS_VTABLE_PROPERTY_CONST
),
785 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_tunables
), SD_BUS_VTABLE_PROPERTY_CONST
),
786 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_modules
), SD_BUS_VTABLE_PROPERTY_CONST
),
787 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_control_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
788 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool
, offsetof(ExecContext
, private_network
), SD_BUS_VTABLE_PROPERTY_CONST
),
789 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool
, offsetof(ExecContext
, private_users
), SD_BUS_VTABLE_PROPERTY_CONST
),
790 SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_bool
, offsetof(ExecContext
, private_mounts
), SD_BUS_VTABLE_PROPERTY_CONST
),
791 SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home
, offsetof(ExecContext
, protect_home
), SD_BUS_VTABLE_PROPERTY_CONST
),
792 SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system
, offsetof(ExecContext
, protect_system
), SD_BUS_VTABLE_PROPERTY_CONST
),
793 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool
, offsetof(ExecContext
, same_pgrp
), SD_BUS_VTABLE_PROPERTY_CONST
),
794 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL
, offsetof(ExecContext
, utmp_id
), SD_BUS_VTABLE_PROPERTY_CONST
),
795 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode
, offsetof(ExecContext
, utmp_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
796 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
797 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
798 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
799 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool
, offsetof(ExecContext
, ignore_sigpipe
), SD_BUS_VTABLE_PROPERTY_CONST
),
800 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool
, offsetof(ExecContext
, no_new_privileges
), SD_BUS_VTABLE_PROPERTY_CONST
),
801 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
802 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
803 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int
, offsetof(ExecContext
, syscall_errno
), SD_BUS_VTABLE_PROPERTY_CONST
),
804 SD_BUS_PROPERTY("Personality", "s", property_get_personality
, offsetof(ExecContext
, personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
805 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool
, offsetof(ExecContext
, lock_personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
806 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
807 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode
, offsetof(ExecContext
, runtime_directory_preserve_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
808 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
809 SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
810 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
811 SD_BUS_PROPERTY("StateDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
812 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
813 SD_BUS_PROPERTY("CacheDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
814 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
815 SD_BUS_PROPERTY("LogsDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
816 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
817 SD_BUS_PROPERTY("ConfigurationDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
818 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool
, offsetof(ExecContext
, memory_deny_write_execute
), SD_BUS_VTABLE_PROPERTY_CONST
),
819 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_realtime
), SD_BUS_VTABLE_PROPERTY_CONST
),
820 SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_suid_sgid
), SD_BUS_VTABLE_PROPERTY_CONST
),
821 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong
, offsetof(ExecContext
, restrict_namespaces
), SD_BUS_VTABLE_PROPERTY_CONST
),
822 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
823 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
824 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
825 SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool
, offsetof(ExecContext
, mount_apivfs
), SD_BUS_VTABLE_PROPERTY_CONST
),
826 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode
, offsetof(ExecContext
, keyring_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
827 SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_hostname
), SD_BUS_VTABLE_PROPERTY_CONST
),
828 SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL
, offsetof(ExecContext
, network_namespace_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
830 /* Obsolete/redundant properties: */
831 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
832 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
833 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
834 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
835 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
840 static int append_exec_command(sd_bus_message
*reply
, ExecCommand
*c
) {
849 r
= sd_bus_message_open_container(reply
, 'r', "sasbttttuii");
853 r
= sd_bus_message_append(reply
, "s", c
->path
);
857 r
= sd_bus_message_append_strv(reply
, c
->argv
);
861 r
= sd_bus_message_append(reply
, "bttttuii",
862 !!(c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
),
863 c
->exec_status
.start_timestamp
.realtime
,
864 c
->exec_status
.start_timestamp
.monotonic
,
865 c
->exec_status
.exit_timestamp
.realtime
,
866 c
->exec_status
.exit_timestamp
.monotonic
,
867 (uint32_t) c
->exec_status
.pid
,
868 (int32_t) c
->exec_status
.code
,
869 (int32_t) c
->exec_status
.status
);
873 return sd_bus_message_close_container(reply
);
876 static int append_exec_ex_command(sd_bus_message
*reply
, ExecCommand
*c
) {
877 _cleanup_strv_free_
char **ex_opts
= NULL
;
886 r
= sd_bus_message_open_container(reply
, 'r', "sasasttttuii");
890 r
= sd_bus_message_append(reply
, "s", c
->path
);
894 r
= sd_bus_message_append_strv(reply
, c
->argv
);
898 r
= exec_command_flags_to_strv(c
->flags
, &ex_opts
);
902 r
= sd_bus_message_append_strv(reply
, ex_opts
);
906 r
= sd_bus_message_append(reply
, "ttttuii",
907 c
->exec_status
.start_timestamp
.realtime
,
908 c
->exec_status
.start_timestamp
.monotonic
,
909 c
->exec_status
.exit_timestamp
.realtime
,
910 c
->exec_status
.exit_timestamp
.monotonic
,
911 (uint32_t) c
->exec_status
.pid
,
912 (int32_t) c
->exec_status
.code
,
913 (int32_t) c
->exec_status
.status
);
917 return sd_bus_message_close_container(reply
);
920 int bus_property_get_exec_command(
923 const char *interface
,
924 const char *property
,
925 sd_bus_message
*reply
,
927 sd_bus_error
*ret_error
) {
929 ExecCommand
*c
= (ExecCommand
*) userdata
;
935 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
939 r
= append_exec_command(reply
, c
);
943 return sd_bus_message_close_container(reply
);
946 int bus_property_get_exec_command_list(
949 const char *interface
,
950 const char *property
,
951 sd_bus_message
*reply
,
953 sd_bus_error
*ret_error
) {
955 ExecCommand
*c
= *(ExecCommand
**) userdata
;
961 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
965 LIST_FOREACH(command
, c
, c
) {
966 r
= append_exec_command(reply
, c
);
971 return sd_bus_message_close_container(reply
);
974 int bus_property_get_exec_ex_command_list(
977 const char *interface
,
978 const char *property
,
979 sd_bus_message
*reply
,
981 sd_bus_error
*ret_error
) {
983 ExecCommand
*c
, *exec_command
= *(ExecCommand
**) userdata
;
989 r
= sd_bus_message_open_container(reply
, 'a', "(sasasttttuii)");
993 LIST_FOREACH(command
, c
, exec_command
) {
994 r
= append_exec_ex_command(reply
, c
);
999 return sd_bus_message_close_container(reply
);
1002 static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags
) {
1005 asprintf(&res
, "%s%s%s%s%s",
1006 FLAGS_SET(flags
, EXEC_COMMAND_IGNORE_FAILURE
) ? "-" : "",
1007 FLAGS_SET(flags
, EXEC_COMMAND_NO_ENV_EXPAND
) ? ":" : "",
1008 FLAGS_SET(flags
, EXEC_COMMAND_FULLY_PRIVILEGED
) ? "+" : "",
1009 FLAGS_SET(flags
, EXEC_COMMAND_NO_SETUID
) ? "!" : "",
1010 FLAGS_SET(flags
, EXEC_COMMAND_AMBIENT_MAGIC
) ? "!!" : "");
1015 int bus_set_transient_exec_command(
1018 ExecCommand
**exec_command
,
1019 sd_bus_message
*message
,
1020 UnitWriteFlags flags
,
1021 sd_bus_error
*error
) {
1022 bool is_ex_prop
= endswith(name
, "Ex");
1026 r
= sd_bus_message_enter_container(message
, 'a', is_ex_prop
? "(sasas)" : "(sasb)");
1030 while ((r
= sd_bus_message_enter_container(message
, 'r', is_ex_prop
? "sasas" : "sasb")) > 0) {
1031 _cleanup_strv_free_
char **argv
= NULL
, **ex_opts
= NULL
;
1035 r
= sd_bus_message_read(message
, "s", &path
);
1039 if (!path_is_absolute(path
))
1040 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
1042 r
= sd_bus_message_read_strv(message
, &argv
);
1046 r
= is_ex_prop
? sd_bus_message_read_strv(message
, &ex_opts
) : sd_bus_message_read(message
, "b", &b
);
1050 r
= sd_bus_message_exit_container(message
);
1054 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1057 c
= new0(ExecCommand
, 1);
1061 c
->path
= strdup(path
);
1067 c
->argv
= TAKE_PTR(argv
);
1070 r
= exec_command_flags_from_strv(ex_opts
, &c
->flags
);
1074 c
->flags
= b
? EXEC_COMMAND_IGNORE_FAILURE
: 0;
1076 path_simplify(c
->path
, false);
1077 exec_command_append_list(exec_command
, c
);
1085 r
= sd_bus_message_exit_container(message
);
1089 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1090 _cleanup_free_
char *buf
= NULL
;
1091 _cleanup_fclose_
FILE *f
= NULL
;
1096 *exec_command
= exec_command_free_list(*exec_command
);
1098 f
= open_memstream_unlocked(&buf
, &size
);
1102 fputs("ExecStart=\n", f
);
1104 LIST_FOREACH(command
, c
, *exec_command
) {
1105 _cleanup_free_
char *a
= NULL
, *t
= NULL
, *exec_chars
= NULL
;
1108 p
= unit_escape_setting(c
->path
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
, &t
);
1112 a
= unit_concat_strv(c
->argv
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
);
1116 exec_chars
= exec_command_flags_to_exec_chars(c
->flags
);
1120 fprintf(f
, "%s=%s@%s %s\n", name
, exec_chars
, p
, a
);
1123 r
= fflush_and_check(f
);
1127 unit_write_setting(u
, flags
, name
, buf
);
1133 static int parse_personality(const char *s
, unsigned long *p
) {
1138 v
= personality_from_string(s
);
1139 if (v
== PERSONALITY_INVALID
)
1146 static const char* mount_propagation_flags_to_string_with_check(unsigned long n
) {
1147 if (!IN_SET(n
, 0, MS_SHARED
, MS_PRIVATE
, MS_SLAVE
))
1150 return mount_propagation_flags_to_string(n
);
1153 static BUS_DEFINE_SET_TRANSIENT(nsec
, "t", uint64_t, nsec_t
, NSEC_FMT
);
1154 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level
, "i", int32_t, int, "%" PRIi32
, log_level_is_valid
);
1156 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno
, "i", int32_t, int, "%" PRIi32
, errno_is_valid
);
1158 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input
, ExecInput
, exec_input_from_string
);
1159 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output
, ExecOutput
, exec_output_from_string
);
1160 static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode
, ExecUtmpMode
, exec_utmp_mode_from_string
);
1161 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system
, ProtectSystem
, protect_system_from_string
);
1162 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home
, ProtectHome
, protect_home_from_string
);
1163 static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode
, ExecKeyringMode
, exec_keyring_mode_from_string
);
1164 static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode
, ExecPreserveMode
, exec_preserve_mode_from_string
);
1165 static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality
, unsigned long, parse_personality
);
1166 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits
, "i", int32_t, int, "%" PRIi32
, secure_bits_to_string_alloc_with_check
);
1167 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability
, "t", uint64_t, uint64_t, "%" PRIu64
, capability_set_to_string_alloc
);
1168 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag
, "t", uint64_t, unsigned long, "%" PRIu64
, namespace_flags_to_string
);
1169 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags
, "t", uint64_t, unsigned long, "%" PRIu64
, mount_propagation_flags_to_string_with_check
);
1171 int bus_exec_context_set_transient_property(
1175 sd_bus_message
*message
,
1176 UnitWriteFlags flags
,
1177 sd_bus_error
*error
) {
1187 flags
|= UNIT_PRIVATE
;
1189 if (streq(name
, "User"))
1190 return bus_set_transient_user_compat(u
, name
, &c
->user
, message
, flags
, error
);
1192 if (streq(name
, "Group"))
1193 return bus_set_transient_user_compat(u
, name
, &c
->group
, message
, flags
, error
);
1195 if (streq(name
, "TTYPath"))
1196 return bus_set_transient_path(u
, name
, &c
->tty_path
, message
, flags
, error
);
1198 if (streq(name
, "RootImage"))
1199 return bus_set_transient_path(u
, name
, &c
->root_image
, message
, flags
, error
);
1201 if (streq(name
, "RootDirectory"))
1202 return bus_set_transient_path(u
, name
, &c
->root_directory
, message
, flags
, error
);
1204 if (streq(name
, "SyslogIdentifier"))
1205 return bus_set_transient_string(u
, name
, &c
->syslog_identifier
, message
, flags
, error
);
1207 if (streq(name
, "LogLevelMax"))
1208 return bus_set_transient_log_level(u
, name
, &c
->log_level_max
, message
, flags
, error
);
1210 if (streq(name
, "LogRateLimitIntervalUSec"))
1211 return bus_set_transient_usec(u
, name
, &c
->log_rate_limit_interval_usec
, message
, flags
, error
);
1213 if (streq(name
, "LogRateLimitBurst"))
1214 return bus_set_transient_unsigned(u
, name
, &c
->log_rate_limit_burst
, message
, flags
, error
);
1216 if (streq(name
, "Personality"))
1217 return bus_set_transient_personality(u
, name
, &c
->personality
, message
, flags
, error
);
1219 if (streq(name
, "StandardInput"))
1220 return bus_set_transient_std_input(u
, name
, &c
->std_input
, message
, flags
, error
);
1222 if (streq(name
, "StandardOutput"))
1223 return bus_set_transient_std_output(u
, name
, &c
->std_output
, message
, flags
, error
);
1225 if (streq(name
, "StandardError"))
1226 return bus_set_transient_std_output(u
, name
, &c
->std_error
, message
, flags
, error
);
1228 if (streq(name
, "IgnoreSIGPIPE"))
1229 return bus_set_transient_bool(u
, name
, &c
->ignore_sigpipe
, message
, flags
, error
);
1231 if (streq(name
, "TTYVHangup"))
1232 return bus_set_transient_bool(u
, name
, &c
->tty_vhangup
, message
, flags
, error
);
1234 if (streq(name
, "TTYReset"))
1235 return bus_set_transient_bool(u
, name
, &c
->tty_reset
, message
, flags
, error
);
1237 if (streq(name
, "TTYVTDisallocate"))
1238 return bus_set_transient_bool(u
, name
, &c
->tty_vt_disallocate
, message
, flags
, error
);
1240 if (streq(name
, "PrivateTmp"))
1241 return bus_set_transient_bool(u
, name
, &c
->private_tmp
, message
, flags
, error
);
1243 if (streq(name
, "PrivateDevices"))
1244 return bus_set_transient_bool(u
, name
, &c
->private_devices
, message
, flags
, error
);
1246 if (streq(name
, "PrivateMounts"))
1247 return bus_set_transient_bool(u
, name
, &c
->private_mounts
, message
, flags
, error
);
1249 if (streq(name
, "PrivateNetwork"))
1250 return bus_set_transient_bool(u
, name
, &c
->private_network
, message
, flags
, error
);
1252 if (streq(name
, "PrivateUsers"))
1253 return bus_set_transient_bool(u
, name
, &c
->private_users
, message
, flags
, error
);
1255 if (streq(name
, "NoNewPrivileges"))
1256 return bus_set_transient_bool(u
, name
, &c
->no_new_privileges
, message
, flags
, error
);
1258 if (streq(name
, "SyslogLevelPrefix"))
1259 return bus_set_transient_bool(u
, name
, &c
->syslog_level_prefix
, message
, flags
, error
);
1261 if (streq(name
, "MemoryDenyWriteExecute"))
1262 return bus_set_transient_bool(u
, name
, &c
->memory_deny_write_execute
, message
, flags
, error
);
1264 if (streq(name
, "RestrictRealtime"))
1265 return bus_set_transient_bool(u
, name
, &c
->restrict_realtime
, message
, flags
, error
);
1267 if (streq(name
, "RestrictSUIDSGID"))
1268 return bus_set_transient_bool(u
, name
, &c
->restrict_suid_sgid
, message
, flags
, error
);
1270 if (streq(name
, "DynamicUser"))
1271 return bus_set_transient_bool(u
, name
, &c
->dynamic_user
, message
, flags
, error
);
1273 if (streq(name
, "RemoveIPC"))
1274 return bus_set_transient_bool(u
, name
, &c
->remove_ipc
, message
, flags
, error
);
1276 if (streq(name
, "ProtectKernelTunables"))
1277 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_tunables
, message
, flags
, error
);
1279 if (streq(name
, "ProtectKernelModules"))
1280 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_modules
, message
, flags
, error
);
1282 if (streq(name
, "ProtectControlGroups"))
1283 return bus_set_transient_bool(u
, name
, &c
->protect_control_groups
, message
, flags
, error
);
1285 if (streq(name
, "MountAPIVFS"))
1286 return bus_set_transient_bool(u
, name
, &c
->mount_apivfs
, message
, flags
, error
);
1288 if (streq(name
, "CPUSchedulingResetOnFork"))
1289 return bus_set_transient_bool(u
, name
, &c
->cpu_sched_reset_on_fork
, message
, flags
, error
);
1291 if (streq(name
, "NonBlocking"))
1292 return bus_set_transient_bool(u
, name
, &c
->non_blocking
, message
, flags
, error
);
1294 if (streq(name
, "LockPersonality"))
1295 return bus_set_transient_bool(u
, name
, &c
->lock_personality
, message
, flags
, error
);
1297 if (streq(name
, "ProtectHostname"))
1298 return bus_set_transient_bool(u
, name
, &c
->protect_hostname
, message
, flags
, error
);
1300 if (streq(name
, "UtmpIdentifier"))
1301 return bus_set_transient_string(u
, name
, &c
->utmp_id
, message
, flags
, error
);
1303 if (streq(name
, "UtmpMode"))
1304 return bus_set_transient_utmp_mode(u
, name
, &c
->utmp_mode
, message
, flags
, error
);
1306 if (streq(name
, "PAMName"))
1307 return bus_set_transient_string(u
, name
, &c
->pam_name
, message
, flags
, error
);
1309 if (streq(name
, "TimerSlackNSec"))
1310 return bus_set_transient_nsec(u
, name
, &c
->timer_slack_nsec
, message
, flags
, error
);
1312 if (streq(name
, "ProtectSystem"))
1313 return bus_set_transient_protect_system(u
, name
, &c
->protect_system
, message
, flags
, error
);
1315 if (streq(name
, "ProtectHome"))
1316 return bus_set_transient_protect_home(u
, name
, &c
->protect_home
, message
, flags
, error
);
1318 if (streq(name
, "KeyringMode"))
1319 return bus_set_transient_keyring_mode(u
, name
, &c
->keyring_mode
, message
, flags
, error
);
1321 if (streq(name
, "RuntimeDirectoryPreserve"))
1322 return bus_set_transient_preserve_mode(u
, name
, &c
->runtime_directory_preserve_mode
, message
, flags
, error
);
1324 if (streq(name
, "UMask"))
1325 return bus_set_transient_mode_t(u
, name
, &c
->umask
, message
, flags
, error
);
1327 if (streq(name
, "RuntimeDirectoryMode"))
1328 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_RUNTIME
].mode
, message
, flags
, error
);
1330 if (streq(name
, "StateDirectoryMode"))
1331 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_STATE
].mode
, message
, flags
, error
);
1333 if (streq(name
, "CacheDirectoryMode"))
1334 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CACHE
].mode
, message
, flags
, error
);
1336 if (streq(name
, "LogsDirectoryMode"))
1337 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_LOGS
].mode
, message
, flags
, error
);
1339 if (streq(name
, "ConfigurationDirectoryMode"))
1340 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
, message
, flags
, error
);
1342 if (streq(name
, "SELinuxContext"))
1343 return bus_set_transient_string(u
, name
, &c
->selinux_context
, message
, flags
, error
);
1345 if (streq(name
, "SecureBits"))
1346 return bus_set_transient_secure_bits(u
, name
, &c
->secure_bits
, message
, flags
, error
);
1348 if (streq(name
, "CapabilityBoundingSet"))
1349 return bus_set_transient_capability(u
, name
, &c
->capability_bounding_set
, message
, flags
, error
);
1351 if (streq(name
, "AmbientCapabilities"))
1352 return bus_set_transient_capability(u
, name
, &c
->capability_ambient_set
, message
, flags
, error
);
1354 if (streq(name
, "RestrictNamespaces"))
1355 return bus_set_transient_namespace_flag(u
, name
, &c
->restrict_namespaces
, message
, flags
, error
);
1357 if (streq(name
, "MountFlags"))
1358 return bus_set_transient_mount_flags(u
, name
, &c
->mount_flags
, message
, flags
, error
);
1360 if (streq(name
, "NetworkNamespacePath"))
1361 return bus_set_transient_path(u
, name
, &c
->network_namespace_path
, message
, flags
, error
);
1363 if (streq(name
, "SupplementaryGroups")) {
1364 _cleanup_strv_free_
char **l
= NULL
;
1367 r
= sd_bus_message_read_strv(message
, &l
);
1372 if (!isempty(*p
) && !valid_user_group_name_or_id_compat(*p
))
1373 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
1374 "Invalid supplementary group names");
1376 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1377 if (strv_isempty(l
)) {
1378 c
->supplementary_groups
= strv_free(c
->supplementary_groups
);
1379 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1381 _cleanup_free_
char *joined
= NULL
;
1383 r
= strv_extend_strv(&c
->supplementary_groups
, l
, true);
1387 joined
= strv_join(c
->supplementary_groups
, " ");
1391 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s", name
, joined
);
1397 } else if (streq(name
, "SyslogLevel")) {
1400 r
= sd_bus_message_read(message
, "i", &level
);
1404 if (!log_level_is_valid(level
))
1405 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log level value out of range");
1407 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1408 c
->syslog_priority
= (c
->syslog_priority
& LOG_FACMASK
) | level
;
1409 unit_write_settingf(u
, flags
, name
, "SyslogLevel=%i", level
);
1414 } else if (streq(name
, "SyslogFacility")) {
1417 r
= sd_bus_message_read(message
, "i", &facility
);
1421 if (!log_facility_unshifted_is_valid(facility
))
1422 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log facility value out of range");
1424 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1425 c
->syslog_priority
= (facility
<< 3) | LOG_PRI(c
->syslog_priority
);
1426 unit_write_settingf(u
, flags
, name
, "SyslogFacility=%i", facility
);
1431 } else if (streq(name
, "LogExtraFields")) {
1434 r
= sd_bus_message_enter_container(message
, 'a', "ay");
1439 _cleanup_free_
void *copy
= NULL
;
1445 /* Note that we expect a byte array for each field, instead of a string. That's because on the
1446 * lower-level journal fields can actually contain binary data and are not restricted to text,
1447 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
1448 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
1449 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
1450 * limitation, should a good, valid usecase arise. */
1452 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
1458 if (memchr(p
, 0, sz
))
1459 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains zero byte");
1461 eq
= memchr(p
, '=', sz
);
1463 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains no '=' character");
1464 if (!journal_field_valid(p
, eq
- (const char*) p
, false))
1465 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field invalid");
1467 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1468 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
1471 c
->log_extra_fields
= t
;
1474 copy
= malloc(sz
+ 1);
1478 memcpy(copy
, p
, sz
);
1479 ((uint8_t*) copy
)[sz
] = 0;
1481 if (!utf8_is_valid(copy
))
1482 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field is not valid UTF-8");
1484 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1485 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE(copy
, sz
);
1486 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
, name
, "LogExtraFields=%s", (char*) copy
);
1494 r
= sd_bus_message_exit_container(message
);
1498 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && n
== 0) {
1499 exec_context_free_log_extra_fields(c
);
1500 unit_write_setting(u
, flags
, name
, "LogExtraFields=");
1508 if (streq(name
, "SystemCallErrorNumber"))
1509 return bus_set_transient_errno(u
, name
, &c
->syscall_errno
, message
, flags
, error
);
1511 if (streq(name
, "SystemCallFilter")) {
1513 _cleanup_strv_free_
char **l
= NULL
;
1515 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1519 r
= sd_bus_message_read(message
, "b", &whitelist
);
1523 r
= sd_bus_message_read_strv(message
, &l
);
1527 r
= sd_bus_message_exit_container(message
);
1531 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1532 _cleanup_free_
char *joined
= NULL
;
1533 SeccompParseFlags invert_flag
= whitelist
? 0 : SECCOMP_PARSE_INVERT
;
1536 if (strv_isempty(l
)) {
1537 c
->syscall_whitelist
= false;
1538 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
1540 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=");
1544 if (!c
->syscall_filter
) {
1545 c
->syscall_filter
= hashmap_new(NULL
);
1546 if (!c
->syscall_filter
)
1549 c
->syscall_whitelist
= whitelist
;
1551 if (c
->syscall_whitelist
) {
1552 r
= seccomp_parse_syscall_filter("@default",
1555 SECCOMP_PARSE_WHITELIST
| invert_flag
,
1563 STRV_FOREACH(s
, l
) {
1564 _cleanup_free_
char *n
= NULL
;
1567 r
= parse_syscall_and_errno(*s
, &n
, &e
);
1571 r
= seccomp_parse_syscall_filter(n
,
1574 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0) | invert_flag
,
1581 joined
= strv_join(l
, " ");
1585 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=%s%s", whitelist
? "" : "~", joined
);
1590 } else if (streq(name
, "SystemCallArchitectures")) {
1591 _cleanup_strv_free_
char **l
= NULL
;
1593 r
= sd_bus_message_read_strv(message
, &l
);
1597 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1598 _cleanup_free_
char *joined
= NULL
;
1600 if (strv_isempty(l
))
1601 c
->syscall_archs
= set_free(c
->syscall_archs
);
1605 r
= set_ensure_allocated(&c
->syscall_archs
, NULL
);
1609 STRV_FOREACH(s
, l
) {
1612 r
= seccomp_arch_from_string(*s
, &a
);
1616 r
= set_put(c
->syscall_archs
, UINT32_TO_PTR(a
+ 1));
1623 joined
= strv_join(l
, " ");
1627 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
1632 } else if (streq(name
, "RestrictAddressFamilies")) {
1634 _cleanup_strv_free_
char **l
= NULL
;
1636 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1640 r
= sd_bus_message_read(message
, "b", &whitelist
);
1644 r
= sd_bus_message_read_strv(message
, &l
);
1648 r
= sd_bus_message_exit_container(message
);
1652 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1653 _cleanup_free_
char *joined
= NULL
;
1656 if (strv_isempty(l
)) {
1657 c
->address_families_whitelist
= false;
1658 c
->address_families
= set_free(c
->address_families
);
1660 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=");
1664 if (!c
->address_families
) {
1665 c
->address_families
= set_new(NULL
);
1666 if (!c
->address_families
)
1669 c
->address_families_whitelist
= whitelist
;
1672 STRV_FOREACH(s
, l
) {
1675 af
= af_from_name(*s
);
1679 if (whitelist
== c
->address_families_whitelist
) {
1680 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
1684 (void) set_remove(c
->address_families
, INT_TO_PTR(af
));
1687 joined
= strv_join(l
, " ");
1691 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=%s%s", whitelist
? "" : "~", joined
);
1697 if (STR_IN_SET(name
, "CPUAffinity", "NUMAMask")) {
1700 bool affinity
= streq(name
, "CPUAffinity");
1701 _cleanup_(cpu_set_reset
) CPUSet set
= {};
1703 r
= sd_bus_message_read_array(message
, 'y', &a
, &n
);
1707 r
= cpu_set_from_dbus(a
, n
, &set
);
1711 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1713 cpu_set_reset(affinity
? &c
->cpu_set
: &c
->numa_policy
.nodes
);
1714 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1716 _cleanup_free_
char *str
= NULL
;
1718 str
= cpu_set_to_string(&set
);
1722 /* We forego any optimizations here, and always create the structure using
1723 * cpu_set_add_all(), because we don't want to care if the existing size we
1724 * got over dbus is appropriate. */
1725 r
= cpu_set_add_all(affinity
? &c
->cpu_set
: &c
->numa_policy
.nodes
, &set
);
1729 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, str
);
1735 } else if (streq(name
, "NUMAPolicy")) {
1738 r
= sd_bus_message_read(message
, "i", &type
);
1742 if (!mpol_is_valid(type
))
1743 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid NUMAPolicy value: %i", type
);
1745 if (!UNIT_WRITE_FLAGS_NOOP(flags
))
1746 c
->numa_policy
.type
= type
;
1749 } else if (streq(name
, "Nice")) {
1752 r
= sd_bus_message_read(message
, "i", &q
);
1756 if (!nice_is_valid(q
))
1757 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid Nice value: %i", q
);
1759 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1763 unit_write_settingf(u
, flags
, name
, "Nice=%i", q
);
1768 } else if (streq(name
, "CPUSchedulingPolicy")) {
1771 r
= sd_bus_message_read(message
, "i", &q
);
1775 if (!sched_policy_is_valid(q
))
1776 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling policy: %i", q
);
1778 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1779 _cleanup_free_
char *s
= NULL
;
1781 r
= sched_policy_to_string_alloc(q
, &s
);
1785 c
->cpu_sched_policy
= q
;
1786 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(q
), sched_get_priority_max(q
));
1787 c
->cpu_sched_set
= true;
1789 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPolicy=%s", s
);
1794 } else if (streq(name
, "CPUSchedulingPriority")) {
1795 int32_t p
, min
, max
;
1797 r
= sd_bus_message_read(message
, "i", &p
);
1801 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1802 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1803 if (p
< min
|| p
> max
)
1804 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling priority: %i", p
);
1806 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1807 c
->cpu_sched_priority
= p
;
1808 c
->cpu_sched_set
= true;
1810 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPriority=%i", p
);
1815 } else if (streq(name
, "IOSchedulingClass")) {
1818 r
= sd_bus_message_read(message
, "i", &q
);
1822 if (!ioprio_class_is_valid(q
))
1823 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling class: %i", q
);
1825 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1826 _cleanup_free_
char *s
= NULL
;
1828 r
= ioprio_class_to_string_alloc(q
, &s
);
1832 c
->ioprio
= IOPRIO_PRIO_VALUE(q
, IOPRIO_PRIO_DATA(c
->ioprio
));
1833 c
->ioprio_set
= true;
1835 unit_write_settingf(u
, flags
, name
, "IOSchedulingClass=%s", s
);
1840 } else if (streq(name
, "IOSchedulingPriority")) {
1843 r
= sd_bus_message_read(message
, "i", &p
);
1847 if (!ioprio_priority_is_valid(p
))
1848 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling priority: %i", p
);
1850 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1851 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), p
);
1852 c
->ioprio_set
= true;
1854 unit_write_settingf(u
, flags
, name
, "IOSchedulingPriority=%i", p
);
1859 } else if (streq(name
, "WorkingDirectory")) {
1863 r
= sd_bus_message_read(message
, "s", &s
);
1873 if (!isempty(s
) && !streq(s
, "~") && !path_is_absolute(s
))
1874 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "WorkingDirectory= expects an absolute path or '~'");
1876 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1877 if (streq(s
, "~")) {
1878 c
->working_directory
= mfree(c
->working_directory
);
1879 c
->working_directory_home
= true;
1881 r
= free_and_strdup(&c
->working_directory
, empty_to_null(s
));
1885 c
->working_directory_home
= false;
1888 c
->working_directory_missing_ok
= missing_ok
;
1889 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "WorkingDirectory=%s%s", missing_ok
? "-" : "", s
);
1894 } else if (STR_IN_SET(name
,
1895 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
1898 r
= sd_bus_message_read(message
, "s", &s
);
1902 if (!isempty(s
) && !fdname_is_valid(s
))
1903 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid file descriptor name");
1905 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1907 if (streq(name
, "StandardInputFileDescriptorName")) {
1908 r
= free_and_strdup(c
->stdio_fdname
+ STDIN_FILENO
, empty_to_null(s
));
1912 c
->std_input
= EXEC_INPUT_NAMED_FD
;
1913 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=fd:%s", exec_context_fdname(c
, STDIN_FILENO
));
1915 } else if (streq(name
, "StandardOutputFileDescriptorName")) {
1916 r
= free_and_strdup(c
->stdio_fdname
+ STDOUT_FILENO
, empty_to_null(s
));
1920 c
->std_output
= EXEC_OUTPUT_NAMED_FD
;
1921 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=fd:%s", exec_context_fdname(c
, STDOUT_FILENO
));
1924 assert(streq(name
, "StandardErrorFileDescriptorName"));
1926 r
= free_and_strdup(&c
->stdio_fdname
[STDERR_FILENO
], empty_to_null(s
));
1930 c
->std_error
= EXEC_OUTPUT_NAMED_FD
;
1931 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=fd:%s", exec_context_fdname(c
, STDERR_FILENO
));
1937 } else if (STR_IN_SET(name
,
1938 "StandardInputFile",
1939 "StandardOutputFile", "StandardOutputFileToAppend",
1940 "StandardErrorFile", "StandardErrorFileToAppend")) {
1943 r
= sd_bus_message_read(message
, "s", &s
);
1948 if (!path_is_absolute(s
))
1949 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute", s
);
1950 if (!path_is_normalized(s
))
1951 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not normalized", s
);
1954 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1956 if (streq(name
, "StandardInputFile")) {
1957 r
= free_and_strdup(&c
->stdio_file
[STDIN_FILENO
], empty_to_null(s
));
1961 c
->std_input
= EXEC_INPUT_FILE
;
1962 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=file:%s", s
);
1964 } else if (STR_IN_SET(name
, "StandardOutputFile", "StandardOutputFileToAppend")) {
1965 r
= free_and_strdup(&c
->stdio_file
[STDOUT_FILENO
], empty_to_null(s
));
1969 if (streq(name
, "StandardOutputFile")) {
1970 c
->std_output
= EXEC_OUTPUT_FILE
;
1971 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=file:%s", s
);
1973 assert(streq(name
, "StandardOutputFileToAppend"));
1974 c
->std_output
= EXEC_OUTPUT_FILE_APPEND
;
1975 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=append:%s", s
);
1978 assert(STR_IN_SET(name
, "StandardErrorFile", "StandardErrorFileToAppend"));
1980 r
= free_and_strdup(&c
->stdio_file
[STDERR_FILENO
], empty_to_null(s
));
1984 if (streq(name
, "StandardErrorFile")) {
1985 c
->std_error
= EXEC_OUTPUT_FILE
;
1986 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=file:%s", s
);
1988 assert(streq(name
, "StandardErrorFileToAppend"));
1989 c
->std_error
= EXEC_OUTPUT_FILE_APPEND
;
1990 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=append:%s", s
);
1997 } else if (streq(name
, "StandardInputData")) {
2001 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
2005 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2006 _cleanup_free_
char *encoded
= NULL
;
2009 c
->stdin_data
= mfree(c
->stdin_data
);
2010 c
->stdin_data_size
= 0;
2012 unit_write_settingf(u
, flags
, name
, "StandardInputData=");
2017 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
2018 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
)
2021 n
= base64mem(p
, sz
, &encoded
);
2025 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
2029 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
2032 c
->stdin_data_size
+= sz
;
2034 unit_write_settingf(u
, flags
, name
, "StandardInputData=%s", encoded
);
2040 } else if (streq(name
, "Environment")) {
2042 _cleanup_strv_free_
char **l
= NULL
;
2044 r
= sd_bus_message_read_strv(message
, &l
);
2048 if (!strv_env_is_valid(l
))
2049 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment block.");
2051 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2052 if (strv_isempty(l
)) {
2053 c
->environment
= strv_free(c
->environment
);
2054 unit_write_setting(u
, flags
, name
, "Environment=");
2056 _cleanup_free_
char *joined
= NULL
;
2059 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
2063 e
= strv_env_merge(2, c
->environment
, l
);
2067 strv_free_and_replace(c
->environment
, e
);
2068 unit_write_settingf(u
, flags
, name
, "Environment=%s", joined
);
2074 } else if (streq(name
, "UnsetEnvironment")) {
2076 _cleanup_strv_free_
char **l
= NULL
;
2078 r
= sd_bus_message_read_strv(message
, &l
);
2082 if (!strv_env_name_or_assignment_is_valid(l
))
2083 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid UnsetEnvironment= list.");
2085 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2086 if (strv_isempty(l
)) {
2087 c
->unset_environment
= strv_free(c
->unset_environment
);
2088 unit_write_setting(u
, flags
, name
, "UnsetEnvironment=");
2090 _cleanup_free_
char *joined
= NULL
;
2093 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
2097 e
= strv_env_merge(2, c
->unset_environment
, l
);
2101 strv_free_and_replace(c
->unset_environment
, e
);
2102 unit_write_settingf(u
, flags
, name
, "UnsetEnvironment=%s", joined
);
2108 } else if (streq(name
, "OOMScoreAdjust")) {
2111 r
= sd_bus_message_read(message
, "i", &oa
);
2115 if (!oom_score_adjust_is_valid(oa
))
2116 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "OOM score adjust value out of range");
2118 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2119 c
->oom_score_adjust
= oa
;
2120 c
->oom_score_adjust_set
= true;
2121 unit_write_settingf(u
, flags
, name
, "OOMScoreAdjust=%i", oa
);
2126 } else if (streq(name
, "EnvironmentFiles")) {
2128 _cleanup_free_
char *joined
= NULL
;
2129 _cleanup_fclose_
FILE *f
= NULL
;
2130 _cleanup_strv_free_
char **l
= NULL
;
2134 r
= sd_bus_message_enter_container(message
, 'a', "(sb)");
2138 f
= open_memstream_unlocked(&joined
, &size
);
2142 fputs("EnvironmentFile=\n", f
);
2144 STRV_FOREACH(i
, c
->environment_files
) {
2145 _cleanup_free_
char *q
= NULL
;
2147 q
= specifier_escape(*i
);
2151 fprintf(f
, "EnvironmentFile=%s\n", q
);
2154 while ((r
= sd_bus_message_enter_container(message
, 'r', "sb")) > 0) {
2158 r
= sd_bus_message_read(message
, "sb", &path
, &b
);
2162 r
= sd_bus_message_exit_container(message
);
2166 if (!path_is_absolute(path
))
2167 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
2169 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2170 _cleanup_free_
char *q
= NULL
, *buf
= NULL
;
2172 buf
= strjoin(b
? "-" : "", path
);
2176 q
= specifier_escape(buf
);
2180 fprintf(f
, "EnvironmentFile=%s\n", q
);
2182 r
= strv_consume(&l
, TAKE_PTR(buf
));
2190 r
= sd_bus_message_exit_container(message
);
2194 r
= fflush_and_check(f
);
2198 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2199 if (strv_isempty(l
)) {
2200 c
->environment_files
= strv_free(c
->environment_files
);
2201 unit_write_setting(u
, flags
, name
, "EnvironmentFile=");
2203 r
= strv_extend_strv(&c
->environment_files
, l
, true);
2207 unit_write_setting(u
, flags
, name
, joined
);
2213 } else if (streq(name
, "PassEnvironment")) {
2215 _cleanup_strv_free_
char **l
= NULL
;
2217 r
= sd_bus_message_read_strv(message
, &l
);
2221 if (!strv_env_name_is_valid(l
))
2222 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PassEnvironment= block.");
2224 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2225 if (strv_isempty(l
)) {
2226 c
->pass_environment
= strv_free(c
->pass_environment
);
2227 unit_write_setting(u
, flags
, name
, "PassEnvironment=");
2229 _cleanup_free_
char *joined
= NULL
;
2231 r
= strv_extend_strv(&c
->pass_environment
, l
, true);
2235 /* We write just the new settings out to file, with unresolved specifiers. */
2236 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2240 unit_write_settingf(u
, flags
, name
, "PassEnvironment=%s", joined
);
2246 } else if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
2247 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) {
2248 _cleanup_strv_free_
char **l
= NULL
;
2252 r
= sd_bus_message_read_strv(message
, &l
);
2256 STRV_FOREACH(p
, l
) {
2260 offset
= i
[0] == '-';
2261 offset
+= i
[offset
] == '+';
2262 if (!path_is_absolute(i
+ offset
))
2263 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
2265 path_simplify(i
+ offset
, false);
2268 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2269 if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadWritePaths"))
2270 dirs
= &c
->read_write_paths
;
2271 else if (STR_IN_SET(name
, "ReadOnlyDirectories", "ReadOnlyPaths"))
2272 dirs
= &c
->read_only_paths
;
2273 else /* "InaccessiblePaths" */
2274 dirs
= &c
->inaccessible_paths
;
2276 if (strv_isempty(l
)) {
2277 *dirs
= strv_free(*dirs
);
2278 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2280 _cleanup_free_
char *joined
= NULL
;
2282 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2286 r
= strv_extend_strv(dirs
, l
, true);
2290 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2296 } else if (STR_IN_SET(name
, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
2297 _cleanup_strv_free_
char **l
= NULL
;
2300 r
= sd_bus_message_read_strv(message
, &l
);
2304 STRV_FOREACH(p
, l
) {
2305 if (!path_is_normalized(*p
))
2306 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is not normalized: %s", name
, *p
);
2308 if (path_is_absolute(*p
))
2309 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is absolute: %s", name
, *p
);
2311 if (path_startswith(*p
, "private"))
2312 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path can't be 'private': %s", name
, *p
);
2315 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2316 ExecDirectoryType i
;
2319 assert_se((i
= exec_directory_type_from_string(name
)) >= 0);
2320 d
= c
->directories
+ i
;
2322 if (strv_isempty(l
)) {
2323 d
->paths
= strv_free(d
->paths
);
2324 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2326 _cleanup_free_
char *joined
= NULL
;
2328 r
= strv_extend_strv(&d
->paths
, l
, true);
2332 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2336 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2342 } else if (STR_IN_SET(name
, "AppArmorProfile", "SmackProcessLabel")) {
2346 r
= sd_bus_message_read(message
, "(bs)", &ignore
, &s
);
2350 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2354 if (streq(name
, "AppArmorProfile")) {
2355 p
= &c
->apparmor_profile
;
2356 b
= &c
->apparmor_profile_ignore
;
2357 } else { /* "SmackProcessLabel" */
2358 p
= &c
->smack_process_label
;
2359 b
= &c
->smack_process_label_ignore
;
2366 if (free_and_strdup(p
, s
) < 0)
2371 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s%s", name
, ignore
? "-" : "", strempty(s
));
2376 } else if (STR_IN_SET(name
, "BindPaths", "BindReadOnlyPaths")) {
2377 const char *source
, *destination
;
2379 uint64_t mount_flags
;
2382 r
= sd_bus_message_enter_container(message
, 'a', "(ssbt)");
2386 while ((r
= sd_bus_message_read(message
, "(ssbt)", &source
, &destination
, &ignore_enoent
, &mount_flags
)) > 0) {
2388 if (!path_is_absolute(source
))
2389 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
2390 if (!path_is_absolute(destination
))
2391 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
2392 if (!IN_SET(mount_flags
, 0, MS_REC
))
2393 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount flags.");
2395 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2396 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
2398 .source
= strdup(source
),
2399 .destination
= strdup(destination
),
2400 .read_only
= !!strstr(name
, "ReadOnly"),
2401 .recursive
= !!(mount_flags
& MS_REC
),
2402 .ignore_enoent
= ignore_enoent
,
2407 unit_write_settingf(
2408 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2411 ignore_enoent
? "-" : "",
2414 (mount_flags
& MS_REC
) ? "rbind" : "norbind");
2422 r
= sd_bus_message_exit_container(message
);
2427 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
2428 c
->bind_mounts
= NULL
;
2429 c
->n_bind_mounts
= 0;
2431 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2436 } else if (streq(name
, "TemporaryFileSystem")) {
2437 const char *path
, *options
;
2440 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
2444 while ((r
= sd_bus_message_read(message
, "(ss)", &path
, &options
)) > 0) {
2446 if (!path_is_absolute(path
))
2447 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Mount point %s is not absolute.", path
);
2449 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2450 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, options
);
2454 unit_write_settingf(
2455 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2467 r
= sd_bus_message_exit_container(message
);
2472 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
2473 c
->temporary_filesystems
= NULL
;
2474 c
->n_temporary_filesystems
= 0;
2476 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2481 } else if ((suffix
= startswith(name
, "Limit"))) {
2482 const char *soft
= NULL
;
2485 ri
= rlimit_from_string(suffix
);
2487 soft
= endswith(suffix
, "Soft");
2491 n
= strndupa(suffix
, soft
- suffix
);
2492 ri
= rlimit_from_string(n
);
2494 name
= strjoina("Limit", n
);
2502 r
= sd_bus_message_read(message
, "t", &rl
);
2506 if (rl
== (uint64_t) -1)
2511 if ((uint64_t) x
!= rl
)
2515 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2516 _cleanup_free_
char *f
= NULL
;
2519 if (c
->rlimit
[ri
]) {
2520 nl
= *c
->rlimit
[ri
];
2527 /* When the resource limit is not initialized yet, then assign the value to both fields */
2528 nl
= (struct rlimit
) {
2533 r
= rlimit_format(&nl
, &f
);
2538 *c
->rlimit
[ri
] = nl
;
2540 c
->rlimit
[ri
] = newdup(struct rlimit
, &nl
, 1);
2545 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, f
);