1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
10 #include <stdio_ext.h>
17 #include "alloc-util.h"
20 #include "capability-util.h"
21 #include "cpu-set-util.h"
22 #include "dbus-execute.h"
23 #include "dbus-util.h"
25 #include "errno-list.h"
30 #include "hexdecoct.h"
33 #include "journal-util.h"
35 #include "mount-util.h"
36 #include "namespace.h"
37 #include "parse-util.h"
38 #include "path-util.h"
39 #include "process-util.h"
40 #include "rlimit-util.h"
42 #include "seccomp-util.h"
44 #include "securebits-util.h"
45 #include "specifier.h"
47 #include "syslog-util.h"
48 #include "unit-printf.h"
49 #include "user-util.h"
52 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output
, exec_output
, ExecOutput
);
53 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input
, exec_input
, ExecInput
);
54 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
);
55 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
);
56 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
);
57 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home
, protect_home
, ProtectHome
);
58 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system
, protect_system
, ProtectSystem
);
59 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality
, personality
, unsigned long);
60 static BUS_DEFINE_PROPERTY_GET(property_get_ioprio
, "i", ExecContext
, exec_context_get_effective_ioprio
);
61 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class
, "i", ExecContext
, exec_context_get_effective_ioprio
, IOPRIO_PRIO_CLASS
);
62 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority
, "i", ExecContext
, exec_context_get_effective_ioprio
, IOPRIO_PRIO_DATA
);
63 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string
, "s", NULL
);
64 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level
, "i", int, LOG_PRI
);
65 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility
, "i", int, LOG_FAC
);
67 static int property_get_environment_files(
70 const char *interface
,
72 sd_bus_message
*reply
,
74 sd_bus_error
*error
) {
76 ExecContext
*c
= userdata
;
84 r
= sd_bus_message_open_container(reply
, 'a', "(sb)");
88 STRV_FOREACH(j
, c
->environment_files
) {
91 r
= sd_bus_message_append(reply
, "(sb)", fn
[0] == '-' ? fn
+ 1 : fn
, fn
[0] == '-');
96 return sd_bus_message_close_container(reply
);
99 static int property_get_oom_score_adjust(
102 const char *interface
,
103 const char *property
,
104 sd_bus_message
*reply
,
106 sd_bus_error
*error
) {
108 ExecContext
*c
= userdata
;
115 if (c
->oom_score_adjust_set
)
116 n
= c
->oom_score_adjust
;
118 _cleanup_free_
char *t
= NULL
;
121 if (read_one_line_file("/proc/self/oom_score_adj", &t
) >= 0)
125 return sd_bus_message_append(reply
, "i", n
);
128 static int property_get_nice(
131 const char *interface
,
132 const char *property
,
133 sd_bus_message
*reply
,
135 sd_bus_error
*error
) {
137 ExecContext
*c
= userdata
;
148 n
= getpriority(PRIO_PROCESS
, 0);
153 return sd_bus_message_append(reply
, "i", n
);
156 static int property_get_cpu_sched_policy(
159 const char *interface
,
160 const char *property
,
161 sd_bus_message
*reply
,
163 sd_bus_error
*error
) {
165 ExecContext
*c
= userdata
;
172 if (c
->cpu_sched_set
)
173 n
= c
->cpu_sched_policy
;
175 n
= sched_getscheduler(0);
180 return sd_bus_message_append(reply
, "i", n
);
183 static int property_get_cpu_sched_priority(
186 const char *interface
,
187 const char *property
,
188 sd_bus_message
*reply
,
190 sd_bus_error
*error
) {
192 ExecContext
*c
= userdata
;
199 if (c
->cpu_sched_set
)
200 n
= c
->cpu_sched_priority
;
202 struct sched_param p
= {};
204 if (sched_getparam(0, &p
) >= 0)
205 n
= p
.sched_priority
;
210 return sd_bus_message_append(reply
, "i", n
);
213 static int property_get_cpu_affinity(
216 const char *interface
,
217 const char *property
,
218 sd_bus_message
*reply
,
220 sd_bus_error
*error
) {
222 ExecContext
*c
= userdata
;
228 return sd_bus_message_append_array(reply
, 'y', c
->cpuset
, CPU_ALLOC_SIZE(c
->cpuset_ncpus
));
231 static int property_get_timer_slack_nsec(
234 const char *interface
,
235 const char *property
,
236 sd_bus_message
*reply
,
238 sd_bus_error
*error
) {
240 ExecContext
*c
= userdata
;
247 if (c
->timer_slack_nsec
!= NSEC_INFINITY
)
248 u
= (uint64_t) c
->timer_slack_nsec
;
250 u
= (uint64_t) prctl(PR_GET_TIMERSLACK
);
252 return sd_bus_message_append(reply
, "t", u
);
255 static int property_get_syscall_filter(
258 const char *interface
,
259 const char *property
,
260 sd_bus_message
*reply
,
262 sd_bus_error
*error
) {
264 ExecContext
*c
= userdata
;
265 _cleanup_strv_free_
char **l
= NULL
;
277 r
= sd_bus_message_open_container(reply
, 'r', "bas");
281 r
= sd_bus_message_append(reply
, "b", c
->syscall_whitelist
);
286 HASHMAP_FOREACH_KEY(val
, id
, c
->syscall_filter
, i
) {
287 _cleanup_free_
char *name
= NULL
;
288 const char *e
= NULL
;
290 int num
= PTR_TO_INT(val
);
292 name
= seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE
, PTR_TO_INT(id
) - 1);
297 e
= errno_to_name(num
);
299 s
= strjoin(name
, ":", e
);
303 r
= asprintf(&s
, "%s:%d", name
, num
);
310 r
= strv_consume(&l
, s
);
318 r
= sd_bus_message_append_strv(reply
, l
);
322 return sd_bus_message_close_container(reply
);
325 static int property_get_syscall_archs(
328 const char *interface
,
329 const char *property
,
330 sd_bus_message
*reply
,
332 sd_bus_error
*error
) {
334 ExecContext
*c
= userdata
;
335 _cleanup_strv_free_
char **l
= NULL
;
348 SET_FOREACH(id
, c
->syscall_archs
, i
) {
351 name
= seccomp_arch_to_string(PTR_TO_UINT32(id
) - 1);
355 r
= strv_extend(&l
, name
);
363 r
= sd_bus_message_append_strv(reply
, l
);
370 static int property_get_selinux_context(
373 const char *interface
,
374 const char *property
,
375 sd_bus_message
*reply
,
377 sd_bus_error
*error
) {
379 ExecContext
*c
= userdata
;
385 return sd_bus_message_append(reply
, "(bs)", c
->selinux_context_ignore
, c
->selinux_context
);
388 static int property_get_apparmor_profile(
391 const char *interface
,
392 const char *property
,
393 sd_bus_message
*reply
,
395 sd_bus_error
*error
) {
397 ExecContext
*c
= userdata
;
403 return sd_bus_message_append(reply
, "(bs)", c
->apparmor_profile_ignore
, c
->apparmor_profile
);
406 static int property_get_smack_process_label(
409 const char *interface
,
410 const char *property
,
411 sd_bus_message
*reply
,
413 sd_bus_error
*error
) {
415 ExecContext
*c
= userdata
;
421 return sd_bus_message_append(reply
, "(bs)", c
->smack_process_label_ignore
, c
->smack_process_label
);
424 static int property_get_address_families(
427 const char *interface
,
428 const char *property
,
429 sd_bus_message
*reply
,
431 sd_bus_error
*error
) {
433 ExecContext
*c
= userdata
;
434 _cleanup_strv_free_
char **l
= NULL
;
443 r
= sd_bus_message_open_container(reply
, 'r', "bas");
447 r
= sd_bus_message_append(reply
, "b", c
->address_families_whitelist
);
451 SET_FOREACH(af
, c
->address_families
, i
) {
454 name
= af_to_name(PTR_TO_INT(af
));
458 r
= strv_extend(&l
, name
);
465 r
= sd_bus_message_append_strv(reply
, l
);
469 return sd_bus_message_close_container(reply
);
472 static int property_get_working_directory(
475 const char *interface
,
476 const char *property
,
477 sd_bus_message
*reply
,
479 sd_bus_error
*error
) {
481 ExecContext
*c
= userdata
;
488 if (c
->working_directory_home
)
491 wd
= c
->working_directory
;
493 if (c
->working_directory_missing_ok
)
494 wd
= strjoina("!", wd
);
496 return sd_bus_message_append(reply
, "s", wd
);
499 static int property_get_stdio_fdname(
502 const char *interface
,
503 const char *property
,
504 sd_bus_message
*reply
,
506 sd_bus_error
*error
) {
508 ExecContext
*c
= userdata
;
516 if (streq(property
, "StandardInputFileDescriptorName"))
517 fileno
= STDIN_FILENO
;
518 else if (streq(property
, "StandardOutputFileDescriptorName"))
519 fileno
= STDOUT_FILENO
;
521 assert(streq(property
, "StandardErrorFileDescriptorName"));
522 fileno
= STDERR_FILENO
;
525 return sd_bus_message_append(reply
, "s", exec_context_fdname(c
, fileno
));
528 static int property_get_input_data(
531 const char *interface
,
532 const char *property
,
533 sd_bus_message
*reply
,
535 sd_bus_error
*error
) {
537 ExecContext
*c
= userdata
;
544 return sd_bus_message_append_array(reply
, 'y', c
->stdin_data
, c
->stdin_data_size
);
547 static int property_get_bind_paths(
550 const char *interface
,
551 const char *property
,
552 sd_bus_message
*reply
,
554 sd_bus_error
*error
) {
556 ExecContext
*c
= userdata
;
566 ro
= !!strstr(property
, "ReadOnly");
568 r
= sd_bus_message_open_container(reply
, 'a', "(ssbt)");
572 for (i
= 0; i
< c
->n_bind_mounts
; i
++) {
574 if (ro
!= c
->bind_mounts
[i
].read_only
)
577 r
= sd_bus_message_append(
579 c
->bind_mounts
[i
].source
,
580 c
->bind_mounts
[i
].destination
,
581 c
->bind_mounts
[i
].ignore_enoent
,
582 c
->bind_mounts
[i
].recursive
? (uint64_t) MS_REC
: (uint64_t) 0);
587 return sd_bus_message_close_container(reply
);
590 static int property_get_temporary_filesystems(
593 const char *interface
,
594 const char *property
,
595 sd_bus_message
*reply
,
597 sd_bus_error
*error
) {
599 ExecContext
*c
= userdata
;
608 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
612 for (i
= 0; i
< c
->n_temporary_filesystems
; i
++) {
613 TemporaryFileSystem
*t
= c
->temporary_filesystems
+ i
;
615 r
= sd_bus_message_append(
623 return sd_bus_message_close_container(reply
);
626 static int property_get_log_extra_fields(
629 const char *interface
,
630 const char *property
,
631 sd_bus_message
*reply
,
633 sd_bus_error
*error
) {
635 ExecContext
*c
= userdata
;
644 r
= sd_bus_message_open_container(reply
, 'a', "ay");
648 for (i
= 0; i
< c
->n_log_extra_fields
; i
++) {
649 r
= sd_bus_message_append_array(reply
, 'y', c
->log_extra_fields
[i
].iov_base
, c
->log_extra_fields
[i
].iov_len
);
654 return sd_bus_message_close_container(reply
);
657 const sd_bus_vtable bus_exec_vtable
[] = {
658 SD_BUS_VTABLE_START(0),
659 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(ExecContext
, environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
660 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
661 SD_BUS_PROPERTY("PassEnvironment", "as", NULL
, offsetof(ExecContext
, pass_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
662 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL
, offsetof(ExecContext
, unset_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
663 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode
, offsetof(ExecContext
, umask
), SD_BUS_VTABLE_PROPERTY_CONST
),
664 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
665 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
666 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
667 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
668 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
669 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
670 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
671 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
672 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
673 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
674 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
675 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
676 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
677 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
678 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
679 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
680 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
681 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
682 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
683 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
684 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
685 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
686 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
687 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
688 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
689 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
690 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
691 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
692 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
693 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
694 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
695 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
696 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
697 SD_BUS_PROPERTY("RootDirectory", "s", NULL
, offsetof(ExecContext
, root_directory
), SD_BUS_VTABLE_PROPERTY_CONST
),
698 SD_BUS_PROPERTY("RootImage", "s", NULL
, offsetof(ExecContext
, root_image
), SD_BUS_VTABLE_PROPERTY_CONST
),
699 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
700 SD_BUS_PROPERTY("Nice", "i", property_get_nice
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
701 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
702 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
703 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
704 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
705 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
706 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
707 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool
, offsetof(ExecContext
, cpu_sched_reset_on_fork
), SD_BUS_VTABLE_PROPERTY_CONST
),
708 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool
, offsetof(ExecContext
, non_blocking
), SD_BUS_VTABLE_PROPERTY_CONST
),
709 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input
, offsetof(ExecContext
, std_input
), SD_BUS_VTABLE_PROPERTY_CONST
),
710 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
711 SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
712 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
713 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
714 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_error
), SD_BUS_VTABLE_PROPERTY_CONST
),
715 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
716 SD_BUS_PROPERTY("TTYPath", "s", NULL
, offsetof(ExecContext
, tty_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
717 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_reset
), SD_BUS_VTABLE_PROPERTY_CONST
),
718 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vhangup
), SD_BUS_VTABLE_PROPERTY_CONST
),
719 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vt_disallocate
), SD_BUS_VTABLE_PROPERTY_CONST
),
720 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
721 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL
, offsetof(ExecContext
, syslog_identifier
), SD_BUS_VTABLE_PROPERTY_CONST
),
722 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool
, offsetof(ExecContext
, syslog_level_prefix
), SD_BUS_VTABLE_PROPERTY_CONST
),
723 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
724 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
725 SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int
, offsetof(ExecContext
, log_level_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
726 SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
727 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int
, offsetof(ExecContext
, secure_bits
), SD_BUS_VTABLE_PROPERTY_CONST
),
728 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL
, offsetof(ExecContext
, capability_bounding_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
729 SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL
, offsetof(ExecContext
, capability_ambient_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
730 SD_BUS_PROPERTY("User", "s", NULL
, offsetof(ExecContext
, user
), SD_BUS_VTABLE_PROPERTY_CONST
),
731 SD_BUS_PROPERTY("Group", "s", NULL
, offsetof(ExecContext
, group
), SD_BUS_VTABLE_PROPERTY_CONST
),
732 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool
, offsetof(ExecContext
, dynamic_user
), SD_BUS_VTABLE_PROPERTY_CONST
),
733 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, remove_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
734 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL
, offsetof(ExecContext
, supplementary_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
735 SD_BUS_PROPERTY("PAMName", "s", NULL
, offsetof(ExecContext
, pam_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
736 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
737 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
738 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
739 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong
, offsetof(ExecContext
, mount_flags
), SD_BUS_VTABLE_PROPERTY_CONST
),
740 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool
, offsetof(ExecContext
, private_tmp
), SD_BUS_VTABLE_PROPERTY_CONST
),
741 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool
, offsetof(ExecContext
, private_devices
), SD_BUS_VTABLE_PROPERTY_CONST
),
742 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_tunables
), SD_BUS_VTABLE_PROPERTY_CONST
),
743 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_modules
), SD_BUS_VTABLE_PROPERTY_CONST
),
744 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_control_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
745 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool
, offsetof(ExecContext
, private_network
), SD_BUS_VTABLE_PROPERTY_CONST
),
746 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool
, offsetof(ExecContext
, private_users
), SD_BUS_VTABLE_PROPERTY_CONST
),
747 SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home
, offsetof(ExecContext
, protect_home
), SD_BUS_VTABLE_PROPERTY_CONST
),
748 SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system
, offsetof(ExecContext
, protect_system
), SD_BUS_VTABLE_PROPERTY_CONST
),
749 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool
, offsetof(ExecContext
, same_pgrp
), SD_BUS_VTABLE_PROPERTY_CONST
),
750 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL
, offsetof(ExecContext
, utmp_id
), SD_BUS_VTABLE_PROPERTY_CONST
),
751 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode
, offsetof(ExecContext
, utmp_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
752 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
753 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
754 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
755 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool
, offsetof(ExecContext
, ignore_sigpipe
), SD_BUS_VTABLE_PROPERTY_CONST
),
756 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool
, offsetof(ExecContext
, no_new_privileges
), SD_BUS_VTABLE_PROPERTY_CONST
),
757 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
758 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
759 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int
, offsetof(ExecContext
, syscall_errno
), SD_BUS_VTABLE_PROPERTY_CONST
),
760 SD_BUS_PROPERTY("Personality", "s", property_get_personality
, offsetof(ExecContext
, personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
761 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool
, offsetof(ExecContext
, lock_personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
762 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
763 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode
, offsetof(ExecContext
, runtime_directory_preserve_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
764 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
765 SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
766 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
767 SD_BUS_PROPERTY("StateDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
768 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
769 SD_BUS_PROPERTY("CacheDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
770 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
771 SD_BUS_PROPERTY("LogsDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
772 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
773 SD_BUS_PROPERTY("ConfigurationDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
774 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool
, offsetof(ExecContext
, memory_deny_write_execute
), SD_BUS_VTABLE_PROPERTY_CONST
),
775 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_realtime
), SD_BUS_VTABLE_PROPERTY_CONST
),
776 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong
, offsetof(ExecContext
, restrict_namespaces
), SD_BUS_VTABLE_PROPERTY_CONST
),
777 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
778 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
779 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
780 SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool
, offsetof(ExecContext
, mount_apivfs
), SD_BUS_VTABLE_PROPERTY_CONST
),
781 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode
, offsetof(ExecContext
, keyring_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
783 /* Obsolete/redundant properties: */
784 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
785 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
786 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
787 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
788 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
793 static int append_exec_command(sd_bus_message
*reply
, ExecCommand
*c
) {
802 r
= sd_bus_message_open_container(reply
, 'r', "sasbttttuii");
806 r
= sd_bus_message_append(reply
, "s", c
->path
);
810 r
= sd_bus_message_append_strv(reply
, c
->argv
);
814 r
= sd_bus_message_append(reply
, "bttttuii",
815 !!(c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
),
816 c
->exec_status
.start_timestamp
.realtime
,
817 c
->exec_status
.start_timestamp
.monotonic
,
818 c
->exec_status
.exit_timestamp
.realtime
,
819 c
->exec_status
.exit_timestamp
.monotonic
,
820 (uint32_t) c
->exec_status
.pid
,
821 (int32_t) c
->exec_status
.code
,
822 (int32_t) c
->exec_status
.status
);
826 return sd_bus_message_close_container(reply
);
829 int bus_property_get_exec_command(
832 const char *interface
,
833 const char *property
,
834 sd_bus_message
*reply
,
836 sd_bus_error
*ret_error
) {
838 ExecCommand
*c
= (ExecCommand
*) userdata
;
844 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
848 r
= append_exec_command(reply
, c
);
852 return sd_bus_message_close_container(reply
);
855 int bus_property_get_exec_command_list(
858 const char *interface
,
859 const char *property
,
860 sd_bus_message
*reply
,
862 sd_bus_error
*ret_error
) {
864 ExecCommand
*c
= *(ExecCommand
**) userdata
;
870 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
874 LIST_FOREACH(command
, c
, c
) {
875 r
= append_exec_command(reply
, c
);
880 return sd_bus_message_close_container(reply
);
883 int bus_set_transient_exec_command(
886 ExecCommand
**exec_command
,
887 sd_bus_message
*message
,
888 UnitWriteFlags flags
,
889 sd_bus_error
*error
) {
893 r
= sd_bus_message_enter_container(message
, 'a', "(sasb)");
897 while ((r
= sd_bus_message_enter_container(message
, 'r', "sasb")) > 0) {
898 _cleanup_strv_free_
char **argv
= NULL
;
902 r
= sd_bus_message_read(message
, "s", &path
);
906 if (!path_is_absolute(path
))
907 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
909 r
= sd_bus_message_read_strv(message
, &argv
);
913 r
= sd_bus_message_read(message
, "b", &b
);
917 r
= sd_bus_message_exit_container(message
);
921 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
924 c
= new0(ExecCommand
, 1);
928 c
->path
= strdup(path
);
934 c
->argv
= TAKE_PTR(argv
);
936 c
->flags
= b
? EXEC_COMMAND_IGNORE_FAILURE
: 0;
938 path_simplify(c
->path
, false);
939 exec_command_append_list(exec_command
, c
);
947 r
= sd_bus_message_exit_container(message
);
951 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
952 _cleanup_free_
char *buf
= NULL
;
953 _cleanup_fclose_
FILE *f
= NULL
;
958 *exec_command
= exec_command_free_list(*exec_command
);
960 f
= open_memstream(&buf
, &size
);
964 (void) __fsetlocking(f
, FSETLOCKING_BYCALLER
);
966 fputs("ExecStart=\n", f
);
968 LIST_FOREACH(command
, c
, *exec_command
) {
969 _cleanup_free_
char *a
= NULL
, *t
= NULL
;
972 p
= unit_escape_setting(c
->path
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
, &t
);
976 a
= unit_concat_strv(c
->argv
, UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
);
980 fprintf(f
, "%s=%s@%s %s\n",
982 c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
? "-" : "",
987 r
= fflush_and_check(f
);
991 unit_write_setting(u
, flags
, name
, buf
);
997 static int parse_personality(const char *s
, unsigned long *p
) {
1002 v
= personality_from_string(s
);
1003 if (v
== PERSONALITY_INVALID
)
1010 static const char* mount_propagation_flags_to_string_with_check(unsigned long n
) {
1011 if (!IN_SET(n
, 0, MS_SHARED
, MS_PRIVATE
, MS_SLAVE
))
1014 return mount_propagation_flags_to_string(n
);
1017 static BUS_DEFINE_SET_TRANSIENT(nsec
, "t", uint64_t, nsec_t
, NSEC_FMT
);
1018 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level
, "i", int32_t, int, "%" PRIi32
, log_level_is_valid
);
1020 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno
, "i", int32_t, int, "%" PRIi32
, errno_is_valid
);
1022 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(sched_priority
, "i", int32_t, int, "%" PRIi32
, sched_priority_is_valid
);
1023 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(nice
, "i", int32_t, int, "%" PRIi32
, nice_is_valid
);
1024 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input
, ExecInput
, exec_input_from_string
);
1025 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output
, ExecOutput
, exec_output_from_string
);
1026 static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode
, ExecUtmpMode
, exec_utmp_mode_from_string
);
1027 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system
, ProtectSystem
, protect_system_or_bool_from_string
);
1028 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home
, ProtectHome
, protect_home_or_bool_from_string
);
1029 static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode
, ExecKeyringMode
, exec_keyring_mode_from_string
);
1030 static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode
, ExecPreserveMode
, exec_preserve_mode_from_string
);
1031 static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality
, unsigned long, parse_personality
);
1032 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits
, "i", int32_t, int, "%" PRIi32
, secure_bits_to_string_alloc_with_check
);
1033 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability
, "t", uint64_t, uint64_t, "%" PRIu64
, capability_set_to_string_alloc
);
1034 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(sched_policy
, "i", int32_t, int, "%" PRIi32
, sched_policy_to_string_alloc_with_check
);
1035 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag
, "t", uint64_t, unsigned long, "%" PRIu64
, namespace_flags_to_string
);
1036 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags
, "t", uint64_t, unsigned long, "%" PRIu64
, mount_propagation_flags_to_string_with_check
);
1038 int bus_exec_context_set_transient_property(
1042 sd_bus_message
*message
,
1043 UnitWriteFlags flags
,
1044 sd_bus_error
*error
) {
1054 flags
|= UNIT_PRIVATE
;
1056 if (streq(name
, "User"))
1057 return bus_set_transient_user(u
, name
, &c
->user
, message
, flags
, error
);
1059 if (streq(name
, "Group"))
1060 return bus_set_transient_user(u
, name
, &c
->group
, message
, flags
, error
);
1062 if (streq(name
, "TTYPath"))
1063 return bus_set_transient_path(u
, name
, &c
->tty_path
, message
, flags
, error
);
1065 if (streq(name
, "RootImage"))
1066 return bus_set_transient_path(u
, name
, &c
->root_image
, message
, flags
, error
);
1068 if (streq(name
, "RootDirectory"))
1069 return bus_set_transient_path(u
, name
, &c
->root_directory
, message
, flags
, error
);
1071 if (streq(name
, "SyslogIdentifier"))
1072 return bus_set_transient_string(u
, name
, &c
->syslog_identifier
, message
, flags
, error
);
1074 if (streq(name
, "LogLevelMax"))
1075 return bus_set_transient_log_level(u
, name
, &c
->log_level_max
, message
, flags
, error
);
1077 if (streq(name
, "CPUSchedulingPriority"))
1078 return bus_set_transient_sched_priority(u
, name
, &c
->cpu_sched_priority
, message
, flags
, error
);
1080 if (streq(name
, "Personality"))
1081 return bus_set_transient_personality(u
, name
, &c
->personality
, message
, flags
, error
);
1083 if (streq(name
, "Nice"))
1084 return bus_set_transient_nice(u
, name
, &c
->nice
, message
, flags
, error
);
1086 if (streq(name
, "StandardInput"))
1087 return bus_set_transient_std_input(u
, name
, &c
->std_input
, message
, flags
, error
);
1089 if (streq(name
, "StandardOutput"))
1090 return bus_set_transient_std_output(u
, name
, &c
->std_output
, message
, flags
, error
);
1092 if (streq(name
, "StandardError"))
1093 return bus_set_transient_std_output(u
, name
, &c
->std_error
, message
, flags
, error
);
1095 if (streq(name
, "IgnoreSIGPIPE"))
1096 return bus_set_transient_bool(u
, name
, &c
->ignore_sigpipe
, message
, flags
, error
);
1098 if (streq(name
, "TTYVHangup"))
1099 return bus_set_transient_bool(u
, name
, &c
->tty_vhangup
, message
, flags
, error
);
1101 if (streq(name
, "TTYReset"))
1102 return bus_set_transient_bool(u
, name
, &c
->tty_reset
, message
, flags
, error
);
1104 if (streq(name
, "TTYVTDisallocate"))
1105 return bus_set_transient_bool(u
, name
, &c
->tty_vt_disallocate
, message
, flags
, error
);
1107 if (streq(name
, "PrivateTmp"))
1108 return bus_set_transient_bool(u
, name
, &c
->private_tmp
, message
, flags
, error
);
1110 if (streq(name
, "PrivateDevices"))
1111 return bus_set_transient_bool(u
, name
, &c
->private_devices
, message
, flags
, error
);
1113 if (streq(name
, "PrivateNetwork"))
1114 return bus_set_transient_bool(u
, name
, &c
->private_network
, message
, flags
, error
);
1116 if (streq(name
, "PrivateUsers"))
1117 return bus_set_transient_bool(u
, name
, &c
->private_users
, message
, flags
, error
);
1119 if (streq(name
, "NoNewPrivileges"))
1120 return bus_set_transient_bool(u
, name
, &c
->no_new_privileges
, message
, flags
, error
);
1122 if (streq(name
, "SyslogLevelPrefix"))
1123 return bus_set_transient_bool(u
, name
, &c
->syslog_level_prefix
, message
, flags
, error
);
1125 if (streq(name
, "MemoryDenyWriteExecute"))
1126 return bus_set_transient_bool(u
, name
, &c
->memory_deny_write_execute
, message
, flags
, error
);
1128 if (streq(name
, "RestrictRealtime"))
1129 return bus_set_transient_bool(u
, name
, &c
->restrict_realtime
, message
, flags
, error
);
1131 if (streq(name
, "DynamicUser"))
1132 return bus_set_transient_bool(u
, name
, &c
->dynamic_user
, message
, flags
, error
);
1134 if (streq(name
, "RemoveIPC"))
1135 return bus_set_transient_bool(u
, name
, &c
->remove_ipc
, message
, flags
, error
);
1137 if (streq(name
, "ProtectKernelTunables"))
1138 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_tunables
, message
, flags
, error
);
1140 if (streq(name
, "ProtectKernelModules"))
1141 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_modules
, message
, flags
, error
);
1143 if (streq(name
, "ProtectControlGroups"))
1144 return bus_set_transient_bool(u
, name
, &c
->protect_control_groups
, message
, flags
, error
);
1146 if (streq(name
, "MountAPIVFS"))
1147 return bus_set_transient_bool(u
, name
, &c
->mount_apivfs
, message
, flags
, error
);
1149 if (streq(name
, "CPUSchedulingResetOnFork"))
1150 return bus_set_transient_bool(u
, name
, &c
->cpu_sched_reset_on_fork
, message
, flags
, error
);
1152 if (streq(name
, "NonBlocking"))
1153 return bus_set_transient_bool(u
, name
, &c
->non_blocking
, message
, flags
, error
);
1155 if (streq(name
, "LockPersonality"))
1156 return bus_set_transient_bool(u
, name
, &c
->lock_personality
, message
, flags
, error
);
1158 if (streq(name
, "UtmpIdentifier"))
1159 return bus_set_transient_string(u
, name
, &c
->utmp_id
, message
, flags
, error
);
1161 if (streq(name
, "UtmpMode"))
1162 return bus_set_transient_utmp_mode(u
, name
, &c
->utmp_mode
, message
, flags
, error
);
1164 if (streq(name
, "PAMName"))
1165 return bus_set_transient_string(u
, name
, &c
->pam_name
, message
, flags
, error
);
1167 if (streq(name
, "TimerSlackNSec"))
1168 return bus_set_transient_nsec(u
, name
, &c
->timer_slack_nsec
, message
, flags
, error
);
1170 if (streq(name
, "ProtectSystem"))
1171 return bus_set_transient_protect_system(u
, name
, &c
->protect_system
, message
, flags
, error
);
1173 if (streq(name
, "ProtectHome"))
1174 return bus_set_transient_protect_home(u
, name
, &c
->protect_home
, message
, flags
, error
);
1176 if (streq(name
, "KeyringMode"))
1177 return bus_set_transient_keyring_mode(u
, name
, &c
->keyring_mode
, message
, flags
, error
);
1179 if (streq(name
, "RuntimeDirectoryPreserve"))
1180 return bus_set_transient_preserve_mode(u
, name
, &c
->runtime_directory_preserve_mode
, message
, flags
, error
);
1182 if (streq(name
, "UMask"))
1183 return bus_set_transient_mode_t(u
, name
, &c
->umask
, message
, flags
, error
);
1185 if (streq(name
, "RuntimeDirectoryMode"))
1186 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_RUNTIME
].mode
, message
, flags
, error
);
1188 if (streq(name
, "StateDirectoryMode"))
1189 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_STATE
].mode
, message
, flags
, error
);
1191 if (streq(name
, "CacheDirectoryMode"))
1192 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CACHE
].mode
, message
, flags
, error
);
1194 if (streq(name
, "LogsDirectoryMode"))
1195 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_LOGS
].mode
, message
, flags
, error
);
1197 if (streq(name
, "ConfigurationDirectoryMode"))
1198 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
, message
, flags
, error
);
1200 if (streq(name
, "SELinuxContext"))
1201 return bus_set_transient_string(u
, name
, &c
->selinux_context
, message
, flags
, error
);
1203 if (streq(name
, "SecureBits"))
1204 return bus_set_transient_secure_bits(u
, name
, &c
->secure_bits
, message
, flags
, error
);
1206 if (streq(name
, "CapabilityBoundingSet"))
1207 return bus_set_transient_capability(u
, name
, &c
->capability_bounding_set
, message
, flags
, error
);
1209 if (streq(name
, "AmbientCapabilities"))
1210 return bus_set_transient_capability(u
, name
, &c
->capability_ambient_set
, message
, flags
, error
);
1212 if (streq(name
, "CPUSchedulingPolicy"))
1213 return bus_set_transient_sched_policy(u
, name
, &c
->cpu_sched_policy
, message
, flags
, error
);
1215 if (streq(name
, "RestrictNamespaces"))
1216 return bus_set_transient_namespace_flag(u
, name
, &c
->restrict_namespaces
, message
, flags
, error
);
1218 if (streq(name
, "MountFlags"))
1219 return bus_set_transient_mount_flags(u
, name
, &c
->mount_flags
, message
, flags
, error
);
1221 if (streq(name
, "SupplementaryGroups")) {
1222 _cleanup_strv_free_
char **l
= NULL
;
1225 r
= sd_bus_message_read_strv(message
, &l
);
1229 STRV_FOREACH(p
, l
) {
1230 if (!isempty(*p
) && !valid_user_group_name_or_id(*p
))
1231 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid supplementary group names");
1234 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1235 if (strv_isempty(l
)) {
1236 c
->supplementary_groups
= strv_free(c
->supplementary_groups
);
1237 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1239 _cleanup_free_
char *joined
= NULL
;
1241 r
= strv_extend_strv(&c
->supplementary_groups
, l
, true);
1245 joined
= strv_join(c
->supplementary_groups
, " ");
1249 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s", name
, joined
);
1255 } else if (streq(name
, "SyslogLevel")) {
1258 r
= sd_bus_message_read(message
, "i", &level
);
1262 if (!log_level_is_valid(level
))
1263 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log level value out of range");
1265 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1266 c
->syslog_priority
= (c
->syslog_priority
& LOG_FACMASK
) | level
;
1267 unit_write_settingf(u
, flags
, name
, "SyslogLevel=%i", level
);
1272 } else if (streq(name
, "SyslogFacility")) {
1275 r
= sd_bus_message_read(message
, "i", &facility
);
1279 if (!log_facility_unshifted_is_valid(facility
))
1280 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log facility value out of range");
1282 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1283 c
->syslog_priority
= (facility
<< 3) | LOG_PRI(c
->syslog_priority
);
1284 unit_write_settingf(u
, flags
, name
, "SyslogFacility=%i", facility
);
1289 } else if (streq(name
, "LogExtraFields")) {
1292 r
= sd_bus_message_enter_container(message
, 'a', "ay");
1297 _cleanup_free_
void *copy
= NULL
;
1303 /* Note that we expect a byte array for each field, instead of a string. That's because on the
1304 * lower-level journal fields can actually contain binary data and are not restricted to text,
1305 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
1306 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
1307 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
1308 * limitation, should a good, valid usecase arise. */
1310 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
1316 if (memchr(p
, 0, sz
))
1317 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains zero byte");
1319 eq
= memchr(p
, '=', sz
);
1321 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains no '=' character");
1322 if (!journal_field_valid(p
, eq
- (const char*) p
, false))
1323 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field invalid");
1325 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1326 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
1329 c
->log_extra_fields
= t
;
1332 copy
= malloc(sz
+ 1);
1336 memcpy(copy
, p
, sz
);
1337 ((uint8_t*) copy
)[sz
] = 0;
1339 if (!utf8_is_valid(copy
))
1340 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field is not valid UTF-8");
1342 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1343 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE(copy
, sz
);
1344 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
, name
, "LogExtraFields=%s", (char*) copy
);
1352 r
= sd_bus_message_exit_container(message
);
1356 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && n
== 0) {
1357 exec_context_free_log_extra_fields(c
);
1358 unit_write_setting(u
, flags
, name
, "LogExtraFields=");
1366 if (streq(name
, "SystemCallErrorNumber"))
1367 return bus_set_transient_errno(u
, name
, &c
->syscall_errno
, message
, flags
, error
);
1369 if (streq(name
, "SystemCallFilter")) {
1371 _cleanup_strv_free_
char **l
= NULL
;
1373 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1377 r
= sd_bus_message_read(message
, "b", &whitelist
);
1381 r
= sd_bus_message_read_strv(message
, &l
);
1385 r
= sd_bus_message_exit_container(message
);
1389 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1390 _cleanup_free_
char *joined
= NULL
;
1391 bool invert
= !whitelist
;
1394 if (strv_isempty(l
)) {
1395 c
->syscall_whitelist
= false;
1396 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
1398 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=");
1402 if (!c
->syscall_filter
) {
1403 c
->syscall_filter
= hashmap_new(NULL
);
1404 if (!c
->syscall_filter
)
1407 c
->syscall_whitelist
= whitelist
;
1409 if (c
->syscall_whitelist
) {
1410 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
| (invert
? SECCOMP_PARSE_INVERT
: 0));
1416 STRV_FOREACH(s
, l
) {
1417 _cleanup_free_
char *n
= NULL
;
1420 r
= parse_syscall_and_errno(*s
, &n
, &e
);
1424 r
= seccomp_parse_syscall_filter(n
, e
, c
->syscall_filter
, (invert
? SECCOMP_PARSE_INVERT
: 0) | (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0));
1429 joined
= strv_join(l
, " ");
1433 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=%s%s", whitelist
? "" : "~", joined
);
1438 } else if (streq(name
, "SystemCallArchitectures")) {
1439 _cleanup_strv_free_
char **l
= NULL
;
1441 r
= sd_bus_message_read_strv(message
, &l
);
1445 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1446 _cleanup_free_
char *joined
= NULL
;
1448 if (strv_isempty(l
))
1449 c
->syscall_archs
= set_free(c
->syscall_archs
);
1453 r
= set_ensure_allocated(&c
->syscall_archs
, NULL
);
1457 STRV_FOREACH(s
, l
) {
1460 r
= seccomp_arch_from_string(*s
, &a
);
1464 r
= set_put(c
->syscall_archs
, UINT32_TO_PTR(a
+ 1));
1471 joined
= strv_join(l
, " ");
1475 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
1480 } else if (streq(name
, "RestrictAddressFamilies")) {
1482 _cleanup_strv_free_
char **l
= NULL
;
1484 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1488 r
= sd_bus_message_read(message
, "b", &whitelist
);
1492 r
= sd_bus_message_read_strv(message
, &l
);
1496 r
= sd_bus_message_exit_container(message
);
1500 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1501 _cleanup_free_
char *joined
= NULL
;
1502 bool invert
= !whitelist
;
1505 if (strv_isempty(l
)) {
1506 c
->address_families_whitelist
= false;
1507 c
->address_families
= set_free(c
->address_families
);
1509 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=");
1513 if (!c
->address_families
) {
1514 c
->address_families
= set_new(NULL
);
1515 if (!c
->address_families
)
1518 c
->address_families_whitelist
= whitelist
;
1521 STRV_FOREACH(s
, l
) {
1524 af
= af_from_name(*s
);
1528 if (!invert
== c
->address_families_whitelist
) {
1529 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
1533 (void) set_remove(c
->address_families
, INT_TO_PTR(af
));
1536 joined
= strv_join(l
, " ");
1540 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=%s%s", whitelist
? "" : "~", joined
);
1546 if (streq(name
, "CPUAffinity")) {
1550 r
= sd_bus_message_read_array(message
, 'y', &a
, &n
);
1554 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1556 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1557 c
->cpuset_ncpus
= 0;
1558 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1560 _cleanup_free_
char *str
= NULL
;
1561 size_t allocated
= 0, len
= 0, i
, ncpus
;
1563 ncpus
= CPU_SIZE_TO_NUM(n
);
1565 for (i
= 0; i
< ncpus
; i
++) {
1566 _cleanup_free_
char *p
= NULL
;
1569 if (!CPU_ISSET_S(i
, n
, (cpu_set_t
*) a
))
1572 r
= asprintf(&p
, "%zu", i
);
1578 if (!GREEDY_REALLOC(str
, allocated
, len
+ add
+ 2))
1581 strcpy(mempcpy(str
+ len
, p
, add
), " ");
1586 str
[len
- 1] = '\0';
1588 if (!c
->cpuset
|| c
->cpuset_ncpus
< ncpus
) {
1591 cpuset
= CPU_ALLOC(ncpus
);
1595 CPU_ZERO_S(n
, cpuset
);
1597 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, (cpu_set_t
*) a
);
1598 CPU_FREE(c
->cpuset
);
1600 CPU_OR_S(n
, cpuset
, cpuset
, (cpu_set_t
*) a
);
1603 c
->cpuset_ncpus
= ncpus
;
1605 CPU_OR_S(n
, c
->cpuset
, c
->cpuset
, (cpu_set_t
*) a
);
1607 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, str
);
1613 } else if (streq(name
, "IOSchedulingClass")) {
1616 r
= sd_bus_message_read(message
, "i", &q
);
1620 if (!ioprio_class_is_valid(q
))
1621 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling class: %i", q
);
1623 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1624 _cleanup_free_
char *s
= NULL
;
1626 r
= ioprio_class_to_string_alloc(q
, &s
);
1630 c
->ioprio
= IOPRIO_PRIO_VALUE(q
, IOPRIO_PRIO_DATA(c
->ioprio
));
1631 c
->ioprio_set
= true;
1633 unit_write_settingf(u
, flags
, name
, "IOSchedulingClass=%s", s
);
1638 } else if (streq(name
, "IOSchedulingPriority")) {
1641 r
= sd_bus_message_read(message
, "i", &p
);
1645 if (!ioprio_priority_is_valid(p
))
1646 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling priority: %i", p
);
1648 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1649 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), p
);
1650 c
->ioprio_set
= true;
1652 unit_write_settingf(u
, flags
, name
, "IOSchedulingPriority=%i", p
);
1657 } else if (streq(name
, "WorkingDirectory")) {
1661 r
= sd_bus_message_read(message
, "s", &s
);
1671 if (!isempty(s
) && !streq(s
, "~") && !path_is_absolute(s
))
1672 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "WorkingDirectory= expects an absolute path or '~'");
1674 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1675 if (streq(s
, "~")) {
1676 c
->working_directory
= mfree(c
->working_directory
);
1677 c
->working_directory_home
= true;
1679 r
= free_and_strdup(&c
->working_directory
, empty_to_null(s
));
1683 c
->working_directory_home
= false;
1686 c
->working_directory_missing_ok
= missing_ok
;
1687 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "WorkingDirectory=%s%s", missing_ok
? "-" : "", s
);
1692 } else if (STR_IN_SET(name
,
1693 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
1696 r
= sd_bus_message_read(message
, "s", &s
);
1700 if (!isempty(s
) && !fdname_is_valid(s
))
1701 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid file descriptor name");
1703 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1705 if (streq(name
, "StandardInputFileDescriptorName")) {
1706 r
= free_and_strdup(c
->stdio_fdname
+ STDIN_FILENO
, empty_to_null(s
));
1710 c
->std_input
= EXEC_INPUT_NAMED_FD
;
1711 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=fd:%s", exec_context_fdname(c
, STDIN_FILENO
));
1713 } else if (streq(name
, "StandardOutputFileDescriptorName")) {
1714 r
= free_and_strdup(c
->stdio_fdname
+ STDOUT_FILENO
, empty_to_null(s
));
1718 c
->std_output
= EXEC_OUTPUT_NAMED_FD
;
1719 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=fd:%s", exec_context_fdname(c
, STDOUT_FILENO
));
1722 assert(streq(name
, "StandardErrorFileDescriptorName"));
1724 r
= free_and_strdup(&c
->stdio_fdname
[STDERR_FILENO
], empty_to_null(s
));
1728 c
->std_error
= EXEC_OUTPUT_NAMED_FD
;
1729 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=fd:%s", exec_context_fdname(c
, STDERR_FILENO
));
1735 } else if (STR_IN_SET(name
, "StandardInputFile", "StandardOutputFile", "StandardErrorFile")) {
1738 r
= sd_bus_message_read(message
, "s", &s
);
1743 if (!path_is_absolute(s
))
1744 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute", s
);
1745 if (!path_is_normalized(s
))
1746 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not normalized", s
);
1749 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1751 if (streq(name
, "StandardInputFile")) {
1752 r
= free_and_strdup(&c
->stdio_file
[STDIN_FILENO
], empty_to_null(s
));
1756 c
->std_input
= EXEC_INPUT_FILE
;
1757 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=file:%s", s
);
1759 } else if (streq(name
, "StandardOutputFile")) {
1760 r
= free_and_strdup(&c
->stdio_file
[STDOUT_FILENO
], empty_to_null(s
));
1764 c
->std_output
= EXEC_OUTPUT_FILE
;
1765 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=file:%s", s
);
1768 assert(streq(name
, "StandardErrorFile"));
1770 r
= free_and_strdup(&c
->stdio_file
[STDERR_FILENO
], empty_to_null(s
));
1774 c
->std_error
= EXEC_OUTPUT_FILE
;
1775 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=file:%s", s
);
1781 } else if (streq(name
, "StandardInputData")) {
1785 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
1789 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1790 _cleanup_free_
char *encoded
= NULL
;
1793 c
->stdin_data
= mfree(c
->stdin_data
);
1794 c
->stdin_data_size
= 0;
1796 unit_write_settingf(u
, flags
, name
, "StandardInputData=");
1801 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1802 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
)
1805 n
= base64mem(p
, sz
, &encoded
);
1809 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1813 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1816 c
->stdin_data_size
+= sz
;
1818 unit_write_settingf(u
, flags
, name
, "StandardInputData=%s", encoded
);
1824 } else if (streq(name
, "Environment")) {
1826 _cleanup_strv_free_
char **l
= NULL
;
1828 r
= sd_bus_message_read_strv(message
, &l
);
1832 if (!strv_env_is_valid(l
))
1833 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment block.");
1835 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1836 if (strv_isempty(l
)) {
1837 c
->environment
= strv_free(c
->environment
);
1838 unit_write_setting(u
, flags
, name
, "Environment=");
1840 _cleanup_free_
char *joined
= NULL
;
1843 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
1847 e
= strv_env_merge(2, c
->environment
, l
);
1851 strv_free_and_replace(c
->environment
, e
);
1852 unit_write_settingf(u
, flags
, name
, "Environment=%s", joined
);
1858 } else if (streq(name
, "UnsetEnvironment")) {
1860 _cleanup_strv_free_
char **l
= NULL
;
1862 r
= sd_bus_message_read_strv(message
, &l
);
1866 if (!strv_env_name_or_assignment_is_valid(l
))
1867 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid UnsetEnvironment= list.");
1869 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1870 if (strv_isempty(l
)) {
1871 c
->unset_environment
= strv_free(c
->unset_environment
);
1872 unit_write_setting(u
, flags
, name
, "UnsetEnvironment=");
1874 _cleanup_free_
char *joined
= NULL
;
1877 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
1881 e
= strv_env_merge(2, c
->unset_environment
, l
);
1885 strv_free_and_replace(c
->unset_environment
, e
);
1886 unit_write_settingf(u
, flags
, name
, "UnsetEnvironment=%s", joined
);
1892 } else if (streq(name
, "OOMScoreAdjust")) {
1895 r
= sd_bus_message_read(message
, "i", &oa
);
1899 if (!oom_score_adjust_is_valid(oa
))
1900 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "OOM score adjust value out of range");
1902 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1903 c
->oom_score_adjust
= oa
;
1904 c
->oom_score_adjust_set
= true;
1905 unit_write_settingf(u
, flags
, name
, "OOMScoreAdjust=%i", oa
);
1910 } else if (streq(name
, "EnvironmentFiles")) {
1912 _cleanup_free_
char *joined
= NULL
;
1913 _cleanup_fclose_
FILE *f
= NULL
;
1914 _cleanup_strv_free_
char **l
= NULL
;
1918 r
= sd_bus_message_enter_container(message
, 'a', "(sb)");
1922 f
= open_memstream(&joined
, &size
);
1926 (void) __fsetlocking(f
, FSETLOCKING_BYCALLER
);
1928 fputs("EnvironmentFile=\n", f
);
1930 STRV_FOREACH(i
, c
->environment_files
) {
1931 _cleanup_free_
char *q
= NULL
;
1933 q
= specifier_escape(*i
);
1937 fprintf(f
, "EnvironmentFile=%s\n", q
);
1940 while ((r
= sd_bus_message_enter_container(message
, 'r', "sb")) > 0) {
1944 r
= sd_bus_message_read(message
, "sb", &path
, &b
);
1948 r
= sd_bus_message_exit_container(message
);
1952 if (!path_is_absolute(path
))
1953 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
1955 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1956 _cleanup_free_
char *q
= NULL
;
1959 buf
= strjoin(b
? "-" : "", path
);
1963 q
= specifier_escape(buf
);
1969 fprintf(f
, "EnvironmentFile=%s\n", q
);
1971 r
= strv_consume(&l
, buf
);
1979 r
= sd_bus_message_exit_container(message
);
1983 r
= fflush_and_check(f
);
1987 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1988 if (strv_isempty(l
)) {
1989 c
->environment_files
= strv_free(c
->environment_files
);
1990 unit_write_setting(u
, flags
, name
, "EnvironmentFile=");
1992 r
= strv_extend_strv(&c
->environment_files
, l
, true);
1996 unit_write_setting(u
, flags
, name
, joined
);
2002 } else if (streq(name
, "PassEnvironment")) {
2004 _cleanup_strv_free_
char **l
= NULL
;
2006 r
= sd_bus_message_read_strv(message
, &l
);
2010 if (!strv_env_name_is_valid(l
))
2011 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PassEnvironment= block.");
2013 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2014 if (strv_isempty(l
)) {
2015 c
->pass_environment
= strv_free(c
->pass_environment
);
2016 unit_write_setting(u
, flags
, name
, "PassEnvironment=");
2018 _cleanup_free_
char *joined
= NULL
;
2020 r
= strv_extend_strv(&c
->pass_environment
, l
, true);
2024 /* We write just the new settings out to file, with unresolved specifiers. */
2025 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2029 unit_write_settingf(u
, flags
, name
, "PassEnvironment=%s", joined
);
2035 } else if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
2036 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) {
2037 _cleanup_strv_free_
char **l
= NULL
;
2041 r
= sd_bus_message_read_strv(message
, &l
);
2045 STRV_FOREACH(p
, l
) {
2049 offset
= i
[0] == '-';
2050 offset
+= i
[offset
] == '+';
2051 if (!path_is_absolute(i
+ offset
))
2052 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
2054 path_simplify(i
+ offset
, false);
2057 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2058 if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadWritePaths"))
2059 dirs
= &c
->read_write_paths
;
2060 else if (STR_IN_SET(name
, "ReadOnlyDirectories", "ReadOnlyPaths"))
2061 dirs
= &c
->read_only_paths
;
2062 else /* "InaccessiblePaths" */
2063 dirs
= &c
->inaccessible_paths
;
2065 if (strv_isempty(l
)) {
2066 *dirs
= strv_free(*dirs
);
2067 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2069 _cleanup_free_
char *joined
= NULL
;
2071 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2075 r
= strv_extend_strv(dirs
, l
, true);
2079 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2085 } else if (STR_IN_SET(name
, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
2086 _cleanup_strv_free_
char **l
= NULL
;
2089 r
= sd_bus_message_read_strv(message
, &l
);
2093 STRV_FOREACH(p
, l
) {
2094 if (!path_is_normalized(*p
))
2095 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is not normalized: %s", name
, *p
);
2097 if (path_is_absolute(*p
))
2098 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is absolute: %s", name
, *p
);
2100 if (path_startswith(*p
, "private"))
2101 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path can't be 'private': %s", name
, *p
);
2104 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2105 char ***dirs
= NULL
;
2106 ExecDirectoryType i
;
2108 for (i
= 0; i
< _EXEC_DIRECTORY_TYPE_MAX
; i
++)
2109 if (streq(name
, exec_directory_type_to_string(i
))) {
2110 dirs
= &c
->directories
[i
].paths
;
2116 if (strv_isempty(l
)) {
2117 *dirs
= strv_free(*dirs
);
2118 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2120 _cleanup_free_
char *joined
= NULL
;
2122 r
= strv_extend_strv(dirs
, l
, true);
2126 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
2130 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2136 } else if (STR_IN_SET(name
, "AppArmorProfile", "SmackProcessLabel")) {
2140 r
= sd_bus_message_read(message
, "(bs)", &ignore
, &s
);
2144 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2148 if (streq(name
, "AppArmorProfile")) {
2149 p
= &c
->apparmor_profile
;
2150 b
= &c
->apparmor_profile_ignore
;
2151 } else { /* "SmackProcessLabel" */
2152 p
= &c
->smack_process_label
;
2153 b
= &c
->smack_process_label_ignore
;
2160 if (free_and_strdup(p
, s
) < 0)
2165 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s%s", name
, ignore
? "-" : "", strempty(s
));
2170 } else if (STR_IN_SET(name
, "BindPaths", "BindReadOnlyPaths")) {
2171 const char *source
, *destination
;
2173 uint64_t mount_flags
;
2176 r
= sd_bus_message_enter_container(message
, 'a', "(ssbt)");
2180 while ((r
= sd_bus_message_read(message
, "(ssbt)", &source
, &destination
, &ignore_enoent
, &mount_flags
)) > 0) {
2182 if (!path_is_absolute(source
))
2183 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
2184 if (!path_is_absolute(destination
))
2185 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
2186 if (!IN_SET(mount_flags
, 0, MS_REC
))
2187 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount flags.");
2189 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2190 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
2192 .source
= strdup(source
),
2193 .destination
= strdup(destination
),
2194 .read_only
= !!strstr(name
, "ReadOnly"),
2195 .recursive
= !!(mount_flags
& MS_REC
),
2196 .ignore_enoent
= ignore_enoent
,
2201 unit_write_settingf(
2202 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2205 ignore_enoent
? "-" : "",
2208 (mount_flags
& MS_REC
) ? "rbind" : "norbind");
2216 r
= sd_bus_message_exit_container(message
);
2221 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
2222 c
->bind_mounts
= NULL
;
2223 c
->n_bind_mounts
= 0;
2225 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2230 } else if (streq(name
, "TemporaryFileSystem")) {
2231 const char *path
, *options
;
2234 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
2238 while ((r
= sd_bus_message_read(message
, "(ss)", &path
, &options
)) > 0) {
2240 if (!path_is_absolute(path
))
2241 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Mount point %s is not absolute.", path
);
2243 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2244 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, options
);
2248 unit_write_settingf(
2249 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2261 r
= sd_bus_message_exit_container(message
);
2266 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
2267 c
->temporary_filesystems
= NULL
;
2268 c
->n_temporary_filesystems
= 0;
2270 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2275 } else if ((suffix
= startswith(name
, "Limit"))) {
2276 const char *soft
= NULL
;
2279 ri
= rlimit_from_string(suffix
);
2281 soft
= endswith(suffix
, "Soft");
2285 n
= strndupa(suffix
, soft
- suffix
);
2286 ri
= rlimit_from_string(n
);
2288 name
= strjoina("Limit", n
);
2296 r
= sd_bus_message_read(message
, "t", &rl
);
2300 if (rl
== (uint64_t) -1)
2305 if ((uint64_t) x
!= rl
)
2309 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2310 _cleanup_free_
char *f
= NULL
;
2313 if (c
->rlimit
[ri
]) {
2314 nl
= *c
->rlimit
[ri
];
2321 /* When the resource limit is not initialized yet, then assign the value to both fields */
2322 nl
= (struct rlimit
) {
2327 r
= rlimit_format(&nl
, &f
);
2332 *c
->rlimit
[ri
] = nl
;
2334 c
->rlimit
[ri
] = newdup(struct rlimit
, &nl
, 1);
2339 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, f
);