1 /* SPDX-License-Identifier: LGPL-2.1+ */
11 #include "alloc-util.h"
14 #include "capability-util.h"
15 #include "cpu-set-util.h"
16 #include "dbus-execute.h"
17 #include "dbus-util.h"
19 #include "errno-list.h"
24 #include "hexdecoct.h"
27 #include "journal-util.h"
28 #include "mountpoint-util.h"
29 #include "namespace.h"
30 #include "parse-util.h"
31 #include "path-util.h"
32 #include "process-util.h"
33 #include "rlimit-util.h"
35 #include "seccomp-util.h"
37 #include "securebits-util.h"
38 #include "specifier.h"
40 #include "syslog-util.h"
41 #include "unit-printf.h"
42 #include "user-util.h"
45 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output
, exec_output
, ExecOutput
);
46 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input
, exec_input
, ExecInput
);
47 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
);
48 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
);
49 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
);
50 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home
, protect_home
, ProtectHome
);
51 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system
, protect_system
, ProtectSystem
);
52 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality
, personality
, unsigned long);
53 static BUS_DEFINE_PROPERTY_GET(property_get_ioprio
, "i", ExecContext
, exec_context_get_effective_ioprio
);
54 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class
, "i", ExecContext
, exec_context_get_effective_ioprio
, IOPRIO_PRIO_CLASS
);
55 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority
, "i", ExecContext
, exec_context_get_effective_ioprio
, IOPRIO_PRIO_DATA
);
56 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string
, "s", NULL
);
57 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level
, "i", int, LOG_PRI
);
58 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility
, "i", int, LOG_FAC
);
60 static int property_get_environment_files(
63 const char *interface
,
65 sd_bus_message
*reply
,
67 sd_bus_error
*error
) {
69 ExecContext
*c
= userdata
;
77 r
= sd_bus_message_open_container(reply
, 'a', "(sb)");
81 STRV_FOREACH(j
, c
->environment_files
) {
84 r
= sd_bus_message_append(reply
, "(sb)", fn
[0] == '-' ? fn
+ 1 : fn
, fn
[0] == '-');
89 return sd_bus_message_close_container(reply
);
92 static int property_get_oom_score_adjust(
95 const char *interface
,
97 sd_bus_message
*reply
,
99 sd_bus_error
*error
) {
101 ExecContext
*c
= userdata
;
108 if (c
->oom_score_adjust_set
)
109 n
= c
->oom_score_adjust
;
111 _cleanup_free_
char *t
= NULL
;
114 if (read_one_line_file("/proc/self/oom_score_adj", &t
) >= 0)
118 return sd_bus_message_append(reply
, "i", n
);
121 static int property_get_nice(
124 const char *interface
,
125 const char *property
,
126 sd_bus_message
*reply
,
128 sd_bus_error
*error
) {
130 ExecContext
*c
= userdata
;
141 n
= getpriority(PRIO_PROCESS
, 0);
146 return sd_bus_message_append(reply
, "i", n
);
149 static int property_get_cpu_sched_policy(
152 const char *interface
,
153 const char *property
,
154 sd_bus_message
*reply
,
156 sd_bus_error
*error
) {
158 ExecContext
*c
= userdata
;
165 if (c
->cpu_sched_set
)
166 n
= c
->cpu_sched_policy
;
168 n
= sched_getscheduler(0);
173 return sd_bus_message_append(reply
, "i", n
);
176 static int property_get_cpu_sched_priority(
179 const char *interface
,
180 const char *property
,
181 sd_bus_message
*reply
,
183 sd_bus_error
*error
) {
185 ExecContext
*c
= userdata
;
192 if (c
->cpu_sched_set
)
193 n
= c
->cpu_sched_priority
;
195 struct sched_param p
= {};
197 if (sched_getparam(0, &p
) >= 0)
198 n
= p
.sched_priority
;
203 return sd_bus_message_append(reply
, "i", n
);
206 static int property_get_cpu_affinity(
209 const char *interface
,
210 const char *property
,
211 sd_bus_message
*reply
,
213 sd_bus_error
*error
) {
215 ExecContext
*c
= userdata
;
216 _cleanup_free_
uint8_t *array
= NULL
;
223 (void) cpu_set_to_dbus(&c
->cpu_set
, &array
, &allocated
);
224 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
227 static int property_get_numa_mask(
230 const char *interface
,
231 const char *property
,
232 sd_bus_message
*reply
,
234 sd_bus_error
*error
) {
236 ExecContext
*c
= userdata
;
237 _cleanup_free_
uint8_t *array
= NULL
;
244 (void) cpu_set_to_dbus(&c
->numa_policy
.nodes
, &array
, &allocated
);
246 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
249 static int property_get_numa_policy(
252 const char *interface
,
253 const char *property
,
254 sd_bus_message
*reply
,
256 sd_bus_error
*error
) {
257 ExecContext
*c
= userdata
;
264 policy
= numa_policy_get_type(&c
->numa_policy
);
266 return sd_bus_message_append_basic(reply
, 'i', &policy
);
269 static int property_get_timer_slack_nsec(
272 const char *interface
,
273 const char *property
,
274 sd_bus_message
*reply
,
276 sd_bus_error
*error
) {
278 ExecContext
*c
= userdata
;
285 if (c
->timer_slack_nsec
!= NSEC_INFINITY
)
286 u
= (uint64_t) c
->timer_slack_nsec
;
288 u
= (uint64_t) prctl(PR_GET_TIMERSLACK
);
290 return sd_bus_message_append(reply
, "t", u
);
293 static int property_get_syscall_filter(
296 const char *interface
,
297 const char *property
,
298 sd_bus_message
*reply
,
300 sd_bus_error
*error
) {
302 ExecContext
*c
= userdata
;
303 _cleanup_strv_free_
char **l
= NULL
;
315 r
= sd_bus_message_open_container(reply
, 'r', "bas");
319 r
= sd_bus_message_append(reply
, "b", c
->syscall_whitelist
);
324 HASHMAP_FOREACH_KEY(val
, id
, c
->syscall_filter
, i
) {
325 _cleanup_free_
char *name
= NULL
;
326 const char *e
= NULL
;
328 int num
= PTR_TO_INT(val
);
330 name
= seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE
, PTR_TO_INT(id
) - 1);
335 e
= errno_to_name(num
);
337 s
= strjoin(name
, ":", e
);
341 r
= asprintf(&s
, "%s:%d", name
, num
);
348 r
= strv_consume(&l
, s
);
356 r
= sd_bus_message_append_strv(reply
, l
);
360 return sd_bus_message_close_container(reply
);
363 static int property_get_syscall_archs(
366 const char *interface
,
367 const char *property
,
368 sd_bus_message
*reply
,
370 sd_bus_error
*error
) {
372 ExecContext
*c
= userdata
;
373 _cleanup_strv_free_
char **l
= NULL
;
386 SET_FOREACH(id
, c
->syscall_archs
, i
) {
389 name
= seccomp_arch_to_string(PTR_TO_UINT32(id
) - 1);
393 r
= strv_extend(&l
, name
);
401 r
= sd_bus_message_append_strv(reply
, l
);
408 static int property_get_selinux_context(
411 const char *interface
,
412 const char *property
,
413 sd_bus_message
*reply
,
415 sd_bus_error
*error
) {
417 ExecContext
*c
= userdata
;
423 return sd_bus_message_append(reply
, "(bs)", c
->selinux_context_ignore
, c
->selinux_context
);
426 static int property_get_apparmor_profile(
429 const char *interface
,
430 const char *property
,
431 sd_bus_message
*reply
,
433 sd_bus_error
*error
) {
435 ExecContext
*c
= userdata
;
441 return sd_bus_message_append(reply
, "(bs)", c
->apparmor_profile_ignore
, c
->apparmor_profile
);
444 static int property_get_smack_process_label(
447 const char *interface
,
448 const char *property
,
449 sd_bus_message
*reply
,
451 sd_bus_error
*error
) {
453 ExecContext
*c
= userdata
;
459 return sd_bus_message_append(reply
, "(bs)", c
->smack_process_label_ignore
, c
->smack_process_label
);
462 static int property_get_address_families(
465 const char *interface
,
466 const char *property
,
467 sd_bus_message
*reply
,
469 sd_bus_error
*error
) {
471 ExecContext
*c
= userdata
;
472 _cleanup_strv_free_
char **l
= NULL
;
481 r
= sd_bus_message_open_container(reply
, 'r', "bas");
485 r
= sd_bus_message_append(reply
, "b", c
->address_families_whitelist
);
489 SET_FOREACH(af
, c
->address_families
, i
) {
492 name
= af_to_name(PTR_TO_INT(af
));
496 r
= strv_extend(&l
, name
);
503 r
= sd_bus_message_append_strv(reply
, l
);
507 return sd_bus_message_close_container(reply
);
510 static int property_get_working_directory(
513 const char *interface
,
514 const char *property
,
515 sd_bus_message
*reply
,
517 sd_bus_error
*error
) {
519 ExecContext
*c
= userdata
;
526 if (c
->working_directory_home
)
529 wd
= c
->working_directory
;
531 if (c
->working_directory_missing_ok
)
532 wd
= strjoina("!", wd
);
534 return sd_bus_message_append(reply
, "s", wd
);
537 static int property_get_stdio_fdname(
540 const char *interface
,
541 const char *property
,
542 sd_bus_message
*reply
,
544 sd_bus_error
*error
) {
546 ExecContext
*c
= userdata
;
554 if (streq(property
, "StandardInputFileDescriptorName"))
555 fileno
= STDIN_FILENO
;
556 else if (streq(property
, "StandardOutputFileDescriptorName"))
557 fileno
= STDOUT_FILENO
;
559 assert(streq(property
, "StandardErrorFileDescriptorName"));
560 fileno
= STDERR_FILENO
;
563 return sd_bus_message_append(reply
, "s", exec_context_fdname(c
, fileno
));
566 static int property_get_input_data(
569 const char *interface
,
570 const char *property
,
571 sd_bus_message
*reply
,
573 sd_bus_error
*error
) {
575 ExecContext
*c
= userdata
;
582 return sd_bus_message_append_array(reply
, 'y', c
->stdin_data
, c
->stdin_data_size
);
585 static int property_get_bind_paths(
588 const char *interface
,
589 const char *property
,
590 sd_bus_message
*reply
,
592 sd_bus_error
*error
) {
594 ExecContext
*c
= userdata
;
604 ro
= strstr(property
, "ReadOnly");
606 r
= sd_bus_message_open_container(reply
, 'a', "(ssbt)");
610 for (i
= 0; i
< c
->n_bind_mounts
; i
++) {
612 if (ro
!= c
->bind_mounts
[i
].read_only
)
615 r
= sd_bus_message_append(
617 c
->bind_mounts
[i
].source
,
618 c
->bind_mounts
[i
].destination
,
619 c
->bind_mounts
[i
].ignore_enoent
,
620 c
->bind_mounts
[i
].recursive
? (uint64_t) MS_REC
: (uint64_t) 0);
625 return sd_bus_message_close_container(reply
);
628 static int property_get_temporary_filesystems(
631 const char *interface
,
632 const char *property
,
633 sd_bus_message
*reply
,
635 sd_bus_error
*error
) {
637 ExecContext
*c
= userdata
;
646 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
650 for (i
= 0; i
< c
->n_temporary_filesystems
; i
++) {
651 TemporaryFileSystem
*t
= c
->temporary_filesystems
+ i
;
653 r
= sd_bus_message_append(
661 return sd_bus_message_close_container(reply
);
664 static int property_get_log_extra_fields(
667 const char *interface
,
668 const char *property
,
669 sd_bus_message
*reply
,
671 sd_bus_error
*error
) {
673 ExecContext
*c
= userdata
;
682 r
= sd_bus_message_open_container(reply
, 'a', "ay");
686 for (i
= 0; i
< c
->n_log_extra_fields
; i
++) {
687 r
= sd_bus_message_append_array(reply
, 'y', c
->log_extra_fields
[i
].iov_base
, c
->log_extra_fields
[i
].iov_len
);
692 return sd_bus_message_close_container(reply
);
695 const sd_bus_vtable bus_exec_vtable
[] = {
696 SD_BUS_VTABLE_START(0),
697 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(ExecContext
, environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
698 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
699 SD_BUS_PROPERTY("PassEnvironment", "as", NULL
, offsetof(ExecContext
, pass_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
700 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL
, offsetof(ExecContext
, unset_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
701 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode
, offsetof(ExecContext
, umask
), SD_BUS_VTABLE_PROPERTY_CONST
),
702 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
703 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
704 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
705 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
706 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
707 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
708 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
709 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
710 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
711 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
712 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
713 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
714 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
715 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
716 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
717 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
718 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
719 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
720 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
721 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
722 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
723 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
724 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
725 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
726 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
727 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
728 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
729 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
730 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
731 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
732 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
733 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
734 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
735 SD_BUS_PROPERTY("RootDirectory", "s", NULL
, offsetof(ExecContext
, root_directory
), SD_BUS_VTABLE_PROPERTY_CONST
),
736 SD_BUS_PROPERTY("RootImage", "s", NULL
, offsetof(ExecContext
, root_image
), SD_BUS_VTABLE_PROPERTY_CONST
),
737 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
738 SD_BUS_PROPERTY("Nice", "i", property_get_nice
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
739 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
740 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
741 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
742 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
743 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
744 SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
745 SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
746 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
747 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool
, offsetof(ExecContext
, cpu_sched_reset_on_fork
), SD_BUS_VTABLE_PROPERTY_CONST
),
748 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool
, offsetof(ExecContext
, non_blocking
), SD_BUS_VTABLE_PROPERTY_CONST
),
749 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input
, offsetof(ExecContext
, std_input
), SD_BUS_VTABLE_PROPERTY_CONST
),
750 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
751 SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
752 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
753 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
754 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_error
), SD_BUS_VTABLE_PROPERTY_CONST
),
755 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
756 SD_BUS_PROPERTY("TTYPath", "s", NULL
, offsetof(ExecContext
, tty_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
757 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_reset
), SD_BUS_VTABLE_PROPERTY_CONST
),
758 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vhangup
), SD_BUS_VTABLE_PROPERTY_CONST
),
759 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vt_disallocate
), SD_BUS_VTABLE_PROPERTY_CONST
),
760 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
761 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL
, offsetof(ExecContext
, syslog_identifier
), SD_BUS_VTABLE_PROPERTY_CONST
),
762 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool
, offsetof(ExecContext
, syslog_level_prefix
), SD_BUS_VTABLE_PROPERTY_CONST
),
763 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
764 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
765 SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int
, offsetof(ExecContext
, log_level_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
766 SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec
, offsetof(ExecContext
, log_ratelimit_interval_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
767 SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned
, offsetof(ExecContext
, log_ratelimit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
768 SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
769 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int
, offsetof(ExecContext
, secure_bits
), SD_BUS_VTABLE_PROPERTY_CONST
),
770 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL
, offsetof(ExecContext
, capability_bounding_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
771 SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL
, offsetof(ExecContext
, capability_ambient_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
772 SD_BUS_PROPERTY("User", "s", NULL
, offsetof(ExecContext
, user
), SD_BUS_VTABLE_PROPERTY_CONST
),
773 SD_BUS_PROPERTY("Group", "s", NULL
, offsetof(ExecContext
, group
), SD_BUS_VTABLE_PROPERTY_CONST
),
774 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool
, offsetof(ExecContext
, dynamic_user
), SD_BUS_VTABLE_PROPERTY_CONST
),
775 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, remove_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
776 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL
, offsetof(ExecContext
, supplementary_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
777 SD_BUS_PROPERTY("PAMName", "s", NULL
, offsetof(ExecContext
, pam_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
778 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
779 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
780 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
781 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong
, offsetof(ExecContext
, mount_flags
), SD_BUS_VTABLE_PROPERTY_CONST
),
782 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool
, offsetof(ExecContext
, private_tmp
), SD_BUS_VTABLE_PROPERTY_CONST
),
783 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool
, offsetof(ExecContext
, private_devices
), SD_BUS_VTABLE_PROPERTY_CONST
),
784 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_tunables
), SD_BUS_VTABLE_PROPERTY_CONST
),
785 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_modules
), SD_BUS_VTABLE_PROPERTY_CONST
),
786 SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_logs
), 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("TimeoutCleanUSec", "t", bus_property_get_usec
, offsetof(ExecContext
, timeout_clean_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
819 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool
, offsetof(ExecContext
, memory_deny_write_execute
), SD_BUS_VTABLE_PROPERTY_CONST
),
820 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_realtime
), SD_BUS_VTABLE_PROPERTY_CONST
),
821 SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_suid_sgid
), SD_BUS_VTABLE_PROPERTY_CONST
),
822 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong
, offsetof(ExecContext
, restrict_namespaces
), SD_BUS_VTABLE_PROPERTY_CONST
),
823 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
824 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
825 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
826 SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool
, offsetof(ExecContext
, mount_apivfs
), SD_BUS_VTABLE_PROPERTY_CONST
),
827 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode
, offsetof(ExecContext
, keyring_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
828 SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_hostname
), SD_BUS_VTABLE_PROPERTY_CONST
),
829 SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL
, offsetof(ExecContext
, network_namespace_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
831 /* Obsolete/redundant properties: */
832 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
833 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
834 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
835 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
836 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
841 static int append_exec_command(sd_bus_message
*reply
, ExecCommand
*c
) {
850 r
= sd_bus_message_open_container(reply
, 'r', "sasbttttuii");
854 r
= sd_bus_message_append(reply
, "s", c
->path
);
858 r
= sd_bus_message_append_strv(reply
, c
->argv
);
862 r
= sd_bus_message_append(reply
, "bttttuii",
863 !!(c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
),
864 c
->exec_status
.start_timestamp
.realtime
,
865 c
->exec_status
.start_timestamp
.monotonic
,
866 c
->exec_status
.exit_timestamp
.realtime
,
867 c
->exec_status
.exit_timestamp
.monotonic
,
868 (uint32_t) c
->exec_status
.pid
,
869 (int32_t) c
->exec_status
.code
,
870 (int32_t) c
->exec_status
.status
);
874 return sd_bus_message_close_container(reply
);
877 static int append_exec_ex_command(sd_bus_message
*reply
, ExecCommand
*c
) {
878 _cleanup_strv_free_
char **ex_opts
= NULL
;
887 r
= sd_bus_message_open_container(reply
, 'r', "sasasttttuii");
891 r
= sd_bus_message_append(reply
, "s", c
->path
);
895 r
= sd_bus_message_append_strv(reply
, c
->argv
);
899 r
= exec_command_flags_to_strv(c
->flags
, &ex_opts
);
903 r
= sd_bus_message_append_strv(reply
, ex_opts
);
907 r
= sd_bus_message_append(reply
, "ttttuii",
908 c
->exec_status
.start_timestamp
.realtime
,
909 c
->exec_status
.start_timestamp
.monotonic
,
910 c
->exec_status
.exit_timestamp
.realtime
,
911 c
->exec_status
.exit_timestamp
.monotonic
,
912 (uint32_t) c
->exec_status
.pid
,
913 (int32_t) c
->exec_status
.code
,
914 (int32_t) c
->exec_status
.status
);
918 return sd_bus_message_close_container(reply
);
921 int bus_property_get_exec_command(
924 const char *interface
,
925 const char *property
,
926 sd_bus_message
*reply
,
928 sd_bus_error
*ret_error
) {
930 ExecCommand
*c
= (ExecCommand
*) userdata
;
936 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
940 r
= append_exec_command(reply
, c
);
944 return sd_bus_message_close_container(reply
);
947 int bus_property_get_exec_command_list(
950 const char *interface
,
951 const char *property
,
952 sd_bus_message
*reply
,
954 sd_bus_error
*ret_error
) {
956 ExecCommand
*c
= *(ExecCommand
**) userdata
;
962 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
966 LIST_FOREACH(command
, c
, c
) {
967 r
= append_exec_command(reply
, c
);
972 return sd_bus_message_close_container(reply
);
975 int bus_property_get_exec_ex_command_list(
978 const char *interface
,
979 const char *property
,
980 sd_bus_message
*reply
,
982 sd_bus_error
*ret_error
) {
984 ExecCommand
*c
, *exec_command
= *(ExecCommand
**) userdata
;
990 r
= sd_bus_message_open_container(reply
, 'a', "(sasasttttuii)");
994 LIST_FOREACH(command
, c
, exec_command
) {
995 r
= append_exec_ex_command(reply
, c
);
1000 return sd_bus_message_close_container(reply
);
1003 static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags
) {
1004 return strjoin(FLAGS_SET(flags
, EXEC_COMMAND_IGNORE_FAILURE
) ? "-" : "",
1005 FLAGS_SET(flags
, EXEC_COMMAND_NO_ENV_EXPAND
) ? ":" : "",
1006 FLAGS_SET(flags
, EXEC_COMMAND_FULLY_PRIVILEGED
) ? "+" : "",
1007 FLAGS_SET(flags
, EXEC_COMMAND_NO_SETUID
) ? "!" : "",
1008 FLAGS_SET(flags
, EXEC_COMMAND_AMBIENT_MAGIC
) ? "!!" : "");
1011 int bus_set_transient_exec_command(
1014 ExecCommand
**exec_command
,
1015 sd_bus_message
*message
,
1016 UnitWriteFlags flags
,
1017 sd_bus_error
*error
) {
1018 bool is_ex_prop
= endswith(name
, "Ex");
1022 r
= sd_bus_message_enter_container(message
, 'a', is_ex_prop
? "(sasas)" : "(sasb)");
1026 while ((r
= sd_bus_message_enter_container(message
, 'r', is_ex_prop
? "sasas" : "sasb")) > 0) {
1027 _cleanup_strv_free_
char **argv
= NULL
, **ex_opts
= NULL
;
1031 r
= sd_bus_message_read(message
, "s", &path
);
1035 if (!path_is_absolute(path
))
1036 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
1038 r
= sd_bus_message_read_strv(message
, &argv
);
1042 r
= is_ex_prop
? sd_bus_message_read_strv(message
, &ex_opts
) : sd_bus_message_read(message
, "b", &b
);
1046 r
= sd_bus_message_exit_container(message
);
1050 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1053 c
= new0(ExecCommand
, 1);
1057 c
->path
= strdup(path
);
1063 c
->argv
= TAKE_PTR(argv
);
1066 r
= exec_command_flags_from_strv(ex_opts
, &c
->flags
);
1070 c
->flags
= b
? EXEC_COMMAND_IGNORE_FAILURE
: 0;
1072 path_simplify(c
->path
, false);
1073 exec_command_append_list(exec_command
, c
);
1081 r
= sd_bus_message_exit_container(message
);
1085 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1086 _cleanup_free_
char *buf
= NULL
;
1087 _cleanup_fclose_
FILE *f
= NULL
;
1092 *exec_command
= exec_command_free_list(*exec_command
);
1094 f
= open_memstream_unlocked(&buf
, &size
);
1098 fprintf(f
, "%s=\n", name
);
1100 LIST_FOREACH(command
, c
, *exec_command
) {
1101 _cleanup_free_
char *a
= NULL
, *exec_chars
= NULL
;
1103 exec_chars
= exec_command_flags_to_exec_chars(c
->flags
);
1107 a
= unit_concat_strv(c
->argv
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
);
1111 if (streq_ptr(c
->path
, c
->argv
? c
->argv
[0] : NULL
))
1112 fprintf(f
, "%s=%s%s\n", name
, exec_chars
, a
);
1114 _cleanup_free_
char *t
= NULL
;
1117 p
= unit_escape_setting(c
->path
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
, &t
);
1121 fprintf(f
, "%s=%s@%s %s\n", name
, exec_chars
, p
, a
);
1125 r
= fflush_and_check(f
);
1129 unit_write_setting(u
, flags
, name
, buf
);
1135 static int parse_personality(const char *s
, unsigned long *p
) {
1140 v
= personality_from_string(s
);
1141 if (v
== PERSONALITY_INVALID
)
1148 static const char* mount_propagation_flags_to_string_with_check(unsigned long n
) {
1149 if (!IN_SET(n
, 0, MS_SHARED
, MS_PRIVATE
, MS_SLAVE
))
1152 return mount_propagation_flags_to_string(n
);
1155 static BUS_DEFINE_SET_TRANSIENT(nsec
, "t", uint64_t, nsec_t
, NSEC_FMT
);
1156 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level
, "i", int32_t, int, "%" PRIi32
, log_level_is_valid
);
1158 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno
, "i", int32_t, int, "%" PRIi32
, errno_is_valid
);
1160 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input
, ExecInput
, exec_input_from_string
);
1161 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output
, ExecOutput
, exec_output_from_string
);
1162 static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode
, ExecUtmpMode
, exec_utmp_mode_from_string
);
1163 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system
, ProtectSystem
, protect_system_from_string
);
1164 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home
, ProtectHome
, protect_home_from_string
);
1165 static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode
, ExecKeyringMode
, exec_keyring_mode_from_string
);
1166 static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode
, ExecPreserveMode
, exec_preserve_mode_from_string
);
1167 static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality
, unsigned long, parse_personality
);
1168 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits
, "i", int32_t, int, "%" PRIi32
, secure_bits_to_string_alloc_with_check
);
1169 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability
, "t", uint64_t, uint64_t, "%" PRIu64
, capability_set_to_string_alloc
);
1170 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag
, "t", uint64_t, unsigned long, "%" PRIu64
, namespace_flags_to_string
);
1171 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags
, "t", uint64_t, unsigned long, "%" PRIu64
, mount_propagation_flags_to_string_with_check
);
1173 int bus_exec_context_set_transient_property(
1177 sd_bus_message
*message
,
1178 UnitWriteFlags flags
,
1179 sd_bus_error
*error
) {
1189 flags
|= UNIT_PRIVATE
;
1191 if (streq(name
, "User"))
1192 return bus_set_transient_user_compat(u
, name
, &c
->user
, message
, flags
, error
);
1194 if (streq(name
, "Group"))
1195 return bus_set_transient_user_compat(u
, name
, &c
->group
, message
, flags
, error
);
1197 if (streq(name
, "TTYPath"))
1198 return bus_set_transient_path(u
, name
, &c
->tty_path
, message
, flags
, error
);
1200 if (streq(name
, "RootImage"))
1201 return bus_set_transient_path(u
, name
, &c
->root_image
, message
, flags
, error
);
1203 if (streq(name
, "RootDirectory"))
1204 return bus_set_transient_path(u
, name
, &c
->root_directory
, message
, flags
, error
);
1206 if (streq(name
, "SyslogIdentifier"))
1207 return bus_set_transient_string(u
, name
, &c
->syslog_identifier
, message
, flags
, error
);
1209 if (streq(name
, "LogLevelMax"))
1210 return bus_set_transient_log_level(u
, name
, &c
->log_level_max
, message
, flags
, error
);
1212 if (streq(name
, "LogRateLimitIntervalUSec"))
1213 return bus_set_transient_usec(u
, name
, &c
->log_ratelimit_interval_usec
, message
, flags
, error
);
1215 if (streq(name
, "LogRateLimitBurst"))
1216 return bus_set_transient_unsigned(u
, name
, &c
->log_ratelimit_burst
, message
, flags
, error
);
1218 if (streq(name
, "Personality"))
1219 return bus_set_transient_personality(u
, name
, &c
->personality
, message
, flags
, error
);
1221 if (streq(name
, "StandardInput"))
1222 return bus_set_transient_std_input(u
, name
, &c
->std_input
, message
, flags
, error
);
1224 if (streq(name
, "StandardOutput"))
1225 return bus_set_transient_std_output(u
, name
, &c
->std_output
, message
, flags
, error
);
1227 if (streq(name
, "StandardError"))
1228 return bus_set_transient_std_output(u
, name
, &c
->std_error
, message
, flags
, error
);
1230 if (streq(name
, "IgnoreSIGPIPE"))
1231 return bus_set_transient_bool(u
, name
, &c
->ignore_sigpipe
, message
, flags
, error
);
1233 if (streq(name
, "TTYVHangup"))
1234 return bus_set_transient_bool(u
, name
, &c
->tty_vhangup
, message
, flags
, error
);
1236 if (streq(name
, "TTYReset"))
1237 return bus_set_transient_bool(u
, name
, &c
->tty_reset
, message
, flags
, error
);
1239 if (streq(name
, "TTYVTDisallocate"))
1240 return bus_set_transient_bool(u
, name
, &c
->tty_vt_disallocate
, message
, flags
, error
);
1242 if (streq(name
, "PrivateTmp"))
1243 return bus_set_transient_bool(u
, name
, &c
->private_tmp
, message
, flags
, error
);
1245 if (streq(name
, "PrivateDevices"))
1246 return bus_set_transient_bool(u
, name
, &c
->private_devices
, message
, flags
, error
);
1248 if (streq(name
, "PrivateMounts"))
1249 return bus_set_transient_bool(u
, name
, &c
->private_mounts
, message
, flags
, error
);
1251 if (streq(name
, "PrivateNetwork"))
1252 return bus_set_transient_bool(u
, name
, &c
->private_network
, message
, flags
, error
);
1254 if (streq(name
, "PrivateUsers"))
1255 return bus_set_transient_bool(u
, name
, &c
->private_users
, message
, flags
, error
);
1257 if (streq(name
, "NoNewPrivileges"))
1258 return bus_set_transient_bool(u
, name
, &c
->no_new_privileges
, message
, flags
, error
);
1260 if (streq(name
, "SyslogLevelPrefix"))
1261 return bus_set_transient_bool(u
, name
, &c
->syslog_level_prefix
, message
, flags
, error
);
1263 if (streq(name
, "MemoryDenyWriteExecute"))
1264 return bus_set_transient_bool(u
, name
, &c
->memory_deny_write_execute
, message
, flags
, error
);
1266 if (streq(name
, "RestrictRealtime"))
1267 return bus_set_transient_bool(u
, name
, &c
->restrict_realtime
, message
, flags
, error
);
1269 if (streq(name
, "RestrictSUIDSGID"))
1270 return bus_set_transient_bool(u
, name
, &c
->restrict_suid_sgid
, message
, flags
, error
);
1272 if (streq(name
, "DynamicUser"))
1273 return bus_set_transient_bool(u
, name
, &c
->dynamic_user
, message
, flags
, error
);
1275 if (streq(name
, "RemoveIPC"))
1276 return bus_set_transient_bool(u
, name
, &c
->remove_ipc
, message
, flags
, error
);
1278 if (streq(name
, "ProtectKernelTunables"))
1279 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_tunables
, message
, flags
, error
);
1281 if (streq(name
, "ProtectKernelModules"))
1282 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_modules
, message
, flags
, error
);
1284 if (streq(name
, "ProtectKernelLogs"))
1285 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_logs
, message
, flags
, error
);
1287 if (streq(name
, "ProtectControlGroups"))
1288 return bus_set_transient_bool(u
, name
, &c
->protect_control_groups
, message
, flags
, error
);
1290 if (streq(name
, "MountAPIVFS"))
1291 return bus_set_transient_bool(u
, name
, &c
->mount_apivfs
, message
, flags
, error
);
1293 if (streq(name
, "CPUSchedulingResetOnFork"))
1294 return bus_set_transient_bool(u
, name
, &c
->cpu_sched_reset_on_fork
, message
, flags
, error
);
1296 if (streq(name
, "NonBlocking"))
1297 return bus_set_transient_bool(u
, name
, &c
->non_blocking
, message
, flags
, error
);
1299 if (streq(name
, "LockPersonality"))
1300 return bus_set_transient_bool(u
, name
, &c
->lock_personality
, message
, flags
, error
);
1302 if (streq(name
, "ProtectHostname"))
1303 return bus_set_transient_bool(u
, name
, &c
->protect_hostname
, message
, flags
, error
);
1305 if (streq(name
, "UtmpIdentifier"))
1306 return bus_set_transient_string(u
, name
, &c
->utmp_id
, message
, flags
, error
);
1308 if (streq(name
, "UtmpMode"))
1309 return bus_set_transient_utmp_mode(u
, name
, &c
->utmp_mode
, message
, flags
, error
);
1311 if (streq(name
, "PAMName"))
1312 return bus_set_transient_string(u
, name
, &c
->pam_name
, message
, flags
, error
);
1314 if (streq(name
, "TimerSlackNSec"))
1315 return bus_set_transient_nsec(u
, name
, &c
->timer_slack_nsec
, message
, flags
, error
);
1317 if (streq(name
, "ProtectSystem"))
1318 return bus_set_transient_protect_system(u
, name
, &c
->protect_system
, message
, flags
, error
);
1320 if (streq(name
, "ProtectHome"))
1321 return bus_set_transient_protect_home(u
, name
, &c
->protect_home
, message
, flags
, error
);
1323 if (streq(name
, "KeyringMode"))
1324 return bus_set_transient_keyring_mode(u
, name
, &c
->keyring_mode
, message
, flags
, error
);
1326 if (streq(name
, "RuntimeDirectoryPreserve"))
1327 return bus_set_transient_preserve_mode(u
, name
, &c
->runtime_directory_preserve_mode
, message
, flags
, error
);
1329 if (streq(name
, "UMask"))
1330 return bus_set_transient_mode_t(u
, name
, &c
->umask
, message
, flags
, error
);
1332 if (streq(name
, "RuntimeDirectoryMode"))
1333 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_RUNTIME
].mode
, message
, flags
, error
);
1335 if (streq(name
, "StateDirectoryMode"))
1336 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_STATE
].mode
, message
, flags
, error
);
1338 if (streq(name
, "CacheDirectoryMode"))
1339 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CACHE
].mode
, message
, flags
, error
);
1341 if (streq(name
, "LogsDirectoryMode"))
1342 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_LOGS
].mode
, message
, flags
, error
);
1344 if (streq(name
, "ConfigurationDirectoryMode"))
1345 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
, message
, flags
, error
);
1347 if (streq(name
, "SELinuxContext"))
1348 return bus_set_transient_string(u
, name
, &c
->selinux_context
, message
, flags
, error
);
1350 if (streq(name
, "SecureBits"))
1351 return bus_set_transient_secure_bits(u
, name
, &c
->secure_bits
, message
, flags
, error
);
1353 if (streq(name
, "CapabilityBoundingSet"))
1354 return bus_set_transient_capability(u
, name
, &c
->capability_bounding_set
, message
, flags
, error
);
1356 if (streq(name
, "AmbientCapabilities"))
1357 return bus_set_transient_capability(u
, name
, &c
->capability_ambient_set
, message
, flags
, error
);
1359 if (streq(name
, "RestrictNamespaces"))
1360 return bus_set_transient_namespace_flag(u
, name
, &c
->restrict_namespaces
, message
, flags
, error
);
1362 if (streq(name
, "MountFlags"))
1363 return bus_set_transient_mount_flags(u
, name
, &c
->mount_flags
, message
, flags
, error
);
1365 if (streq(name
, "NetworkNamespacePath"))
1366 return bus_set_transient_path(u
, name
, &c
->network_namespace_path
, message
, flags
, error
);
1368 if (streq(name
, "SupplementaryGroups")) {
1369 _cleanup_strv_free_
char **l
= NULL
;
1372 r
= sd_bus_message_read_strv(message
, &l
);
1377 if (!isempty(*p
) && !valid_user_group_name_or_id_compat(*p
))
1378 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
1379 "Invalid supplementary group names");
1381 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1382 if (strv_isempty(l
)) {
1383 c
->supplementary_groups
= strv_free(c
->supplementary_groups
);
1384 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1386 _cleanup_free_
char *joined
= NULL
;
1388 r
= strv_extend_strv(&c
->supplementary_groups
, l
, true);
1392 joined
= strv_join(c
->supplementary_groups
, " ");
1396 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s", name
, joined
);
1402 } else if (streq(name
, "SyslogLevel")) {
1405 r
= sd_bus_message_read(message
, "i", &level
);
1409 if (!log_level_is_valid(level
))
1410 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log level value out of range");
1412 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1413 c
->syslog_priority
= (c
->syslog_priority
& LOG_FACMASK
) | level
;
1414 unit_write_settingf(u
, flags
, name
, "SyslogLevel=%i", level
);
1419 } else if (streq(name
, "SyslogFacility")) {
1422 r
= sd_bus_message_read(message
, "i", &facility
);
1426 if (!log_facility_unshifted_is_valid(facility
))
1427 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log facility value out of range");
1429 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1430 c
->syslog_priority
= (facility
<< 3) | LOG_PRI(c
->syslog_priority
);
1431 unit_write_settingf(u
, flags
, name
, "SyslogFacility=%i", facility
);
1436 } else if (streq(name
, "LogExtraFields")) {
1439 r
= sd_bus_message_enter_container(message
, 'a', "ay");
1444 _cleanup_free_
void *copy
= NULL
;
1450 /* Note that we expect a byte array for each field, instead of a string. That's because on the
1451 * lower-level journal fields can actually contain binary data and are not restricted to text,
1452 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
1453 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
1454 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
1455 * limitation, should a good, valid usecase arise. */
1457 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
1463 if (memchr(p
, 0, sz
))
1464 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains zero byte");
1466 eq
= memchr(p
, '=', sz
);
1468 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains no '=' character");
1469 if (!journal_field_valid(p
, eq
- (const char*) p
, false))
1470 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field invalid");
1472 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1473 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
1476 c
->log_extra_fields
= t
;
1479 copy
= malloc(sz
+ 1);
1483 memcpy(copy
, p
, sz
);
1484 ((uint8_t*) copy
)[sz
] = 0;
1486 if (!utf8_is_valid(copy
))
1487 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field is not valid UTF-8");
1489 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1490 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE(copy
, sz
);
1491 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
, name
, "LogExtraFields=%s", (char*) copy
);
1499 r
= sd_bus_message_exit_container(message
);
1503 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && n
== 0) {
1504 exec_context_free_log_extra_fields(c
);
1505 unit_write_setting(u
, flags
, name
, "LogExtraFields=");
1513 if (streq(name
, "SystemCallErrorNumber"))
1514 return bus_set_transient_errno(u
, name
, &c
->syscall_errno
, message
, flags
, error
);
1516 if (streq(name
, "SystemCallFilter")) {
1518 _cleanup_strv_free_
char **l
= NULL
;
1520 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1524 r
= sd_bus_message_read(message
, "b", &whitelist
);
1528 r
= sd_bus_message_read_strv(message
, &l
);
1532 r
= sd_bus_message_exit_container(message
);
1536 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1537 _cleanup_free_
char *joined
= NULL
;
1538 SeccompParseFlags invert_flag
= whitelist
? 0 : SECCOMP_PARSE_INVERT
;
1541 if (strv_isempty(l
)) {
1542 c
->syscall_whitelist
= false;
1543 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
1545 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=");
1549 if (!c
->syscall_filter
) {
1550 c
->syscall_filter
= hashmap_new(NULL
);
1551 if (!c
->syscall_filter
)
1554 c
->syscall_whitelist
= whitelist
;
1556 if (c
->syscall_whitelist
) {
1557 r
= seccomp_parse_syscall_filter("@default",
1560 SECCOMP_PARSE_WHITELIST
| invert_flag
,
1568 STRV_FOREACH(s
, l
) {
1569 _cleanup_free_
char *n
= NULL
;
1572 r
= parse_syscall_and_errno(*s
, &n
, &e
);
1576 r
= seccomp_parse_syscall_filter(n
,
1579 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0) | invert_flag
,
1586 joined
= strv_join(l
, " ");
1590 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=%s%s", whitelist
? "" : "~", joined
);
1595 } else if (streq(name
, "SystemCallArchitectures")) {
1596 _cleanup_strv_free_
char **l
= NULL
;
1598 r
= sd_bus_message_read_strv(message
, &l
);
1602 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1603 _cleanup_free_
char *joined
= NULL
;
1605 if (strv_isempty(l
))
1606 c
->syscall_archs
= set_free(c
->syscall_archs
);
1610 r
= set_ensure_allocated(&c
->syscall_archs
, NULL
);
1614 STRV_FOREACH(s
, l
) {
1617 r
= seccomp_arch_from_string(*s
, &a
);
1621 r
= set_put(c
->syscall_archs
, UINT32_TO_PTR(a
+ 1));
1628 joined
= strv_join(l
, " ");
1632 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
1637 } else if (streq(name
, "RestrictAddressFamilies")) {
1639 _cleanup_strv_free_
char **l
= NULL
;
1641 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1645 r
= sd_bus_message_read(message
, "b", &whitelist
);
1649 r
= sd_bus_message_read_strv(message
, &l
);
1653 r
= sd_bus_message_exit_container(message
);
1657 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1658 _cleanup_free_
char *joined
= NULL
;
1661 if (strv_isempty(l
)) {
1662 c
->address_families_whitelist
= false;
1663 c
->address_families
= set_free(c
->address_families
);
1665 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=");
1669 if (!c
->address_families
) {
1670 c
->address_families
= set_new(NULL
);
1671 if (!c
->address_families
)
1674 c
->address_families_whitelist
= whitelist
;
1677 STRV_FOREACH(s
, l
) {
1680 af
= af_from_name(*s
);
1684 if (whitelist
== c
->address_families_whitelist
) {
1685 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
1689 (void) set_remove(c
->address_families
, INT_TO_PTR(af
));
1692 joined
= strv_join(l
, " ");
1696 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=%s%s", whitelist
? "" : "~", joined
);
1702 if (STR_IN_SET(name
, "CPUAffinity", "NUMAMask")) {
1705 bool affinity
= streq(name
, "CPUAffinity");
1706 _cleanup_(cpu_set_reset
) CPUSet set
= {};
1708 r
= sd_bus_message_read_array(message
, 'y', &a
, &n
);
1712 r
= cpu_set_from_dbus(a
, n
, &set
);
1716 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1718 cpu_set_reset(affinity
? &c
->cpu_set
: &c
->numa_policy
.nodes
);
1719 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1721 _cleanup_free_
char *str
= NULL
;
1723 str
= cpu_set_to_string(&set
);
1727 /* We forego any optimizations here, and always create the structure using
1728 * cpu_set_add_all(), because we don't want to care if the existing size we
1729 * got over dbus is appropriate. */
1730 r
= cpu_set_add_all(affinity
? &c
->cpu_set
: &c
->numa_policy
.nodes
, &set
);
1734 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, str
);
1740 } else if (streq(name
, "NUMAPolicy")) {
1743 r
= sd_bus_message_read(message
, "i", &type
);
1747 if (!mpol_is_valid(type
))
1748 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid NUMAPolicy value: %i", type
);
1750 if (!UNIT_WRITE_FLAGS_NOOP(flags
))
1751 c
->numa_policy
.type
= type
;
1754 } else if (streq(name
, "Nice")) {
1757 r
= sd_bus_message_read(message
, "i", &q
);
1761 if (!nice_is_valid(q
))
1762 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid Nice value: %i", q
);
1764 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1768 unit_write_settingf(u
, flags
, name
, "Nice=%i", q
);
1773 } else if (streq(name
, "CPUSchedulingPolicy")) {
1776 r
= sd_bus_message_read(message
, "i", &q
);
1780 if (!sched_policy_is_valid(q
))
1781 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling policy: %i", q
);
1783 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1784 _cleanup_free_
char *s
= NULL
;
1786 r
= sched_policy_to_string_alloc(q
, &s
);
1790 c
->cpu_sched_policy
= q
;
1791 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(q
), sched_get_priority_max(q
));
1792 c
->cpu_sched_set
= true;
1794 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPolicy=%s", s
);
1799 } else if (streq(name
, "CPUSchedulingPriority")) {
1800 int32_t p
, min
, max
;
1802 r
= sd_bus_message_read(message
, "i", &p
);
1806 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1807 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1808 if (p
< min
|| p
> max
)
1809 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling priority: %i", p
);
1811 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1812 c
->cpu_sched_priority
= p
;
1813 c
->cpu_sched_set
= true;
1815 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPriority=%i", p
);
1820 } else if (streq(name
, "IOSchedulingClass")) {
1823 r
= sd_bus_message_read(message
, "i", &q
);
1827 if (!ioprio_class_is_valid(q
))
1828 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling class: %i", q
);
1830 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1831 _cleanup_free_
char *s
= NULL
;
1833 r
= ioprio_class_to_string_alloc(q
, &s
);
1837 c
->ioprio
= IOPRIO_PRIO_VALUE(q
, IOPRIO_PRIO_DATA(c
->ioprio
));
1838 c
->ioprio_set
= true;
1840 unit_write_settingf(u
, flags
, name
, "IOSchedulingClass=%s", s
);
1845 } else if (streq(name
, "IOSchedulingPriority")) {
1848 r
= sd_bus_message_read(message
, "i", &p
);
1852 if (!ioprio_priority_is_valid(p
))
1853 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling priority: %i", p
);
1855 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1856 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), p
);
1857 c
->ioprio_set
= true;
1859 unit_write_settingf(u
, flags
, name
, "IOSchedulingPriority=%i", p
);
1864 } else if (streq(name
, "WorkingDirectory")) {
1868 r
= sd_bus_message_read(message
, "s", &s
);
1878 if (!isempty(s
) && !streq(s
, "~") && !path_is_absolute(s
))
1879 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "WorkingDirectory= expects an absolute path or '~'");
1881 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1882 if (streq(s
, "~")) {
1883 c
->working_directory
= mfree(c
->working_directory
);
1884 c
->working_directory_home
= true;
1886 r
= free_and_strdup(&c
->working_directory
, empty_to_null(s
));
1890 c
->working_directory_home
= false;
1893 c
->working_directory_missing_ok
= missing_ok
;
1894 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "WorkingDirectory=%s%s", missing_ok
? "-" : "", s
);
1899 } else if (STR_IN_SET(name
,
1900 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
1903 r
= sd_bus_message_read(message
, "s", &s
);
1907 if (!isempty(s
) && !fdname_is_valid(s
))
1908 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid file descriptor name");
1910 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1912 if (streq(name
, "StandardInputFileDescriptorName")) {
1913 r
= free_and_strdup(c
->stdio_fdname
+ STDIN_FILENO
, empty_to_null(s
));
1917 c
->std_input
= EXEC_INPUT_NAMED_FD
;
1918 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=fd:%s", exec_context_fdname(c
, STDIN_FILENO
));
1920 } else if (streq(name
, "StandardOutputFileDescriptorName")) {
1921 r
= free_and_strdup(c
->stdio_fdname
+ STDOUT_FILENO
, empty_to_null(s
));
1925 c
->std_output
= EXEC_OUTPUT_NAMED_FD
;
1926 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=fd:%s", exec_context_fdname(c
, STDOUT_FILENO
));
1929 assert(streq(name
, "StandardErrorFileDescriptorName"));
1931 r
= free_and_strdup(&c
->stdio_fdname
[STDERR_FILENO
], empty_to_null(s
));
1935 c
->std_error
= EXEC_OUTPUT_NAMED_FD
;
1936 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=fd:%s", exec_context_fdname(c
, STDERR_FILENO
));
1942 } else if (STR_IN_SET(name
,
1943 "StandardInputFile",
1944 "StandardOutputFile", "StandardOutputFileToAppend",
1945 "StandardErrorFile", "StandardErrorFileToAppend")) {
1948 r
= sd_bus_message_read(message
, "s", &s
);
1953 if (!path_is_absolute(s
))
1954 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute", s
);
1955 if (!path_is_normalized(s
))
1956 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not normalized", s
);
1959 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1961 if (streq(name
, "StandardInputFile")) {
1962 r
= free_and_strdup(&c
->stdio_file
[STDIN_FILENO
], empty_to_null(s
));
1966 c
->std_input
= EXEC_INPUT_FILE
;
1967 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=file:%s", s
);
1969 } else if (STR_IN_SET(name
, "StandardOutputFile", "StandardOutputFileToAppend")) {
1970 r
= free_and_strdup(&c
->stdio_file
[STDOUT_FILENO
], empty_to_null(s
));
1974 if (streq(name
, "StandardOutputFile")) {
1975 c
->std_output
= EXEC_OUTPUT_FILE
;
1976 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=file:%s", s
);
1978 assert(streq(name
, "StandardOutputFileToAppend"));
1979 c
->std_output
= EXEC_OUTPUT_FILE_APPEND
;
1980 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=append:%s", s
);
1983 assert(STR_IN_SET(name
, "StandardErrorFile", "StandardErrorFileToAppend"));
1985 r
= free_and_strdup(&c
->stdio_file
[STDERR_FILENO
], empty_to_null(s
));
1989 if (streq(name
, "StandardErrorFile")) {
1990 c
->std_error
= EXEC_OUTPUT_FILE
;
1991 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=file:%s", s
);
1993 assert(streq(name
, "StandardErrorFileToAppend"));
1994 c
->std_error
= EXEC_OUTPUT_FILE_APPEND
;
1995 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=append:%s", s
);
2002 } else if (streq(name
, "StandardInputData")) {
2006 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
2010 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2011 _cleanup_free_
char *encoded
= NULL
;
2014 c
->stdin_data
= mfree(c
->stdin_data
);
2015 c
->stdin_data_size
= 0;
2017 unit_write_settingf(u
, flags
, name
, "StandardInputData=");
2022 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
2023 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
)
2026 n
= base64mem(p
, sz
, &encoded
);
2030 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
2034 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
2037 c
->stdin_data_size
+= sz
;
2039 unit_write_settingf(u
, flags
, name
, "StandardInputData=%s", encoded
);
2045 } else if (streq(name
, "Environment")) {
2047 _cleanup_strv_free_
char **l
= NULL
;
2049 r
= sd_bus_message_read_strv(message
, &l
);
2053 if (!strv_env_is_valid(l
))
2054 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment block.");
2056 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2057 if (strv_isempty(l
)) {
2058 c
->environment
= strv_free(c
->environment
);
2059 unit_write_setting(u
, flags
, name
, "Environment=");
2061 _cleanup_free_
char *joined
= NULL
;
2064 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
2068 e
= strv_env_merge(2, c
->environment
, l
);
2072 strv_free_and_replace(c
->environment
, e
);
2073 unit_write_settingf(u
, flags
, name
, "Environment=%s", joined
);
2079 } else if (streq(name
, "UnsetEnvironment")) {
2081 _cleanup_strv_free_
char **l
= NULL
;
2083 r
= sd_bus_message_read_strv(message
, &l
);
2087 if (!strv_env_name_or_assignment_is_valid(l
))
2088 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid UnsetEnvironment= list.");
2090 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2091 if (strv_isempty(l
)) {
2092 c
->unset_environment
= strv_free(c
->unset_environment
);
2093 unit_write_setting(u
, flags
, name
, "UnsetEnvironment=");
2095 _cleanup_free_
char *joined
= NULL
;
2098 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
2102 e
= strv_env_merge(2, c
->unset_environment
, l
);
2106 strv_free_and_replace(c
->unset_environment
, e
);
2107 unit_write_settingf(u
, flags
, name
, "UnsetEnvironment=%s", joined
);
2113 } else if (streq(name
, "OOMScoreAdjust")) {
2116 r
= sd_bus_message_read(message
, "i", &oa
);
2120 if (!oom_score_adjust_is_valid(oa
))
2121 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "OOM score adjust value out of range");
2123 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2124 c
->oom_score_adjust
= oa
;
2125 c
->oom_score_adjust_set
= true;
2126 unit_write_settingf(u
, flags
, name
, "OOMScoreAdjust=%i", oa
);
2131 } else if (streq(name
, "EnvironmentFiles")) {
2133 _cleanup_free_
char *joined
= NULL
;
2134 _cleanup_fclose_
FILE *f
= NULL
;
2135 _cleanup_strv_free_
char **l
= NULL
;
2139 r
= sd_bus_message_enter_container(message
, 'a', "(sb)");
2143 f
= open_memstream_unlocked(&joined
, &size
);
2147 fputs("EnvironmentFile=\n", f
);
2149 STRV_FOREACH(i
, c
->environment_files
) {
2150 _cleanup_free_
char *q
= NULL
;
2152 q
= specifier_escape(*i
);
2156 fprintf(f
, "EnvironmentFile=%s\n", q
);
2159 while ((r
= sd_bus_message_enter_container(message
, 'r', "sb")) > 0) {
2163 r
= sd_bus_message_read(message
, "sb", &path
, &b
);
2167 r
= sd_bus_message_exit_container(message
);
2171 if (!path_is_absolute(path
))
2172 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
2174 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2175 _cleanup_free_
char *q
= NULL
, *buf
= NULL
;
2177 buf
= strjoin(b
? "-" : "", path
);
2181 q
= specifier_escape(buf
);
2185 fprintf(f
, "EnvironmentFile=%s\n", q
);
2187 r
= strv_consume(&l
, TAKE_PTR(buf
));
2195 r
= sd_bus_message_exit_container(message
);
2199 r
= fflush_and_check(f
);
2203 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2204 if (strv_isempty(l
)) {
2205 c
->environment_files
= strv_free(c
->environment_files
);
2206 unit_write_setting(u
, flags
, name
, "EnvironmentFile=");
2208 r
= strv_extend_strv(&c
->environment_files
, l
, true);
2212 unit_write_setting(u
, flags
, name
, joined
);
2218 } else if (streq(name
, "PassEnvironment")) {
2220 _cleanup_strv_free_
char **l
= NULL
;
2222 r
= sd_bus_message_read_strv(message
, &l
);
2226 if (!strv_env_name_is_valid(l
))
2227 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PassEnvironment= block.");
2229 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2230 if (strv_isempty(l
)) {
2231 c
->pass_environment
= strv_free(c
->pass_environment
);
2232 unit_write_setting(u
, flags
, name
, "PassEnvironment=");
2234 _cleanup_free_
char *joined
= NULL
;
2236 r
= strv_extend_strv(&c
->pass_environment
, l
, true);
2240 /* We write just the new settings out to file, with unresolved specifiers. */
2241 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2245 unit_write_settingf(u
, flags
, name
, "PassEnvironment=%s", joined
);
2251 } else if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
2252 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) {
2253 _cleanup_strv_free_
char **l
= NULL
;
2257 r
= sd_bus_message_read_strv(message
, &l
);
2261 STRV_FOREACH(p
, l
) {
2265 offset
= i
[0] == '-';
2266 offset
+= i
[offset
] == '+';
2267 if (!path_is_absolute(i
+ offset
))
2268 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
2270 path_simplify(i
+ offset
, false);
2273 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2274 if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadWritePaths"))
2275 dirs
= &c
->read_write_paths
;
2276 else if (STR_IN_SET(name
, "ReadOnlyDirectories", "ReadOnlyPaths"))
2277 dirs
= &c
->read_only_paths
;
2278 else /* "InaccessiblePaths" */
2279 dirs
= &c
->inaccessible_paths
;
2281 if (strv_isempty(l
)) {
2282 *dirs
= strv_free(*dirs
);
2283 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2285 _cleanup_free_
char *joined
= NULL
;
2287 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2291 r
= strv_extend_strv(dirs
, l
, true);
2295 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2301 } else if (STR_IN_SET(name
, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
2302 _cleanup_strv_free_
char **l
= NULL
;
2305 r
= sd_bus_message_read_strv(message
, &l
);
2309 STRV_FOREACH(p
, l
) {
2310 if (!path_is_normalized(*p
))
2311 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is not normalized: %s", name
, *p
);
2313 if (path_is_absolute(*p
))
2314 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is absolute: %s", name
, *p
);
2316 if (path_startswith(*p
, "private"))
2317 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path can't be 'private': %s", name
, *p
);
2320 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2321 ExecDirectoryType i
;
2324 assert_se((i
= exec_directory_type_from_string(name
)) >= 0);
2325 d
= c
->directories
+ i
;
2327 if (strv_isempty(l
)) {
2328 d
->paths
= strv_free(d
->paths
);
2329 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2331 _cleanup_free_
char *joined
= NULL
;
2333 r
= strv_extend_strv(&d
->paths
, l
, true);
2337 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2341 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2347 } else if (STR_IN_SET(name
, "AppArmorProfile", "SmackProcessLabel")) {
2351 r
= sd_bus_message_read(message
, "(bs)", &ignore
, &s
);
2355 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2359 if (streq(name
, "AppArmorProfile")) {
2360 p
= &c
->apparmor_profile
;
2361 b
= &c
->apparmor_profile_ignore
;
2362 } else { /* "SmackProcessLabel" */
2363 p
= &c
->smack_process_label
;
2364 b
= &c
->smack_process_label_ignore
;
2371 if (free_and_strdup(p
, s
) < 0)
2376 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s%s", name
, ignore
? "-" : "", strempty(s
));
2381 } else if (STR_IN_SET(name
, "BindPaths", "BindReadOnlyPaths")) {
2382 const char *source
, *destination
;
2384 uint64_t mount_flags
;
2387 r
= sd_bus_message_enter_container(message
, 'a', "(ssbt)");
2391 while ((r
= sd_bus_message_read(message
, "(ssbt)", &source
, &destination
, &ignore_enoent
, &mount_flags
)) > 0) {
2393 if (!path_is_absolute(source
))
2394 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
2395 if (!path_is_absolute(destination
))
2396 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
2397 if (!IN_SET(mount_flags
, 0, MS_REC
))
2398 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount flags.");
2400 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2401 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
2403 .source
= strdup(source
),
2404 .destination
= strdup(destination
),
2405 .read_only
= !!strstr(name
, "ReadOnly"),
2406 .recursive
= !!(mount_flags
& MS_REC
),
2407 .ignore_enoent
= ignore_enoent
,
2412 unit_write_settingf(
2413 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2416 ignore_enoent
? "-" : "",
2419 (mount_flags
& MS_REC
) ? "rbind" : "norbind");
2427 r
= sd_bus_message_exit_container(message
);
2432 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
2433 c
->bind_mounts
= NULL
;
2434 c
->n_bind_mounts
= 0;
2436 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2441 } else if (streq(name
, "TemporaryFileSystem")) {
2442 const char *path
, *options
;
2445 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
2449 while ((r
= sd_bus_message_read(message
, "(ss)", &path
, &options
)) > 0) {
2451 if (!path_is_absolute(path
))
2452 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Mount point %s is not absolute.", path
);
2454 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2455 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, options
);
2459 unit_write_settingf(
2460 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2472 r
= sd_bus_message_exit_container(message
);
2477 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
2478 c
->temporary_filesystems
= NULL
;
2479 c
->n_temporary_filesystems
= 0;
2481 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2486 } else if ((suffix
= startswith(name
, "Limit"))) {
2487 const char *soft
= NULL
;
2490 ri
= rlimit_from_string(suffix
);
2492 soft
= endswith(suffix
, "Soft");
2496 n
= strndupa(suffix
, soft
- suffix
);
2497 ri
= rlimit_from_string(n
);
2499 name
= strjoina("Limit", n
);
2507 r
= sd_bus_message_read(message
, "t", &rl
);
2511 if (rl
== (uint64_t) -1)
2516 if ((uint64_t) x
!= rl
)
2520 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2521 _cleanup_free_
char *f
= NULL
;
2524 if (c
->rlimit
[ri
]) {
2525 nl
= *c
->rlimit
[ri
];
2532 /* When the resource limit is not initialized yet, then assign the value to both fields */
2533 nl
= (struct rlimit
) {
2538 r
= rlimit_format(&nl
, &f
);
2543 *c
->rlimit
[ri
] = nl
;
2545 c
->rlimit
[ri
] = newdup(struct rlimit
, &nl
, 1);
2550 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, f
);