1 /* SPDX-License-Identifier: LGPL-2.1+ */
12 #include "alloc-util.h"
15 #include "capability-util.h"
16 #include "cpu-set-util.h"
17 #include "dbus-execute.h"
18 #include "dbus-util.h"
20 #include "errno-list.h"
25 #include "hexdecoct.h"
28 #include "journal-util.h"
30 #include "mount-util.h"
31 #include "namespace.h"
32 #include "parse-util.h"
33 #include "path-util.h"
34 #include "process-util.h"
35 #include "rlimit-util.h"
37 #include "seccomp-util.h"
39 #include "securebits-util.h"
40 #include "specifier.h"
42 #include "syslog-util.h"
43 #include "unit-printf.h"
44 #include "user-util.h"
47 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output
, exec_output
, ExecOutput
);
48 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input
, exec_input
, ExecInput
);
49 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
);
50 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
);
51 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
);
52 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home
, protect_home
, ProtectHome
);
53 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system
, protect_system
, ProtectSystem
);
54 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality
, personality
, unsigned long);
55 static BUS_DEFINE_PROPERTY_GET(property_get_ioprio
, "i", ExecContext
, exec_context_get_effective_ioprio
);
56 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class
, "i", ExecContext
, exec_context_get_effective_ioprio
, IOPRIO_PRIO_CLASS
);
57 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority
, "i", ExecContext
, exec_context_get_effective_ioprio
, IOPRIO_PRIO_DATA
);
58 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string
, "s", NULL
);
59 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level
, "i", int, LOG_PRI
);
60 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility
, "i", int, LOG_FAC
);
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
;
110 if (c
->oom_score_adjust_set
)
111 n
= c
->oom_score_adjust
;
113 _cleanup_free_
char *t
= NULL
;
116 if (read_one_line_file("/proc/self/oom_score_adj", &t
) >= 0)
120 return sd_bus_message_append(reply
, "i", n
);
123 static int property_get_nice(
126 const char *interface
,
127 const char *property
,
128 sd_bus_message
*reply
,
130 sd_bus_error
*error
) {
132 ExecContext
*c
= userdata
;
143 n
= getpriority(PRIO_PROCESS
, 0);
148 return sd_bus_message_append(reply
, "i", n
);
151 static int property_get_cpu_sched_policy(
154 const char *interface
,
155 const char *property
,
156 sd_bus_message
*reply
,
158 sd_bus_error
*error
) {
160 ExecContext
*c
= userdata
;
167 if (c
->cpu_sched_set
)
168 n
= c
->cpu_sched_policy
;
170 n
= sched_getscheduler(0);
175 return sd_bus_message_append(reply
, "i", n
);
178 static int property_get_cpu_sched_priority(
181 const char *interface
,
182 const char *property
,
183 sd_bus_message
*reply
,
185 sd_bus_error
*error
) {
187 ExecContext
*c
= userdata
;
194 if (c
->cpu_sched_set
)
195 n
= c
->cpu_sched_priority
;
197 struct sched_param p
= {};
199 if (sched_getparam(0, &p
) >= 0)
200 n
= p
.sched_priority
;
205 return sd_bus_message_append(reply
, "i", n
);
208 static int property_get_cpu_affinity(
211 const char *interface
,
212 const char *property
,
213 sd_bus_message
*reply
,
215 sd_bus_error
*error
) {
217 ExecContext
*c
= userdata
;
223 return sd_bus_message_append_array(reply
, 'y', c
->cpuset
, CPU_ALLOC_SIZE(c
->cpuset_ncpus
));
226 static int property_get_timer_slack_nsec(
229 const char *interface
,
230 const char *property
,
231 sd_bus_message
*reply
,
233 sd_bus_error
*error
) {
235 ExecContext
*c
= userdata
;
242 if (c
->timer_slack_nsec
!= NSEC_INFINITY
)
243 u
= (uint64_t) c
->timer_slack_nsec
;
245 u
= (uint64_t) prctl(PR_GET_TIMERSLACK
);
247 return sd_bus_message_append(reply
, "t", u
);
250 static int property_get_syscall_filter(
253 const char *interface
,
254 const char *property
,
255 sd_bus_message
*reply
,
257 sd_bus_error
*error
) {
259 ExecContext
*c
= userdata
;
260 _cleanup_strv_free_
char **l
= NULL
;
272 r
= sd_bus_message_open_container(reply
, 'r', "bas");
276 r
= sd_bus_message_append(reply
, "b", c
->syscall_whitelist
);
281 HASHMAP_FOREACH_KEY(val
, id
, c
->syscall_filter
, i
) {
282 _cleanup_free_
char *name
= NULL
;
283 const char *e
= NULL
;
285 int num
= PTR_TO_INT(val
);
287 name
= seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE
, PTR_TO_INT(id
) - 1);
292 e
= errno_to_name(num
);
294 s
= strjoin(name
, ":", e
);
298 r
= asprintf(&s
, "%s:%d", name
, num
);
305 r
= strv_consume(&l
, s
);
313 r
= sd_bus_message_append_strv(reply
, l
);
317 return sd_bus_message_close_container(reply
);
320 static int property_get_syscall_archs(
323 const char *interface
,
324 const char *property
,
325 sd_bus_message
*reply
,
327 sd_bus_error
*error
) {
329 ExecContext
*c
= userdata
;
330 _cleanup_strv_free_
char **l
= NULL
;
343 SET_FOREACH(id
, c
->syscall_archs
, i
) {
346 name
= seccomp_arch_to_string(PTR_TO_UINT32(id
) - 1);
350 r
= strv_extend(&l
, name
);
358 r
= sd_bus_message_append_strv(reply
, l
);
365 static int property_get_selinux_context(
368 const char *interface
,
369 const char *property
,
370 sd_bus_message
*reply
,
372 sd_bus_error
*error
) {
374 ExecContext
*c
= userdata
;
380 return sd_bus_message_append(reply
, "(bs)", c
->selinux_context_ignore
, c
->selinux_context
);
383 static int property_get_apparmor_profile(
386 const char *interface
,
387 const char *property
,
388 sd_bus_message
*reply
,
390 sd_bus_error
*error
) {
392 ExecContext
*c
= userdata
;
398 return sd_bus_message_append(reply
, "(bs)", c
->apparmor_profile_ignore
, c
->apparmor_profile
);
401 static int property_get_smack_process_label(
404 const char *interface
,
405 const char *property
,
406 sd_bus_message
*reply
,
408 sd_bus_error
*error
) {
410 ExecContext
*c
= userdata
;
416 return sd_bus_message_append(reply
, "(bs)", c
->smack_process_label_ignore
, c
->smack_process_label
);
419 static int property_get_address_families(
422 const char *interface
,
423 const char *property
,
424 sd_bus_message
*reply
,
426 sd_bus_error
*error
) {
428 ExecContext
*c
= userdata
;
429 _cleanup_strv_free_
char **l
= NULL
;
438 r
= sd_bus_message_open_container(reply
, 'r', "bas");
442 r
= sd_bus_message_append(reply
, "b", c
->address_families_whitelist
);
446 SET_FOREACH(af
, c
->address_families
, i
) {
449 name
= af_to_name(PTR_TO_INT(af
));
453 r
= strv_extend(&l
, name
);
460 r
= sd_bus_message_append_strv(reply
, l
);
464 return sd_bus_message_close_container(reply
);
467 static int property_get_working_directory(
470 const char *interface
,
471 const char *property
,
472 sd_bus_message
*reply
,
474 sd_bus_error
*error
) {
476 ExecContext
*c
= userdata
;
483 if (c
->working_directory_home
)
486 wd
= c
->working_directory
;
488 if (c
->working_directory_missing_ok
)
489 wd
= strjoina("!", wd
);
491 return sd_bus_message_append(reply
, "s", wd
);
494 static int property_get_stdio_fdname(
497 const char *interface
,
498 const char *property
,
499 sd_bus_message
*reply
,
501 sd_bus_error
*error
) {
503 ExecContext
*c
= userdata
;
511 if (streq(property
, "StandardInputFileDescriptorName"))
512 fileno
= STDIN_FILENO
;
513 else if (streq(property
, "StandardOutputFileDescriptorName"))
514 fileno
= STDOUT_FILENO
;
516 assert(streq(property
, "StandardErrorFileDescriptorName"));
517 fileno
= STDERR_FILENO
;
520 return sd_bus_message_append(reply
, "s", exec_context_fdname(c
, fileno
));
523 static int property_get_input_data(
526 const char *interface
,
527 const char *property
,
528 sd_bus_message
*reply
,
530 sd_bus_error
*error
) {
532 ExecContext
*c
= userdata
;
539 return sd_bus_message_append_array(reply
, 'y', c
->stdin_data
, c
->stdin_data_size
);
542 static int property_get_bind_paths(
545 const char *interface
,
546 const char *property
,
547 sd_bus_message
*reply
,
549 sd_bus_error
*error
) {
551 ExecContext
*c
= userdata
;
561 ro
= strstr(property
, "ReadOnly");
563 r
= sd_bus_message_open_container(reply
, 'a', "(ssbt)");
567 for (i
= 0; i
< c
->n_bind_mounts
; i
++) {
569 if (ro
!= c
->bind_mounts
[i
].read_only
)
572 r
= sd_bus_message_append(
574 c
->bind_mounts
[i
].source
,
575 c
->bind_mounts
[i
].destination
,
576 c
->bind_mounts
[i
].ignore_enoent
,
577 c
->bind_mounts
[i
].recursive
? (uint64_t) MS_REC
: (uint64_t) 0);
582 return sd_bus_message_close_container(reply
);
585 static int property_get_temporary_filesystems(
588 const char *interface
,
589 const char *property
,
590 sd_bus_message
*reply
,
592 sd_bus_error
*error
) {
594 ExecContext
*c
= userdata
;
603 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
607 for (i
= 0; i
< c
->n_temporary_filesystems
; i
++) {
608 TemporaryFileSystem
*t
= c
->temporary_filesystems
+ i
;
610 r
= sd_bus_message_append(
618 return sd_bus_message_close_container(reply
);
621 static int property_get_log_extra_fields(
624 const char *interface
,
625 const char *property
,
626 sd_bus_message
*reply
,
628 sd_bus_error
*error
) {
630 ExecContext
*c
= userdata
;
639 r
= sd_bus_message_open_container(reply
, 'a', "ay");
643 for (i
= 0; i
< c
->n_log_extra_fields
; i
++) {
644 r
= sd_bus_message_append_array(reply
, 'y', c
->log_extra_fields
[i
].iov_base
, c
->log_extra_fields
[i
].iov_len
);
649 return sd_bus_message_close_container(reply
);
652 const sd_bus_vtable bus_exec_vtable
[] = {
653 SD_BUS_VTABLE_START(0),
654 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(ExecContext
, environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
655 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
656 SD_BUS_PROPERTY("PassEnvironment", "as", NULL
, offsetof(ExecContext
, pass_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
657 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL
, offsetof(ExecContext
, unset_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
658 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode
, offsetof(ExecContext
, umask
), SD_BUS_VTABLE_PROPERTY_CONST
),
659 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
660 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
661 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
662 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
663 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
664 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
665 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
666 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
667 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
668 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
669 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
670 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
671 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
672 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
673 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
674 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
675 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
676 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
677 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
678 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
679 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
680 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
681 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
682 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
683 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
684 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
685 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
686 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
687 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
688 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
689 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
690 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
691 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
692 SD_BUS_PROPERTY("RootDirectory", "s", NULL
, offsetof(ExecContext
, root_directory
), SD_BUS_VTABLE_PROPERTY_CONST
),
693 SD_BUS_PROPERTY("RootImage", "s", NULL
, offsetof(ExecContext
, root_image
), SD_BUS_VTABLE_PROPERTY_CONST
),
694 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
695 SD_BUS_PROPERTY("Nice", "i", property_get_nice
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
696 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
697 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
698 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
699 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
700 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
701 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
702 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool
, offsetof(ExecContext
, cpu_sched_reset_on_fork
), SD_BUS_VTABLE_PROPERTY_CONST
),
703 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool
, offsetof(ExecContext
, non_blocking
), SD_BUS_VTABLE_PROPERTY_CONST
),
704 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input
, offsetof(ExecContext
, std_input
), SD_BUS_VTABLE_PROPERTY_CONST
),
705 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
706 SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
707 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
708 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
709 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_error
), SD_BUS_VTABLE_PROPERTY_CONST
),
710 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
711 SD_BUS_PROPERTY("TTYPath", "s", NULL
, offsetof(ExecContext
, tty_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
712 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_reset
), SD_BUS_VTABLE_PROPERTY_CONST
),
713 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vhangup
), SD_BUS_VTABLE_PROPERTY_CONST
),
714 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vt_disallocate
), SD_BUS_VTABLE_PROPERTY_CONST
),
715 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
716 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL
, offsetof(ExecContext
, syslog_identifier
), SD_BUS_VTABLE_PROPERTY_CONST
),
717 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool
, offsetof(ExecContext
, syslog_level_prefix
), SD_BUS_VTABLE_PROPERTY_CONST
),
718 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
719 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
720 SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int
, offsetof(ExecContext
, log_level_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
721 SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
722 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int
, offsetof(ExecContext
, secure_bits
), SD_BUS_VTABLE_PROPERTY_CONST
),
723 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL
, offsetof(ExecContext
, capability_bounding_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
724 SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL
, offsetof(ExecContext
, capability_ambient_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
725 SD_BUS_PROPERTY("User", "s", NULL
, offsetof(ExecContext
, user
), SD_BUS_VTABLE_PROPERTY_CONST
),
726 SD_BUS_PROPERTY("Group", "s", NULL
, offsetof(ExecContext
, group
), SD_BUS_VTABLE_PROPERTY_CONST
),
727 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool
, offsetof(ExecContext
, dynamic_user
), SD_BUS_VTABLE_PROPERTY_CONST
),
728 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, remove_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
729 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL
, offsetof(ExecContext
, supplementary_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
730 SD_BUS_PROPERTY("PAMName", "s", NULL
, offsetof(ExecContext
, pam_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
731 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
732 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
733 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
734 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong
, offsetof(ExecContext
, mount_flags
), SD_BUS_VTABLE_PROPERTY_CONST
),
735 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool
, offsetof(ExecContext
, private_tmp
), SD_BUS_VTABLE_PROPERTY_CONST
),
736 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool
, offsetof(ExecContext
, private_devices
), SD_BUS_VTABLE_PROPERTY_CONST
),
737 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_tunables
), SD_BUS_VTABLE_PROPERTY_CONST
),
738 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_modules
), SD_BUS_VTABLE_PROPERTY_CONST
),
739 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_control_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
740 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool
, offsetof(ExecContext
, private_network
), SD_BUS_VTABLE_PROPERTY_CONST
),
741 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool
, offsetof(ExecContext
, private_users
), SD_BUS_VTABLE_PROPERTY_CONST
),
742 SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_bool
, offsetof(ExecContext
, private_mounts
), SD_BUS_VTABLE_PROPERTY_CONST
),
743 SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home
, offsetof(ExecContext
, protect_home
), SD_BUS_VTABLE_PROPERTY_CONST
),
744 SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system
, offsetof(ExecContext
, protect_system
), SD_BUS_VTABLE_PROPERTY_CONST
),
745 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool
, offsetof(ExecContext
, same_pgrp
), SD_BUS_VTABLE_PROPERTY_CONST
),
746 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL
, offsetof(ExecContext
, utmp_id
), SD_BUS_VTABLE_PROPERTY_CONST
),
747 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode
, offsetof(ExecContext
, utmp_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
748 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
749 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
750 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
751 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool
, offsetof(ExecContext
, ignore_sigpipe
), SD_BUS_VTABLE_PROPERTY_CONST
),
752 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool
, offsetof(ExecContext
, no_new_privileges
), SD_BUS_VTABLE_PROPERTY_CONST
),
753 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
754 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
755 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int
, offsetof(ExecContext
, syscall_errno
), SD_BUS_VTABLE_PROPERTY_CONST
),
756 SD_BUS_PROPERTY("Personality", "s", property_get_personality
, offsetof(ExecContext
, personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
757 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool
, offsetof(ExecContext
, lock_personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
758 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
759 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode
, offsetof(ExecContext
, runtime_directory_preserve_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
760 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
761 SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
762 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
763 SD_BUS_PROPERTY("StateDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
764 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
765 SD_BUS_PROPERTY("CacheDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
766 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
767 SD_BUS_PROPERTY("LogsDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
768 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
769 SD_BUS_PROPERTY("ConfigurationDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
770 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool
, offsetof(ExecContext
, memory_deny_write_execute
), SD_BUS_VTABLE_PROPERTY_CONST
),
771 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_realtime
), SD_BUS_VTABLE_PROPERTY_CONST
),
772 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong
, offsetof(ExecContext
, restrict_namespaces
), SD_BUS_VTABLE_PROPERTY_CONST
),
773 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
774 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
775 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
776 SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool
, offsetof(ExecContext
, mount_apivfs
), SD_BUS_VTABLE_PROPERTY_CONST
),
777 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode
, offsetof(ExecContext
, keyring_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
779 /* Obsolete/redundant properties: */
780 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
781 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
782 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
783 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
784 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
789 static int append_exec_command(sd_bus_message
*reply
, ExecCommand
*c
) {
798 r
= sd_bus_message_open_container(reply
, 'r', "sasbttttuii");
802 r
= sd_bus_message_append(reply
, "s", c
->path
);
806 r
= sd_bus_message_append_strv(reply
, c
->argv
);
810 r
= sd_bus_message_append(reply
, "bttttuii",
811 !!(c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
),
812 c
->exec_status
.start_timestamp
.realtime
,
813 c
->exec_status
.start_timestamp
.monotonic
,
814 c
->exec_status
.exit_timestamp
.realtime
,
815 c
->exec_status
.exit_timestamp
.monotonic
,
816 (uint32_t) c
->exec_status
.pid
,
817 (int32_t) c
->exec_status
.code
,
818 (int32_t) c
->exec_status
.status
);
822 return sd_bus_message_close_container(reply
);
825 int bus_property_get_exec_command(
828 const char *interface
,
829 const char *property
,
830 sd_bus_message
*reply
,
832 sd_bus_error
*ret_error
) {
834 ExecCommand
*c
= (ExecCommand
*) userdata
;
840 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
844 r
= append_exec_command(reply
, c
);
848 return sd_bus_message_close_container(reply
);
851 int bus_property_get_exec_command_list(
854 const char *interface
,
855 const char *property
,
856 sd_bus_message
*reply
,
858 sd_bus_error
*ret_error
) {
860 ExecCommand
*c
= *(ExecCommand
**) userdata
;
866 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
870 LIST_FOREACH(command
, c
, c
) {
871 r
= append_exec_command(reply
, c
);
876 return sd_bus_message_close_container(reply
);
879 int bus_set_transient_exec_command(
882 ExecCommand
**exec_command
,
883 sd_bus_message
*message
,
884 UnitWriteFlags flags
,
885 sd_bus_error
*error
) {
889 r
= sd_bus_message_enter_container(message
, 'a', "(sasb)");
893 while ((r
= sd_bus_message_enter_container(message
, 'r', "sasb")) > 0) {
894 _cleanup_strv_free_
char **argv
= NULL
;
898 r
= sd_bus_message_read(message
, "s", &path
);
902 if (!path_is_absolute(path
))
903 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
905 r
= sd_bus_message_read_strv(message
, &argv
);
909 r
= sd_bus_message_read(message
, "b", &b
);
913 r
= sd_bus_message_exit_container(message
);
917 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
920 c
= new0(ExecCommand
, 1);
924 c
->path
= strdup(path
);
930 c
->argv
= TAKE_PTR(argv
);
932 c
->flags
= b
? EXEC_COMMAND_IGNORE_FAILURE
: 0;
934 path_simplify(c
->path
, false);
935 exec_command_append_list(exec_command
, c
);
943 r
= sd_bus_message_exit_container(message
);
947 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
948 _cleanup_free_
char *buf
= NULL
;
949 _cleanup_fclose_
FILE *f
= NULL
;
954 *exec_command
= exec_command_free_list(*exec_command
);
956 f
= open_memstream(&buf
, &size
);
960 (void) __fsetlocking(f
, FSETLOCKING_BYCALLER
);
962 fputs("ExecStart=\n", f
);
964 LIST_FOREACH(command
, c
, *exec_command
) {
965 _cleanup_free_
char *a
= NULL
, *t
= NULL
;
968 p
= unit_escape_setting(c
->path
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
, &t
);
972 a
= unit_concat_strv(c
->argv
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
);
976 fprintf(f
, "%s=%s@%s %s\n",
978 c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
? "-" : "",
983 r
= fflush_and_check(f
);
987 unit_write_setting(u
, flags
, name
, buf
);
993 static int parse_personality(const char *s
, unsigned long *p
) {
998 v
= personality_from_string(s
);
999 if (v
== PERSONALITY_INVALID
)
1006 static const char* mount_propagation_flags_to_string_with_check(unsigned long n
) {
1007 if (!IN_SET(n
, 0, MS_SHARED
, MS_PRIVATE
, MS_SLAVE
))
1010 return mount_propagation_flags_to_string(n
);
1013 static BUS_DEFINE_SET_TRANSIENT(nsec
, "t", uint64_t, nsec_t
, NSEC_FMT
);
1014 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level
, "i", int32_t, int, "%" PRIi32
, log_level_is_valid
);
1016 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno
, "i", int32_t, int, "%" PRIi32
, errno_is_valid
);
1018 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input
, ExecInput
, exec_input_from_string
);
1019 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output
, ExecOutput
, exec_output_from_string
);
1020 static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode
, ExecUtmpMode
, exec_utmp_mode_from_string
);
1021 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system
, ProtectSystem
, protect_system_from_string
);
1022 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home
, ProtectHome
, protect_home_from_string
);
1023 static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode
, ExecKeyringMode
, exec_keyring_mode_from_string
);
1024 static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode
, ExecPreserveMode
, exec_preserve_mode_from_string
);
1025 static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality
, unsigned long, parse_personality
);
1026 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits
, "i", int32_t, int, "%" PRIi32
, secure_bits_to_string_alloc_with_check
);
1027 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability
, "t", uint64_t, uint64_t, "%" PRIu64
, capability_set_to_string_alloc
);
1028 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag
, "t", uint64_t, unsigned long, "%" PRIu64
, namespace_flags_to_string
);
1029 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags
, "t", uint64_t, unsigned long, "%" PRIu64
, mount_propagation_flags_to_string_with_check
);
1031 int bus_exec_context_set_transient_property(
1035 sd_bus_message
*message
,
1036 UnitWriteFlags flags
,
1037 sd_bus_error
*error
) {
1047 flags
|= UNIT_PRIVATE
;
1049 if (streq(name
, "User"))
1050 return bus_set_transient_user(u
, name
, &c
->user
, message
, flags
, error
);
1052 if (streq(name
, "Group"))
1053 return bus_set_transient_user(u
, name
, &c
->group
, message
, flags
, error
);
1055 if (streq(name
, "TTYPath"))
1056 return bus_set_transient_path(u
, name
, &c
->tty_path
, message
, flags
, error
);
1058 if (streq(name
, "RootImage"))
1059 return bus_set_transient_path(u
, name
, &c
->root_image
, message
, flags
, error
);
1061 if (streq(name
, "RootDirectory"))
1062 return bus_set_transient_path(u
, name
, &c
->root_directory
, message
, flags
, error
);
1064 if (streq(name
, "SyslogIdentifier"))
1065 return bus_set_transient_string(u
, name
, &c
->syslog_identifier
, message
, flags
, error
);
1067 if (streq(name
, "LogLevelMax"))
1068 return bus_set_transient_log_level(u
, name
, &c
->log_level_max
, message
, flags
, error
);
1070 if (streq(name
, "Personality"))
1071 return bus_set_transient_personality(u
, name
, &c
->personality
, message
, flags
, error
);
1073 if (streq(name
, "StandardInput"))
1074 return bus_set_transient_std_input(u
, name
, &c
->std_input
, message
, flags
, error
);
1076 if (streq(name
, "StandardOutput"))
1077 return bus_set_transient_std_output(u
, name
, &c
->std_output
, message
, flags
, error
);
1079 if (streq(name
, "StandardError"))
1080 return bus_set_transient_std_output(u
, name
, &c
->std_error
, message
, flags
, error
);
1082 if (streq(name
, "IgnoreSIGPIPE"))
1083 return bus_set_transient_bool(u
, name
, &c
->ignore_sigpipe
, message
, flags
, error
);
1085 if (streq(name
, "TTYVHangup"))
1086 return bus_set_transient_bool(u
, name
, &c
->tty_vhangup
, message
, flags
, error
);
1088 if (streq(name
, "TTYReset"))
1089 return bus_set_transient_bool(u
, name
, &c
->tty_reset
, message
, flags
, error
);
1091 if (streq(name
, "TTYVTDisallocate"))
1092 return bus_set_transient_bool(u
, name
, &c
->tty_vt_disallocate
, message
, flags
, error
);
1094 if (streq(name
, "PrivateTmp"))
1095 return bus_set_transient_bool(u
, name
, &c
->private_tmp
, message
, flags
, error
);
1097 if (streq(name
, "PrivateDevices"))
1098 return bus_set_transient_bool(u
, name
, &c
->private_devices
, message
, flags
, error
);
1100 if (streq(name
, "PrivateMounts"))
1101 return bus_set_transient_bool(u
, name
, &c
->private_mounts
, message
, flags
, error
);
1103 if (streq(name
, "PrivateNetwork"))
1104 return bus_set_transient_bool(u
, name
, &c
->private_network
, message
, flags
, error
);
1106 if (streq(name
, "PrivateUsers"))
1107 return bus_set_transient_bool(u
, name
, &c
->private_users
, message
, flags
, error
);
1109 if (streq(name
, "NoNewPrivileges"))
1110 return bus_set_transient_bool(u
, name
, &c
->no_new_privileges
, message
, flags
, error
);
1112 if (streq(name
, "SyslogLevelPrefix"))
1113 return bus_set_transient_bool(u
, name
, &c
->syslog_level_prefix
, message
, flags
, error
);
1115 if (streq(name
, "MemoryDenyWriteExecute"))
1116 return bus_set_transient_bool(u
, name
, &c
->memory_deny_write_execute
, message
, flags
, error
);
1118 if (streq(name
, "RestrictRealtime"))
1119 return bus_set_transient_bool(u
, name
, &c
->restrict_realtime
, message
, flags
, error
);
1121 if (streq(name
, "DynamicUser"))
1122 return bus_set_transient_bool(u
, name
, &c
->dynamic_user
, message
, flags
, error
);
1124 if (streq(name
, "RemoveIPC"))
1125 return bus_set_transient_bool(u
, name
, &c
->remove_ipc
, message
, flags
, error
);
1127 if (streq(name
, "ProtectKernelTunables"))
1128 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_tunables
, message
, flags
, error
);
1130 if (streq(name
, "ProtectKernelModules"))
1131 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_modules
, message
, flags
, error
);
1133 if (streq(name
, "ProtectControlGroups"))
1134 return bus_set_transient_bool(u
, name
, &c
->protect_control_groups
, message
, flags
, error
);
1136 if (streq(name
, "MountAPIVFS"))
1137 return bus_set_transient_bool(u
, name
, &c
->mount_apivfs
, message
, flags
, error
);
1139 if (streq(name
, "CPUSchedulingResetOnFork"))
1140 return bus_set_transient_bool(u
, name
, &c
->cpu_sched_reset_on_fork
, message
, flags
, error
);
1142 if (streq(name
, "NonBlocking"))
1143 return bus_set_transient_bool(u
, name
, &c
->non_blocking
, message
, flags
, error
);
1145 if (streq(name
, "LockPersonality"))
1146 return bus_set_transient_bool(u
, name
, &c
->lock_personality
, message
, flags
, error
);
1148 if (streq(name
, "UtmpIdentifier"))
1149 return bus_set_transient_string(u
, name
, &c
->utmp_id
, message
, flags
, error
);
1151 if (streq(name
, "UtmpMode"))
1152 return bus_set_transient_utmp_mode(u
, name
, &c
->utmp_mode
, message
, flags
, error
);
1154 if (streq(name
, "PAMName"))
1155 return bus_set_transient_string(u
, name
, &c
->pam_name
, message
, flags
, error
);
1157 if (streq(name
, "TimerSlackNSec"))
1158 return bus_set_transient_nsec(u
, name
, &c
->timer_slack_nsec
, message
, flags
, error
);
1160 if (streq(name
, "ProtectSystem"))
1161 return bus_set_transient_protect_system(u
, name
, &c
->protect_system
, message
, flags
, error
);
1163 if (streq(name
, "ProtectHome"))
1164 return bus_set_transient_protect_home(u
, name
, &c
->protect_home
, message
, flags
, error
);
1166 if (streq(name
, "KeyringMode"))
1167 return bus_set_transient_keyring_mode(u
, name
, &c
->keyring_mode
, message
, flags
, error
);
1169 if (streq(name
, "RuntimeDirectoryPreserve"))
1170 return bus_set_transient_preserve_mode(u
, name
, &c
->runtime_directory_preserve_mode
, message
, flags
, error
);
1172 if (streq(name
, "UMask"))
1173 return bus_set_transient_mode_t(u
, name
, &c
->umask
, message
, flags
, error
);
1175 if (streq(name
, "RuntimeDirectoryMode"))
1176 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_RUNTIME
].mode
, message
, flags
, error
);
1178 if (streq(name
, "StateDirectoryMode"))
1179 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_STATE
].mode
, message
, flags
, error
);
1181 if (streq(name
, "CacheDirectoryMode"))
1182 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CACHE
].mode
, message
, flags
, error
);
1184 if (streq(name
, "LogsDirectoryMode"))
1185 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_LOGS
].mode
, message
, flags
, error
);
1187 if (streq(name
, "ConfigurationDirectoryMode"))
1188 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
, message
, flags
, error
);
1190 if (streq(name
, "SELinuxContext"))
1191 return bus_set_transient_string(u
, name
, &c
->selinux_context
, message
, flags
, error
);
1193 if (streq(name
, "SecureBits"))
1194 return bus_set_transient_secure_bits(u
, name
, &c
->secure_bits
, message
, flags
, error
);
1196 if (streq(name
, "CapabilityBoundingSet"))
1197 return bus_set_transient_capability(u
, name
, &c
->capability_bounding_set
, message
, flags
, error
);
1199 if (streq(name
, "AmbientCapabilities"))
1200 return bus_set_transient_capability(u
, name
, &c
->capability_ambient_set
, message
, flags
, error
);
1202 if (streq(name
, "RestrictNamespaces"))
1203 return bus_set_transient_namespace_flag(u
, name
, &c
->restrict_namespaces
, message
, flags
, error
);
1205 if (streq(name
, "MountFlags"))
1206 return bus_set_transient_mount_flags(u
, name
, &c
->mount_flags
, message
, flags
, error
);
1208 if (streq(name
, "SupplementaryGroups")) {
1209 _cleanup_strv_free_
char **l
= NULL
;
1212 r
= sd_bus_message_read_strv(message
, &l
);
1216 STRV_FOREACH(p
, l
) {
1217 if (!isempty(*p
) && !valid_user_group_name_or_id(*p
))
1218 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid supplementary group names");
1221 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1222 if (strv_isempty(l
)) {
1223 c
->supplementary_groups
= strv_free(c
->supplementary_groups
);
1224 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1226 _cleanup_free_
char *joined
= NULL
;
1228 r
= strv_extend_strv(&c
->supplementary_groups
, l
, true);
1232 joined
= strv_join(c
->supplementary_groups
, " ");
1236 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s", name
, joined
);
1242 } else if (streq(name
, "SyslogLevel")) {
1245 r
= sd_bus_message_read(message
, "i", &level
);
1249 if (!log_level_is_valid(level
))
1250 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log level value out of range");
1252 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1253 c
->syslog_priority
= (c
->syslog_priority
& LOG_FACMASK
) | level
;
1254 unit_write_settingf(u
, flags
, name
, "SyslogLevel=%i", level
);
1259 } else if (streq(name
, "SyslogFacility")) {
1262 r
= sd_bus_message_read(message
, "i", &facility
);
1266 if (!log_facility_unshifted_is_valid(facility
))
1267 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log facility value out of range");
1269 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1270 c
->syslog_priority
= (facility
<< 3) | LOG_PRI(c
->syslog_priority
);
1271 unit_write_settingf(u
, flags
, name
, "SyslogFacility=%i", facility
);
1276 } else if (streq(name
, "LogExtraFields")) {
1279 r
= sd_bus_message_enter_container(message
, 'a', "ay");
1284 _cleanup_free_
void *copy
= NULL
;
1290 /* Note that we expect a byte array for each field, instead of a string. That's because on the
1291 * lower-level journal fields can actually contain binary data and are not restricted to text,
1292 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
1293 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
1294 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
1295 * limitation, should a good, valid usecase arise. */
1297 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
1303 if (memchr(p
, 0, sz
))
1304 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains zero byte");
1306 eq
= memchr(p
, '=', sz
);
1308 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains no '=' character");
1309 if (!journal_field_valid(p
, eq
- (const char*) p
, false))
1310 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field invalid");
1312 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1313 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
1316 c
->log_extra_fields
= t
;
1319 copy
= malloc(sz
+ 1);
1323 memcpy(copy
, p
, sz
);
1324 ((uint8_t*) copy
)[sz
] = 0;
1326 if (!utf8_is_valid(copy
))
1327 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field is not valid UTF-8");
1329 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1330 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE(copy
, sz
);
1331 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
, name
, "LogExtraFields=%s", (char*) copy
);
1339 r
= sd_bus_message_exit_container(message
);
1343 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && n
== 0) {
1344 exec_context_free_log_extra_fields(c
);
1345 unit_write_setting(u
, flags
, name
, "LogExtraFields=");
1353 if (streq(name
, "SystemCallErrorNumber"))
1354 return bus_set_transient_errno(u
, name
, &c
->syscall_errno
, message
, flags
, error
);
1356 if (streq(name
, "SystemCallFilter")) {
1358 _cleanup_strv_free_
char **l
= NULL
;
1360 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1364 r
= sd_bus_message_read(message
, "b", &whitelist
);
1368 r
= sd_bus_message_read_strv(message
, &l
);
1372 r
= sd_bus_message_exit_container(message
);
1376 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1377 _cleanup_free_
char *joined
= NULL
;
1378 bool invert
= !whitelist
;
1381 if (strv_isempty(l
)) {
1382 c
->syscall_whitelist
= false;
1383 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
1385 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=");
1389 if (!c
->syscall_filter
) {
1390 c
->syscall_filter
= hashmap_new(NULL
);
1391 if (!c
->syscall_filter
)
1394 c
->syscall_whitelist
= whitelist
;
1396 if (c
->syscall_whitelist
) {
1397 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
| (invert
? SECCOMP_PARSE_INVERT
: 0));
1403 STRV_FOREACH(s
, l
) {
1404 _cleanup_free_
char *n
= NULL
;
1407 r
= parse_syscall_and_errno(*s
, &n
, &e
);
1411 r
= seccomp_parse_syscall_filter(n
, e
, c
->syscall_filter
, (invert
? SECCOMP_PARSE_INVERT
: 0) | (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0));
1416 joined
= strv_join(l
, " ");
1420 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=%s%s", whitelist
? "" : "~", joined
);
1425 } else if (streq(name
, "SystemCallArchitectures")) {
1426 _cleanup_strv_free_
char **l
= NULL
;
1428 r
= sd_bus_message_read_strv(message
, &l
);
1432 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1433 _cleanup_free_
char *joined
= NULL
;
1435 if (strv_isempty(l
))
1436 c
->syscall_archs
= set_free(c
->syscall_archs
);
1440 r
= set_ensure_allocated(&c
->syscall_archs
, NULL
);
1444 STRV_FOREACH(s
, l
) {
1447 r
= seccomp_arch_from_string(*s
, &a
);
1451 r
= set_put(c
->syscall_archs
, UINT32_TO_PTR(a
+ 1));
1458 joined
= strv_join(l
, " ");
1462 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
1467 } else if (streq(name
, "RestrictAddressFamilies")) {
1469 _cleanup_strv_free_
char **l
= NULL
;
1471 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1475 r
= sd_bus_message_read(message
, "b", &whitelist
);
1479 r
= sd_bus_message_read_strv(message
, &l
);
1483 r
= sd_bus_message_exit_container(message
);
1487 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1488 _cleanup_free_
char *joined
= NULL
;
1489 bool invert
= !whitelist
;
1492 if (strv_isempty(l
)) {
1493 c
->address_families_whitelist
= false;
1494 c
->address_families
= set_free(c
->address_families
);
1496 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=");
1500 if (!c
->address_families
) {
1501 c
->address_families
= set_new(NULL
);
1502 if (!c
->address_families
)
1505 c
->address_families_whitelist
= whitelist
;
1508 STRV_FOREACH(s
, l
) {
1511 af
= af_from_name(*s
);
1515 if (!invert
== c
->address_families_whitelist
) {
1516 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
1520 (void) set_remove(c
->address_families
, INT_TO_PTR(af
));
1523 joined
= strv_join(l
, " ");
1527 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=%s%s", whitelist
? "" : "~", joined
);
1533 if (streq(name
, "CPUAffinity")) {
1537 r
= sd_bus_message_read_array(message
, 'y', &a
, &n
);
1541 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1543 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1544 c
->cpuset_ncpus
= 0;
1545 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1547 _cleanup_free_
char *str
= NULL
;
1548 size_t allocated
= 0, len
= 0, i
, ncpus
;
1550 ncpus
= CPU_SIZE_TO_NUM(n
);
1552 for (i
= 0; i
< ncpus
; i
++) {
1553 _cleanup_free_
char *p
= NULL
;
1556 if (!CPU_ISSET_S(i
, n
, (cpu_set_t
*) a
))
1559 r
= asprintf(&p
, "%zu", i
);
1565 if (!GREEDY_REALLOC(str
, allocated
, len
+ add
+ 2))
1568 strcpy(mempcpy(str
+ len
, p
, add
), " ");
1573 str
[len
- 1] = '\0';
1575 if (!c
->cpuset
|| c
->cpuset_ncpus
< ncpus
) {
1578 cpuset
= CPU_ALLOC(ncpus
);
1582 CPU_ZERO_S(n
, cpuset
);
1584 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, (cpu_set_t
*) a
);
1585 CPU_FREE(c
->cpuset
);
1587 CPU_OR_S(n
, cpuset
, cpuset
, (cpu_set_t
*) a
);
1590 c
->cpuset_ncpus
= ncpus
;
1592 CPU_OR_S(n
, c
->cpuset
, c
->cpuset
, (cpu_set_t
*) a
);
1594 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, str
);
1600 } else if (streq(name
, "Nice")) {
1603 r
= sd_bus_message_read(message
, "i", &q
);
1607 if (!nice_is_valid(q
))
1608 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid Nice value: %i", q
);
1610 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1614 unit_write_settingf(u
, flags
, name
, "Nice=%i", q
);
1619 } else if (streq(name
, "CPUSchedulingPolicy")) {
1622 r
= sd_bus_message_read(message
, "i", &q
);
1626 if (!sched_policy_is_valid(q
))
1627 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling policy: %i", q
);
1629 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1630 _cleanup_free_
char *s
= NULL
;
1632 r
= sched_policy_to_string_alloc(q
, &s
);
1636 c
->cpu_sched_policy
= q
;
1637 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(q
), sched_get_priority_max(q
));
1638 c
->cpu_sched_set
= true;
1640 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPolicy=%s", s
);
1645 } else if (streq(name
, "CPUSchedulingPriority")) {
1646 int32_t p
, min
, max
;
1648 r
= sd_bus_message_read(message
, "i", &p
);
1652 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1653 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1654 if (p
< min
|| p
> max
)
1655 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling priority: %i", p
);
1657 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1658 c
->cpu_sched_priority
= p
;
1659 c
->cpu_sched_set
= true;
1661 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPriority=%i", p
);
1666 } else if (streq(name
, "IOSchedulingClass")) {
1669 r
= sd_bus_message_read(message
, "i", &q
);
1673 if (!ioprio_class_is_valid(q
))
1674 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling class: %i", q
);
1676 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1677 _cleanup_free_
char *s
= NULL
;
1679 r
= ioprio_class_to_string_alloc(q
, &s
);
1683 c
->ioprio
= IOPRIO_PRIO_VALUE(q
, IOPRIO_PRIO_DATA(c
->ioprio
));
1684 c
->ioprio_set
= true;
1686 unit_write_settingf(u
, flags
, name
, "IOSchedulingClass=%s", s
);
1691 } else if (streq(name
, "IOSchedulingPriority")) {
1694 r
= sd_bus_message_read(message
, "i", &p
);
1698 if (!ioprio_priority_is_valid(p
))
1699 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling priority: %i", p
);
1701 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1702 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), p
);
1703 c
->ioprio_set
= true;
1705 unit_write_settingf(u
, flags
, name
, "IOSchedulingPriority=%i", p
);
1710 } else if (streq(name
, "WorkingDirectory")) {
1714 r
= sd_bus_message_read(message
, "s", &s
);
1724 if (!isempty(s
) && !streq(s
, "~") && !path_is_absolute(s
))
1725 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "WorkingDirectory= expects an absolute path or '~'");
1727 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1728 if (streq(s
, "~")) {
1729 c
->working_directory
= mfree(c
->working_directory
);
1730 c
->working_directory_home
= true;
1732 r
= free_and_strdup(&c
->working_directory
, empty_to_null(s
));
1736 c
->working_directory_home
= false;
1739 c
->working_directory_missing_ok
= missing_ok
;
1740 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "WorkingDirectory=%s%s", missing_ok
? "-" : "", s
);
1745 } else if (STR_IN_SET(name
,
1746 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
1749 r
= sd_bus_message_read(message
, "s", &s
);
1753 if (!isempty(s
) && !fdname_is_valid(s
))
1754 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid file descriptor name");
1756 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1758 if (streq(name
, "StandardInputFileDescriptorName")) {
1759 r
= free_and_strdup(c
->stdio_fdname
+ STDIN_FILENO
, empty_to_null(s
));
1763 c
->std_input
= EXEC_INPUT_NAMED_FD
;
1764 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=fd:%s", exec_context_fdname(c
, STDIN_FILENO
));
1766 } else if (streq(name
, "StandardOutputFileDescriptorName")) {
1767 r
= free_and_strdup(c
->stdio_fdname
+ STDOUT_FILENO
, empty_to_null(s
));
1771 c
->std_output
= EXEC_OUTPUT_NAMED_FD
;
1772 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=fd:%s", exec_context_fdname(c
, STDOUT_FILENO
));
1775 assert(streq(name
, "StandardErrorFileDescriptorName"));
1777 r
= free_and_strdup(&c
->stdio_fdname
[STDERR_FILENO
], empty_to_null(s
));
1781 c
->std_error
= EXEC_OUTPUT_NAMED_FD
;
1782 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=fd:%s", exec_context_fdname(c
, STDERR_FILENO
));
1788 } else if (STR_IN_SET(name
,
1789 "StandardInputFile",
1790 "StandardOutputFile", "StandardOutputFileToCreate", "StandardOutputFileToAppend",
1791 "StandardErrorFile", "StandardErrorFileToCreate", "StandardErrorFileToAppend")) {
1794 r
= sd_bus_message_read(message
, "s", &s
);
1799 if (!path_is_absolute(s
))
1800 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute", s
);
1801 if (!path_is_normalized(s
))
1802 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not normalized", s
);
1805 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1807 if (streq(name
, "StandardInputFile")) {
1808 r
= free_and_strdup(&c
->stdio_file
[STDIN_FILENO
], empty_to_null(s
));
1812 c
->std_input
= EXEC_INPUT_FILE
;
1813 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=file:%s", s
);
1815 } else if (STR_IN_SET(name
, "StandardOutputFile", "StandardOutputFileToAppend")) {
1816 r
= free_and_strdup(&c
->stdio_file
[STDOUT_FILENO
], empty_to_null(s
));
1820 if (streq(name
, "StandardOutputFile")) {
1821 c
->std_output
= EXEC_OUTPUT_FILE
;
1822 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=file:%s", s
);
1824 assert(streq(name
, "StandardOutputFileToAppend"));
1825 c
->std_output
= EXEC_OUTPUT_FILE_APPEND
;
1826 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=append:%s", s
);
1829 assert(STR_IN_SET(name
, "StandardErrorFile", "StandardErrorFileToAppend"));
1831 r
= free_and_strdup(&c
->stdio_file
[STDERR_FILENO
], empty_to_null(s
));
1835 if (streq(name
, "StandardErrorFile")) {
1836 c
->std_error
= EXEC_OUTPUT_FILE
;
1837 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=file:%s", s
);
1839 assert(streq(name
, "StandardErrorFileToAppend"));
1840 c
->std_error
= EXEC_OUTPUT_FILE_APPEND
;
1841 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=append:%s", s
);
1848 } else if (streq(name
, "StandardInputData")) {
1852 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
1856 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1857 _cleanup_free_
char *encoded
= NULL
;
1860 c
->stdin_data
= mfree(c
->stdin_data
);
1861 c
->stdin_data_size
= 0;
1863 unit_write_settingf(u
, flags
, name
, "StandardInputData=");
1868 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1869 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
)
1872 n
= base64mem(p
, sz
, &encoded
);
1876 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1880 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1883 c
->stdin_data_size
+= sz
;
1885 unit_write_settingf(u
, flags
, name
, "StandardInputData=%s", encoded
);
1891 } else if (streq(name
, "Environment")) {
1893 _cleanup_strv_free_
char **l
= NULL
;
1895 r
= sd_bus_message_read_strv(message
, &l
);
1899 if (!strv_env_is_valid(l
))
1900 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment block.");
1902 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1903 if (strv_isempty(l
)) {
1904 c
->environment
= strv_free(c
->environment
);
1905 unit_write_setting(u
, flags
, name
, "Environment=");
1907 _cleanup_free_
char *joined
= NULL
;
1910 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
1914 e
= strv_env_merge(2, c
->environment
, l
);
1918 strv_free_and_replace(c
->environment
, e
);
1919 unit_write_settingf(u
, flags
, name
, "Environment=%s", joined
);
1925 } else if (streq(name
, "UnsetEnvironment")) {
1927 _cleanup_strv_free_
char **l
= NULL
;
1929 r
= sd_bus_message_read_strv(message
, &l
);
1933 if (!strv_env_name_or_assignment_is_valid(l
))
1934 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid UnsetEnvironment= list.");
1936 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1937 if (strv_isempty(l
)) {
1938 c
->unset_environment
= strv_free(c
->unset_environment
);
1939 unit_write_setting(u
, flags
, name
, "UnsetEnvironment=");
1941 _cleanup_free_
char *joined
= NULL
;
1944 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
1948 e
= strv_env_merge(2, c
->unset_environment
, l
);
1952 strv_free_and_replace(c
->unset_environment
, e
);
1953 unit_write_settingf(u
, flags
, name
, "UnsetEnvironment=%s", joined
);
1959 } else if (streq(name
, "OOMScoreAdjust")) {
1962 r
= sd_bus_message_read(message
, "i", &oa
);
1966 if (!oom_score_adjust_is_valid(oa
))
1967 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "OOM score adjust value out of range");
1969 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1970 c
->oom_score_adjust
= oa
;
1971 c
->oom_score_adjust_set
= true;
1972 unit_write_settingf(u
, flags
, name
, "OOMScoreAdjust=%i", oa
);
1977 } else if (streq(name
, "EnvironmentFiles")) {
1979 _cleanup_free_
char *joined
= NULL
;
1980 _cleanup_fclose_
FILE *f
= NULL
;
1981 _cleanup_strv_free_
char **l
= NULL
;
1985 r
= sd_bus_message_enter_container(message
, 'a', "(sb)");
1989 f
= open_memstream(&joined
, &size
);
1993 (void) __fsetlocking(f
, FSETLOCKING_BYCALLER
);
1995 fputs("EnvironmentFile=\n", f
);
1997 STRV_FOREACH(i
, c
->environment_files
) {
1998 _cleanup_free_
char *q
= NULL
;
2000 q
= specifier_escape(*i
);
2004 fprintf(f
, "EnvironmentFile=%s\n", q
);
2007 while ((r
= sd_bus_message_enter_container(message
, 'r', "sb")) > 0) {
2011 r
= sd_bus_message_read(message
, "sb", &path
, &b
);
2015 r
= sd_bus_message_exit_container(message
);
2019 if (!path_is_absolute(path
))
2020 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
2022 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2023 _cleanup_free_
char *q
= NULL
;
2026 buf
= strjoin(b
? "-" : "", path
);
2030 q
= specifier_escape(buf
);
2036 fprintf(f
, "EnvironmentFile=%s\n", q
);
2038 r
= strv_consume(&l
, buf
);
2046 r
= sd_bus_message_exit_container(message
);
2050 r
= fflush_and_check(f
);
2054 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2055 if (strv_isempty(l
)) {
2056 c
->environment_files
= strv_free(c
->environment_files
);
2057 unit_write_setting(u
, flags
, name
, "EnvironmentFile=");
2059 r
= strv_extend_strv(&c
->environment_files
, l
, true);
2063 unit_write_setting(u
, flags
, name
, joined
);
2069 } else if (streq(name
, "PassEnvironment")) {
2071 _cleanup_strv_free_
char **l
= NULL
;
2073 r
= sd_bus_message_read_strv(message
, &l
);
2077 if (!strv_env_name_is_valid(l
))
2078 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PassEnvironment= block.");
2080 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2081 if (strv_isempty(l
)) {
2082 c
->pass_environment
= strv_free(c
->pass_environment
);
2083 unit_write_setting(u
, flags
, name
, "PassEnvironment=");
2085 _cleanup_free_
char *joined
= NULL
;
2087 r
= strv_extend_strv(&c
->pass_environment
, l
, true);
2091 /* We write just the new settings out to file, with unresolved specifiers. */
2092 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2096 unit_write_settingf(u
, flags
, name
, "PassEnvironment=%s", joined
);
2102 } else if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
2103 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) {
2104 _cleanup_strv_free_
char **l
= NULL
;
2108 r
= sd_bus_message_read_strv(message
, &l
);
2112 STRV_FOREACH(p
, l
) {
2116 offset
= i
[0] == '-';
2117 offset
+= i
[offset
] == '+';
2118 if (!path_is_absolute(i
+ offset
))
2119 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
2121 path_simplify(i
+ offset
, false);
2124 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2125 if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadWritePaths"))
2126 dirs
= &c
->read_write_paths
;
2127 else if (STR_IN_SET(name
, "ReadOnlyDirectories", "ReadOnlyPaths"))
2128 dirs
= &c
->read_only_paths
;
2129 else /* "InaccessiblePaths" */
2130 dirs
= &c
->inaccessible_paths
;
2132 if (strv_isempty(l
)) {
2133 *dirs
= strv_free(*dirs
);
2134 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2136 _cleanup_free_
char *joined
= NULL
;
2138 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2142 r
= strv_extend_strv(dirs
, l
, true);
2146 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2152 } else if (STR_IN_SET(name
, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
2153 _cleanup_strv_free_
char **l
= NULL
;
2156 r
= sd_bus_message_read_strv(message
, &l
);
2160 STRV_FOREACH(p
, l
) {
2161 if (!path_is_normalized(*p
))
2162 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is not normalized: %s", name
, *p
);
2164 if (path_is_absolute(*p
))
2165 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is absolute: %s", name
, *p
);
2167 if (path_startswith(*p
, "private"))
2168 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path can't be 'private': %s", name
, *p
);
2171 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2172 char ***dirs
= NULL
;
2173 ExecDirectoryType i
;
2175 for (i
= 0; i
< _EXEC_DIRECTORY_TYPE_MAX
; i
++)
2176 if (streq(name
, exec_directory_type_to_string(i
))) {
2177 dirs
= &c
->directories
[i
].paths
;
2183 if (strv_isempty(l
)) {
2184 *dirs
= strv_free(*dirs
);
2185 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2187 _cleanup_free_
char *joined
= NULL
;
2189 r
= strv_extend_strv(dirs
, l
, true);
2193 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2197 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2203 } else if (STR_IN_SET(name
, "AppArmorProfile", "SmackProcessLabel")) {
2207 r
= sd_bus_message_read(message
, "(bs)", &ignore
, &s
);
2211 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2215 if (streq(name
, "AppArmorProfile")) {
2216 p
= &c
->apparmor_profile
;
2217 b
= &c
->apparmor_profile_ignore
;
2218 } else { /* "SmackProcessLabel" */
2219 p
= &c
->smack_process_label
;
2220 b
= &c
->smack_process_label_ignore
;
2227 if (free_and_strdup(p
, s
) < 0)
2232 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s%s", name
, ignore
? "-" : "", strempty(s
));
2237 } else if (STR_IN_SET(name
, "BindPaths", "BindReadOnlyPaths")) {
2238 const char *source
, *destination
;
2240 uint64_t mount_flags
;
2243 r
= sd_bus_message_enter_container(message
, 'a', "(ssbt)");
2247 while ((r
= sd_bus_message_read(message
, "(ssbt)", &source
, &destination
, &ignore_enoent
, &mount_flags
)) > 0) {
2249 if (!path_is_absolute(source
))
2250 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
2251 if (!path_is_absolute(destination
))
2252 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
2253 if (!IN_SET(mount_flags
, 0, MS_REC
))
2254 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount flags.");
2256 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2257 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
2259 .source
= strdup(source
),
2260 .destination
= strdup(destination
),
2261 .read_only
= !!strstr(name
, "ReadOnly"),
2262 .recursive
= !!(mount_flags
& MS_REC
),
2263 .ignore_enoent
= ignore_enoent
,
2268 unit_write_settingf(
2269 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2272 ignore_enoent
? "-" : "",
2275 (mount_flags
& MS_REC
) ? "rbind" : "norbind");
2283 r
= sd_bus_message_exit_container(message
);
2288 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
2289 c
->bind_mounts
= NULL
;
2290 c
->n_bind_mounts
= 0;
2292 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2297 } else if (streq(name
, "TemporaryFileSystem")) {
2298 const char *path
, *options
;
2301 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
2305 while ((r
= sd_bus_message_read(message
, "(ss)", &path
, &options
)) > 0) {
2307 if (!path_is_absolute(path
))
2308 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Mount point %s is not absolute.", path
);
2310 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2311 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, options
);
2315 unit_write_settingf(
2316 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2328 r
= sd_bus_message_exit_container(message
);
2333 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
2334 c
->temporary_filesystems
= NULL
;
2335 c
->n_temporary_filesystems
= 0;
2337 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2342 } else if ((suffix
= startswith(name
, "Limit"))) {
2343 const char *soft
= NULL
;
2346 ri
= rlimit_from_string(suffix
);
2348 soft
= endswith(suffix
, "Soft");
2352 n
= strndupa(suffix
, soft
- suffix
);
2353 ri
= rlimit_from_string(n
);
2355 name
= strjoina("Limit", n
);
2363 r
= sd_bus_message_read(message
, "t", &rl
);
2367 if (rl
== (uint64_t) -1)
2372 if ((uint64_t) x
!= rl
)
2376 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2377 _cleanup_free_
char *f
= NULL
;
2380 if (c
->rlimit
[ri
]) {
2381 nl
= *c
->rlimit
[ri
];
2388 /* When the resource limit is not initialized yet, then assign the value to both fields */
2389 nl
= (struct rlimit
) {
2394 r
= rlimit_format(&nl
, &f
);
2399 *c
->rlimit
[ri
] = nl
;
2401 c
->rlimit
[ri
] = newdup(struct rlimit
, &nl
, 1);
2406 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, f
);