2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include <sys/prctl.h>
27 #include "alloc-util.h"
29 #include "capability-util.h"
30 #include "dbus-execute.h"
37 #include "mount-util.h"
38 #include "namespace.h"
39 #include "parse-util.h"
40 #include "path-util.h"
41 #include "process-util.h"
42 #include "rlimit-util.h"
44 #include "seccomp-util.h"
47 #include "syslog-util.h"
48 #include "user-util.h"
51 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
);
55 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
);
57 static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_protect_home
, protect_home
, ProtectHome
);
58 static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_protect_system
, protect_system
, ProtectSystem
);
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
) {
102 ExecContext
*c
= userdata
;
109 if (c
->oom_score_adjust_set
)
110 n
= c
->oom_score_adjust
;
112 _cleanup_free_
char *t
= NULL
;
115 if (read_one_line_file("/proc/self/oom_score_adj", &t
) >= 0)
119 return sd_bus_message_append(reply
, "i", n
);
122 static int property_get_nice(
125 const char *interface
,
126 const char *property
,
127 sd_bus_message
*reply
,
129 sd_bus_error
*error
) {
132 ExecContext
*c
= userdata
;
143 n
= getpriority(PRIO_PROCESS
, 0);
148 return sd_bus_message_append(reply
, "i", n
);
151 static int property_get_ioprio(
154 const char *interface
,
155 const char *property
,
156 sd_bus_message
*reply
,
158 sd_bus_error
*error
) {
161 ExecContext
*c
= userdata
;
171 n
= ioprio_get(IOPRIO_WHO_PROCESS
, 0);
173 n
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 4);
176 return sd_bus_message_append(reply
, "i", n
);
179 static int property_get_cpu_sched_policy(
182 const char *interface
,
183 const char *property
,
184 sd_bus_message
*reply
,
186 sd_bus_error
*error
) {
188 ExecContext
*c
= userdata
;
195 if (c
->cpu_sched_set
)
196 n
= c
->cpu_sched_policy
;
198 n
= sched_getscheduler(0);
203 return sd_bus_message_append(reply
, "i", n
);
206 static int property_get_cpu_sched_priority(
209 const char *interface
,
210 const char *property
,
211 sd_bus_message
*reply
,
213 sd_bus_error
*error
) {
215 ExecContext
*c
= userdata
;
222 if (c
->cpu_sched_set
)
223 n
= c
->cpu_sched_priority
;
225 struct sched_param p
= {};
227 if (sched_getparam(0, &p
) >= 0)
228 n
= p
.sched_priority
;
233 return sd_bus_message_append(reply
, "i", n
);
236 static int property_get_cpu_affinity(
239 const char *interface
,
240 const char *property
,
241 sd_bus_message
*reply
,
243 sd_bus_error
*error
) {
245 ExecContext
*c
= userdata
;
252 return sd_bus_message_append_array(reply
, 'y', c
->cpuset
, CPU_ALLOC_SIZE(c
->cpuset_ncpus
));
254 return sd_bus_message_append_array(reply
, 'y', NULL
, 0);
257 static int property_get_timer_slack_nsec(
260 const char *interface
,
261 const char *property
,
262 sd_bus_message
*reply
,
264 sd_bus_error
*error
) {
266 ExecContext
*c
= userdata
;
273 if (c
->timer_slack_nsec
!= NSEC_INFINITY
)
274 u
= (uint64_t) c
->timer_slack_nsec
;
276 u
= (uint64_t) prctl(PR_GET_TIMERSLACK
);
278 return sd_bus_message_append(reply
, "t", u
);
281 static int property_get_capability_bounding_set(
284 const char *interface
,
285 const char *property
,
286 sd_bus_message
*reply
,
288 sd_bus_error
*error
) {
290 ExecContext
*c
= userdata
;
296 return sd_bus_message_append(reply
, "t", c
->capability_bounding_set
);
299 static int property_get_ambient_capabilities(
302 const char *interface
,
303 const char *property
,
304 sd_bus_message
*reply
,
306 sd_bus_error
*error
) {
308 ExecContext
*c
= userdata
;
314 return sd_bus_message_append(reply
, "t", c
->capability_ambient_set
);
317 static int property_get_empty_string(
320 const char *interface
,
321 const char *property
,
322 sd_bus_message
*reply
,
324 sd_bus_error
*error
) {
329 return sd_bus_message_append(reply
, "s", "");
332 static int property_get_syscall_filter(
335 const char *interface
,
336 const char *property
,
337 sd_bus_message
*reply
,
339 sd_bus_error
*error
) {
341 ExecContext
*c
= userdata
;
342 _cleanup_strv_free_
char **l
= NULL
;
354 r
= sd_bus_message_open_container(reply
, 'r', "bas");
358 r
= sd_bus_message_append(reply
, "b", c
->syscall_whitelist
);
363 SET_FOREACH(id
, c
->syscall_filter
, i
) {
366 name
= seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE
, PTR_TO_INT(id
) - 1);
370 r
= strv_consume(&l
, name
);
378 r
= sd_bus_message_append_strv(reply
, l
);
382 return sd_bus_message_close_container(reply
);
385 static int property_get_syscall_archs(
388 const char *interface
,
389 const char *property
,
390 sd_bus_message
*reply
,
392 sd_bus_error
*error
) {
394 ExecContext
*c
= userdata
;
395 _cleanup_strv_free_
char **l
= NULL
;
408 SET_FOREACH(id
, c
->syscall_archs
, i
) {
411 name
= seccomp_arch_to_string(PTR_TO_UINT32(id
) - 1);
415 r
= strv_extend(&l
, name
);
423 r
= sd_bus_message_append_strv(reply
, l
);
430 static int property_get_syscall_errno(
433 const char *interface
,
434 const char *property
,
435 sd_bus_message
*reply
,
437 sd_bus_error
*error
) {
439 ExecContext
*c
= userdata
;
445 return sd_bus_message_append(reply
, "i", (int32_t) c
->syscall_errno
);
448 static int property_get_selinux_context(
451 const char *interface
,
452 const char *property
,
453 sd_bus_message
*reply
,
455 sd_bus_error
*error
) {
457 ExecContext
*c
= userdata
;
463 return sd_bus_message_append(reply
, "(bs)", c
->selinux_context_ignore
, c
->selinux_context
);
466 static int property_get_apparmor_profile(
469 const char *interface
,
470 const char *property
,
471 sd_bus_message
*reply
,
473 sd_bus_error
*error
) {
475 ExecContext
*c
= userdata
;
481 return sd_bus_message_append(reply
, "(bs)", c
->apparmor_profile_ignore
, c
->apparmor_profile
);
484 static int property_get_smack_process_label(
487 const char *interface
,
488 const char *property
,
489 sd_bus_message
*reply
,
491 sd_bus_error
*error
) {
493 ExecContext
*c
= userdata
;
499 return sd_bus_message_append(reply
, "(bs)", c
->smack_process_label_ignore
, c
->smack_process_label
);
502 static int property_get_personality(
505 const char *interface
,
506 const char *property
,
507 sd_bus_message
*reply
,
509 sd_bus_error
*error
) {
511 ExecContext
*c
= userdata
;
517 return sd_bus_message_append(reply
, "s", personality_to_string(c
->personality
));
520 static int property_get_address_families(
523 const char *interface
,
524 const char *property
,
525 sd_bus_message
*reply
,
527 sd_bus_error
*error
) {
529 ExecContext
*c
= userdata
;
530 _cleanup_strv_free_
char **l
= NULL
;
539 r
= sd_bus_message_open_container(reply
, 'r', "bas");
543 r
= sd_bus_message_append(reply
, "b", c
->address_families_whitelist
);
547 SET_FOREACH(af
, c
->address_families
, i
) {
550 name
= af_to_name(PTR_TO_INT(af
));
554 r
= strv_extend(&l
, name
);
561 r
= sd_bus_message_append_strv(reply
, l
);
565 return sd_bus_message_close_container(reply
);
568 static int property_get_working_directory(
571 const char *interface
,
572 const char *property
,
573 sd_bus_message
*reply
,
575 sd_bus_error
*error
) {
577 ExecContext
*c
= userdata
;
584 if (c
->working_directory_home
)
587 wd
= c
->working_directory
;
589 if (c
->working_directory_missing_ok
)
590 wd
= strjoina("!", wd
);
592 return sd_bus_message_append(reply
, "s", wd
);
595 static int property_get_syslog_level(
598 const char *interface
,
599 const char *property
,
600 sd_bus_message
*reply
,
602 sd_bus_error
*error
) {
604 ExecContext
*c
= userdata
;
610 return sd_bus_message_append(reply
, "i", LOG_PRI(c
->syslog_priority
));
613 static int property_get_syslog_facility(
616 const char *interface
,
617 const char *property
,
618 sd_bus_message
*reply
,
620 sd_bus_error
*error
) {
622 ExecContext
*c
= userdata
;
628 return sd_bus_message_append(reply
, "i", LOG_FAC(c
->syslog_priority
));
631 static int property_get_input_fdname(
634 const char *interface
,
635 const char *property
,
636 sd_bus_message
*reply
,
638 sd_bus_error
*error
) {
640 ExecContext
*c
= userdata
;
648 name
= exec_context_fdname(c
, STDIN_FILENO
);
650 return sd_bus_message_append(reply
, "s", name
);
653 static int property_get_output_fdname(
656 const char *interface
,
657 const char *property
,
658 sd_bus_message
*reply
,
660 sd_bus_error
*error
) {
662 ExecContext
*c
= userdata
;
663 const char *name
= NULL
;
670 if (c
->std_output
== EXEC_OUTPUT_NAMED_FD
&& streq(property
, "StandardOutputFileDescriptorName"))
671 name
= exec_context_fdname(c
, STDOUT_FILENO
);
672 else if (c
->std_error
== EXEC_OUTPUT_NAMED_FD
&& streq(property
, "StandardErrorFileDescriptorName"))
673 name
= exec_context_fdname(c
, STDERR_FILENO
);
675 return sd_bus_message_append(reply
, "s", name
);
678 static int property_get_bind_paths(
681 const char *interface
,
682 const char *property
,
683 sd_bus_message
*reply
,
685 sd_bus_error
*error
) {
687 ExecContext
*c
= userdata
;
697 ro
= !!strstr(property
, "ReadOnly");
699 r
= sd_bus_message_open_container(reply
, 'a', "(ssbt)");
703 for (i
= 0; i
< c
->n_bind_mounts
; i
++) {
705 if (ro
!= c
->bind_mounts
[i
].read_only
)
708 r
= sd_bus_message_append(
710 c
->bind_mounts
[i
].source
,
711 c
->bind_mounts
[i
].destination
,
712 c
->bind_mounts
[i
].ignore_enoent
,
713 c
->bind_mounts
[i
].recursive
? MS_REC
: 0);
718 return sd_bus_message_close_container(reply
);
721 const sd_bus_vtable bus_exec_vtable
[] = {
722 SD_BUS_VTABLE_START(0),
723 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(ExecContext
, environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
724 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
725 SD_BUS_PROPERTY("PassEnvironment", "as", NULL
, offsetof(ExecContext
, pass_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
726 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode
, offsetof(ExecContext
, umask
), SD_BUS_VTABLE_PROPERTY_CONST
),
727 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
728 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
729 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
730 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
731 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
732 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
733 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
734 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
735 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
736 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
737 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
738 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
739 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
740 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
741 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
742 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
743 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
744 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
745 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
746 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
747 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
748 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
749 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
750 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
751 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
752 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
753 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
754 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
755 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
756 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
757 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
758 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
759 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
760 SD_BUS_PROPERTY("RootDirectory", "s", NULL
, offsetof(ExecContext
, root_directory
), SD_BUS_VTABLE_PROPERTY_CONST
),
761 SD_BUS_PROPERTY("RootImage", "s", NULL
, offsetof(ExecContext
, root_image
), SD_BUS_VTABLE_PROPERTY_CONST
),
762 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
763 SD_BUS_PROPERTY("Nice", "i", property_get_nice
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
764 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
765 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
766 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
767 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
768 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
769 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool
, offsetof(ExecContext
, cpu_sched_reset_on_fork
), SD_BUS_VTABLE_PROPERTY_CONST
),
770 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool
, offsetof(ExecContext
, non_blocking
), SD_BUS_VTABLE_PROPERTY_CONST
),
771 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input
, offsetof(ExecContext
, std_input
), SD_BUS_VTABLE_PROPERTY_CONST
),
772 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_input_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
773 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
774 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_output_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
775 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_error
), SD_BUS_VTABLE_PROPERTY_CONST
),
776 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_output_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
777 SD_BUS_PROPERTY("TTYPath", "s", NULL
, offsetof(ExecContext
, tty_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
778 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_reset
), SD_BUS_VTABLE_PROPERTY_CONST
),
779 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vhangup
), SD_BUS_VTABLE_PROPERTY_CONST
),
780 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vt_disallocate
), SD_BUS_VTABLE_PROPERTY_CONST
),
781 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
782 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL
, offsetof(ExecContext
, syslog_identifier
), SD_BUS_VTABLE_PROPERTY_CONST
),
783 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool
, offsetof(ExecContext
, syslog_level_prefix
), SD_BUS_VTABLE_PROPERTY_CONST
),
784 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
785 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
786 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
787 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int
, offsetof(ExecContext
, secure_bits
), SD_BUS_VTABLE_PROPERTY_CONST
),
788 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", property_get_capability_bounding_set
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
789 SD_BUS_PROPERTY("AmbientCapabilities", "t", property_get_ambient_capabilities
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
790 SD_BUS_PROPERTY("User", "s", NULL
, offsetof(ExecContext
, user
), SD_BUS_VTABLE_PROPERTY_CONST
),
791 SD_BUS_PROPERTY("Group", "s", NULL
, offsetof(ExecContext
, group
), SD_BUS_VTABLE_PROPERTY_CONST
),
792 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool
, offsetof(ExecContext
, dynamic_user
), SD_BUS_VTABLE_PROPERTY_CONST
),
793 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, remove_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
794 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL
, offsetof(ExecContext
, supplementary_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
795 SD_BUS_PROPERTY("PAMName", "s", NULL
, offsetof(ExecContext
, pam_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
796 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
797 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
798 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
799 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
800 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
801 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
802 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong
, offsetof(ExecContext
, mount_flags
), SD_BUS_VTABLE_PROPERTY_CONST
),
803 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool
, offsetof(ExecContext
, private_tmp
), SD_BUS_VTABLE_PROPERTY_CONST
),
804 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool
, offsetof(ExecContext
, private_devices
), SD_BUS_VTABLE_PROPERTY_CONST
),
805 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_tunables
), SD_BUS_VTABLE_PROPERTY_CONST
),
806 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_modules
), SD_BUS_VTABLE_PROPERTY_CONST
),
807 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_control_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
808 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool
, offsetof(ExecContext
, private_network
), SD_BUS_VTABLE_PROPERTY_CONST
),
809 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool
, offsetof(ExecContext
, private_users
), SD_BUS_VTABLE_PROPERTY_CONST
),
810 SD_BUS_PROPERTY("ProtectHome", "s", bus_property_get_protect_home
, offsetof(ExecContext
, protect_home
), SD_BUS_VTABLE_PROPERTY_CONST
),
811 SD_BUS_PROPERTY("ProtectSystem", "s", bus_property_get_protect_system
, offsetof(ExecContext
, protect_system
), SD_BUS_VTABLE_PROPERTY_CONST
),
812 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool
, offsetof(ExecContext
, same_pgrp
), SD_BUS_VTABLE_PROPERTY_CONST
),
813 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL
, offsetof(ExecContext
, utmp_id
), SD_BUS_VTABLE_PROPERTY_CONST
),
814 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode
, offsetof(ExecContext
, utmp_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
815 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
816 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
817 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
818 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool
, offsetof(ExecContext
, ignore_sigpipe
), SD_BUS_VTABLE_PROPERTY_CONST
),
819 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool
, offsetof(ExecContext
, no_new_privileges
), SD_BUS_VTABLE_PROPERTY_CONST
),
820 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
821 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
822 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", property_get_syscall_errno
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
823 SD_BUS_PROPERTY("Personality", "s", property_get_personality
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
824 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
825 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, runtime_directory_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
826 SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL
, offsetof(ExecContext
, runtime_directory
), SD_BUS_VTABLE_PROPERTY_CONST
),
827 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool
, offsetof(ExecContext
, memory_deny_write_execute
), SD_BUS_VTABLE_PROPERTY_CONST
),
828 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_realtime
), SD_BUS_VTABLE_PROPERTY_CONST
),
829 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong
, offsetof(ExecContext
, restrict_namespaces
), SD_BUS_VTABLE_PROPERTY_CONST
),
830 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
831 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
832 SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool
, offsetof(ExecContext
, mount_apivfs
), SD_BUS_VTABLE_PROPERTY_CONST
),
836 static int append_exec_command(sd_bus_message
*reply
, ExecCommand
*c
) {
845 r
= sd_bus_message_open_container(reply
, 'r', "sasbttttuii");
849 r
= sd_bus_message_append(reply
, "s", c
->path
);
853 r
= sd_bus_message_append_strv(reply
, c
->argv
);
857 r
= sd_bus_message_append(reply
, "bttttuii",
859 c
->exec_status
.start_timestamp
.realtime
,
860 c
->exec_status
.start_timestamp
.monotonic
,
861 c
->exec_status
.exit_timestamp
.realtime
,
862 c
->exec_status
.exit_timestamp
.monotonic
,
863 (uint32_t) c
->exec_status
.pid
,
864 (int32_t) c
->exec_status
.code
,
865 (int32_t) c
->exec_status
.status
);
869 return sd_bus_message_close_container(reply
);
872 int bus_property_get_exec_command(
875 const char *interface
,
876 const char *property
,
877 sd_bus_message
*reply
,
879 sd_bus_error
*ret_error
) {
881 ExecCommand
*c
= (ExecCommand
*) userdata
;
887 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
891 r
= append_exec_command(reply
, c
);
895 return sd_bus_message_close_container(reply
);
898 int bus_property_get_exec_command_list(
901 const char *interface
,
902 const char *property
,
903 sd_bus_message
*reply
,
905 sd_bus_error
*ret_error
) {
907 ExecCommand
*c
= *(ExecCommand
**) userdata
;
913 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
917 LIST_FOREACH(command
, c
, c
) {
918 r
= append_exec_command(reply
, c
);
923 return sd_bus_message_close_container(reply
);
926 int bus_exec_context_set_transient_property(
930 sd_bus_message
*message
,
931 UnitSetPropertiesMode mode
,
932 sd_bus_error
*error
) {
934 const char *soft
= NULL
;
942 if (streq(name
, "User")) {
945 r
= sd_bus_message_read(message
, "s", &uu
);
949 if (!isempty(uu
) && !valid_user_group_name_or_id(uu
))
950 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid user name: %s", uu
);
952 if (mode
!= UNIT_CHECK
) {
955 c
->user
= mfree(c
->user
);
956 else if (free_and_strdup(&c
->user
, uu
) < 0)
959 unit_write_drop_in_private_format(u
, mode
, name
, "User=%s", uu
);
964 } else if (streq(name
, "Group")) {
967 r
= sd_bus_message_read(message
, "s", &gg
);
971 if (!isempty(gg
) && !valid_user_group_name_or_id(gg
))
972 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid group name: %s", gg
);
974 if (mode
!= UNIT_CHECK
) {
977 c
->group
= mfree(c
->group
);
978 else if (free_and_strdup(&c
->group
, gg
) < 0)
981 unit_write_drop_in_private_format(u
, mode
, name
, "Group=%s", gg
);
985 } else if (streq(name
, "SyslogIdentifier")) {
988 r
= sd_bus_message_read(message
, "s", &id
);
992 if (mode
!= UNIT_CHECK
) {
995 c
->syslog_identifier
= mfree(c
->syslog_identifier
);
996 else if (free_and_strdup(&c
->syslog_identifier
, id
) < 0)
999 unit_write_drop_in_private_format(u
, mode
, name
, "SyslogIdentifier=%s", id
);
1003 } else if (streq(name
, "SyslogLevel")) {
1006 r
= sd_bus_message_read(message
, "i", &level
);
1010 if (!log_level_is_valid(level
))
1011 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log level value out of range");
1013 if (mode
!= UNIT_CHECK
) {
1014 c
->syslog_priority
= (c
->syslog_priority
& LOG_FACMASK
) | level
;
1015 unit_write_drop_in_private_format(u
, mode
, name
, "SyslogLevel=%i", level
);
1019 } else if (streq(name
, "SyslogFacility")) {
1022 r
= sd_bus_message_read(message
, "i", &facility
);
1026 if (!log_facility_unshifted_is_valid(facility
))
1027 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log facility value out of range");
1029 if (mode
!= UNIT_CHECK
) {
1030 c
->syslog_priority
= (facility
<< 3) | LOG_PRI(c
->syslog_priority
);
1031 unit_write_drop_in_private_format(u
, mode
, name
, "SyslogFacility=%i", facility
);
1035 } else if (streq(name
, "Nice")) {
1038 r
= sd_bus_message_read(message
, "i", &n
);
1042 if (!nice_is_valid(n
))
1043 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Nice value out of range");
1045 if (mode
!= UNIT_CHECK
) {
1047 unit_write_drop_in_private_format(u
, mode
, name
, "Nice=%i", n
);
1052 } else if (STR_IN_SET(name
, "TTYPath", "RootDirectory", "RootImage")) {
1055 r
= sd_bus_message_read(message
, "s", &s
);
1059 if (!path_is_absolute(s
))
1060 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s takes an absolute path", name
);
1062 if (mode
!= UNIT_CHECK
) {
1063 if (streq(name
, "TTYPath"))
1064 r
= free_and_strdup(&c
->tty_path
, s
);
1065 else if (streq(name
, "RootImage"))
1066 r
= free_and_strdup(&c
->root_image
, s
);
1068 assert(streq(name
, "RootDirectory"));
1069 r
= free_and_strdup(&c
->root_directory
, s
);
1074 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, s
);
1079 } else if (streq(name
, "WorkingDirectory")) {
1083 r
= sd_bus_message_read(message
, "s", &s
);
1093 if (!streq(s
, "~") && !path_is_absolute(s
))
1094 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "WorkingDirectory= expects an absolute path or '~'");
1096 if (mode
!= UNIT_CHECK
) {
1097 if (streq(s
, "~")) {
1098 c
->working_directory
= mfree(c
->working_directory
);
1099 c
->working_directory_home
= true;
1101 r
= free_and_strdup(&c
->working_directory
, s
);
1105 c
->working_directory_home
= false;
1108 c
->working_directory_missing_ok
= missing_ok
;
1109 unit_write_drop_in_private_format(u
, mode
, name
, "WorkingDirectory=%s%s", missing_ok
? "-" : "", s
);
1114 } else if (streq(name
, "StandardInput")) {
1118 r
= sd_bus_message_read(message
, "s", &s
);
1122 p
= exec_input_from_string(s
);
1124 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid standard input name");
1126 if (mode
!= UNIT_CHECK
) {
1129 unit_write_drop_in_private_format(u
, mode
, name
, "StandardInput=%s", exec_input_to_string(p
));
1134 } else if (streq(name
, "StandardOutput")) {
1138 r
= sd_bus_message_read(message
, "s", &s
);
1142 p
= exec_output_from_string(s
);
1144 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid standard output name");
1146 if (mode
!= UNIT_CHECK
) {
1149 unit_write_drop_in_private_format(u
, mode
, name
, "StandardOutput=%s", exec_output_to_string(p
));
1154 } else if (streq(name
, "StandardError")) {
1158 r
= sd_bus_message_read(message
, "s", &s
);
1162 p
= exec_output_from_string(s
);
1164 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid standard error name");
1166 if (mode
!= UNIT_CHECK
) {
1169 unit_write_drop_in_private_format(u
, mode
, name
, "StandardError=%s", exec_output_to_string(p
));
1174 } else if (STR_IN_SET(name
,
1175 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
1178 r
= sd_bus_message_read(message
, "s", &s
);
1182 if (!fdname_is_valid(s
))
1183 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid file descriptor name");
1185 if (mode
!= UNIT_CHECK
) {
1186 if (streq(name
, "StandardInputFileDescriptorName")) {
1187 c
->std_input
= EXEC_INPUT_NAMED_FD
;
1188 r
= free_and_strdup(&c
->stdio_fdname
[STDIN_FILENO
], s
);
1191 unit_write_drop_in_private_format(u
, mode
, name
, "StandardInput=fd:%s", s
);
1192 } else if (streq(name
, "StandardOutputFileDescriptorName")) {
1193 c
->std_output
= EXEC_OUTPUT_NAMED_FD
;
1194 r
= free_and_strdup(&c
->stdio_fdname
[STDOUT_FILENO
], s
);
1197 unit_write_drop_in_private_format(u
, mode
, name
, "StandardOutput=fd:%s", s
);
1198 } else if (streq(name
, "StandardErrorFileDescriptorName")) {
1199 c
->std_error
= EXEC_OUTPUT_NAMED_FD
;
1200 r
= free_and_strdup(&c
->stdio_fdname
[STDERR_FILENO
], s
);
1203 unit_write_drop_in_private_format(u
, mode
, name
, "StandardError=fd:%s", s
);
1209 } else if (STR_IN_SET(name
,
1210 "IgnoreSIGPIPE", "TTYVHangup", "TTYReset",
1211 "PrivateTmp", "PrivateDevices", "PrivateNetwork", "PrivateUsers",
1212 "NoNewPrivileges", "SyslogLevelPrefix", "MemoryDenyWriteExecute",
1213 "RestrictRealtime", "DynamicUser", "RemoveIPC", "ProtectKernelTunables",
1214 "ProtectKernelModules", "ProtectControlGroups", "MountAPIVFS")) {
1217 r
= sd_bus_message_read(message
, "b", &b
);
1221 if (mode
!= UNIT_CHECK
) {
1222 if (streq(name
, "IgnoreSIGPIPE"))
1223 c
->ignore_sigpipe
= b
;
1224 else if (streq(name
, "TTYVHangup"))
1226 else if (streq(name
, "TTYReset"))
1228 else if (streq(name
, "PrivateTmp"))
1230 else if (streq(name
, "PrivateDevices"))
1231 c
->private_devices
= b
;
1232 else if (streq(name
, "PrivateNetwork"))
1233 c
->private_network
= b
;
1234 else if (streq(name
, "PrivateUsers"))
1235 c
->private_users
= b
;
1236 else if (streq(name
, "NoNewPrivileges"))
1237 c
->no_new_privileges
= b
;
1238 else if (streq(name
, "SyslogLevelPrefix"))
1239 c
->syslog_level_prefix
= b
;
1240 else if (streq(name
, "MemoryDenyWriteExecute"))
1241 c
->memory_deny_write_execute
= b
;
1242 else if (streq(name
, "RestrictRealtime"))
1243 c
->restrict_realtime
= b
;
1244 else if (streq(name
, "DynamicUser"))
1245 c
->dynamic_user
= b
;
1246 else if (streq(name
, "RemoveIPC"))
1248 else if (streq(name
, "ProtectKernelTunables"))
1249 c
->protect_kernel_tunables
= b
;
1250 else if (streq(name
, "ProtectKernelModules"))
1251 c
->protect_kernel_modules
= b
;
1252 else if (streq(name
, "ProtectControlGroups"))
1253 c
->protect_control_groups
= b
;
1254 else if (streq(name
, "MountAPIVFS"))
1255 c
->mount_apivfs
= b
;
1257 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, yes_no(b
));
1262 } else if (streq(name
, "UtmpIdentifier")) {
1265 r
= sd_bus_message_read(message
, "s", &id
);
1269 if (mode
!= UNIT_CHECK
) {
1271 c
->utmp_id
= mfree(c
->utmp_id
);
1272 else if (free_and_strdup(&c
->utmp_id
, id
) < 0)
1275 unit_write_drop_in_private_format(u
, mode
, name
, "UtmpIdentifier=%s", strempty(id
));
1280 } else if (streq(name
, "UtmpMode")) {
1284 r
= sd_bus_message_read(message
, "s", &s
);
1288 m
= exec_utmp_mode_from_string(s
);
1290 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid utmp mode");
1292 if (mode
!= UNIT_CHECK
) {
1295 unit_write_drop_in_private_format(u
, mode
, name
, "UtmpMode=%s", exec_utmp_mode_to_string(m
));
1300 } else if (streq(name
, "PAMName")) {
1303 r
= sd_bus_message_read(message
, "s", &n
);
1307 if (mode
!= UNIT_CHECK
) {
1309 c
->pam_name
= mfree(c
->pam_name
);
1310 else if (free_and_strdup(&c
->pam_name
, n
) < 0)
1313 unit_write_drop_in_private_format(u
, mode
, name
, "PAMName=%s", strempty(n
));
1318 } else if (streq(name
, "Environment")) {
1320 _cleanup_strv_free_
char **l
= NULL
;
1322 r
= sd_bus_message_read_strv(message
, &l
);
1326 if (!strv_env_is_valid(l
))
1327 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment block.");
1329 if (mode
!= UNIT_CHECK
) {
1330 _cleanup_free_
char *joined
= NULL
;
1333 if (strv_length(l
) == 0) {
1334 c
->environment
= strv_free(c
->environment
);
1335 unit_write_drop_in_private_format(u
, mode
, name
, "Environment=");
1337 e
= strv_env_merge(2, c
->environment
, l
);
1341 strv_free(c
->environment
);
1344 joined
= strv_join_quoted(c
->environment
);
1348 unit_write_drop_in_private_format(u
, mode
, name
, "Environment=%s", joined
);
1354 } else if (streq(name
, "TimerSlackNSec")) {
1358 r
= sd_bus_message_read(message
, "t", &n
);
1362 if (mode
!= UNIT_CHECK
) {
1363 c
->timer_slack_nsec
= n
;
1364 unit_write_drop_in_private_format(u
, mode
, name
, "TimerSlackNSec=" NSEC_FMT
, n
);
1369 } else if (streq(name
, "OOMScoreAdjust")) {
1372 r
= sd_bus_message_read(message
, "i", &oa
);
1376 if (!oom_score_adjust_is_valid(oa
))
1377 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "OOM score adjust value out of range");
1379 if (mode
!= UNIT_CHECK
) {
1380 c
->oom_score_adjust
= oa
;
1381 c
->oom_score_adjust_set
= true;
1382 unit_write_drop_in_private_format(u
, mode
, name
, "OOMScoreAdjust=%i", oa
);
1387 } else if (streq(name
, "EnvironmentFiles")) {
1389 _cleanup_free_
char *joined
= NULL
;
1390 _cleanup_fclose_
FILE *f
= NULL
;
1391 _cleanup_strv_free_
char **l
= NULL
;
1395 r
= sd_bus_message_enter_container(message
, 'a', "(sb)");
1399 f
= open_memstream(&joined
, &size
);
1403 STRV_FOREACH(i
, c
->environment_files
)
1404 fprintf(f
, "EnvironmentFile=%s", *i
);
1406 while ((r
= sd_bus_message_enter_container(message
, 'r', "sb")) > 0) {
1410 r
= sd_bus_message_read(message
, "sb", &path
, &b
);
1414 r
= sd_bus_message_exit_container(message
);
1418 if (!path_is_absolute(path
))
1419 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
1421 if (mode
!= UNIT_CHECK
) {
1424 buf
= strjoin(b
? "-" : "", path
);
1428 fprintf(f
, "EnvironmentFile=%s", buf
);
1430 r
= strv_consume(&l
, buf
);
1438 r
= sd_bus_message_exit_container(message
);
1442 r
= fflush_and_check(f
);
1446 if (mode
!= UNIT_CHECK
) {
1447 if (strv_isempty(l
)) {
1448 c
->environment_files
= strv_free(c
->environment_files
);
1449 unit_write_drop_in_private(u
, mode
, name
, "EnvironmentFile=");
1451 r
= strv_extend_strv(&c
->environment_files
, l
, true);
1455 unit_write_drop_in_private(u
, mode
, name
, joined
);
1461 } else if (streq(name
, "PassEnvironment")) {
1463 _cleanup_strv_free_
char **l
= NULL
;
1465 r
= sd_bus_message_read_strv(message
, &l
);
1469 if (!strv_env_name_is_valid(l
))
1470 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PassEnvironment block.");
1472 if (mode
!= UNIT_CHECK
) {
1473 if (strv_isempty(l
)) {
1474 c
->pass_environment
= strv_free(c
->pass_environment
);
1475 unit_write_drop_in_private_format(u
, mode
, name
, "PassEnvironment=");
1477 _cleanup_free_
char *joined
= NULL
;
1479 r
= strv_extend_strv(&c
->pass_environment
, l
, true);
1483 joined
= strv_join_quoted(c
->pass_environment
);
1487 unit_write_drop_in_private_format(u
, mode
, name
, "PassEnvironment=%s", joined
);
1493 } else if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
1494 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) {
1495 _cleanup_strv_free_
char **l
= NULL
;
1499 r
= sd_bus_message_read_strv(message
, &l
);
1503 STRV_FOREACH(p
, l
) {
1507 if (!utf8_is_valid(i
))
1508 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
1510 offset
= i
[0] == '-';
1511 offset
+= i
[offset
] == '+';
1512 if (!path_is_absolute(i
+ offset
))
1513 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
1516 if (mode
!= UNIT_CHECK
) {
1517 _cleanup_free_
char *joined
= NULL
;
1519 if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadWritePaths"))
1520 dirs
= &c
->read_write_paths
;
1521 else if (STR_IN_SET(name
, "ReadOnlyDirectories", "ReadOnlyPaths"))
1522 dirs
= &c
->read_only_paths
;
1523 else /* "InaccessiblePaths" */
1524 dirs
= &c
->inaccessible_paths
;
1526 if (strv_length(l
) == 0) {
1527 *dirs
= strv_free(*dirs
);
1528 unit_write_drop_in_private_format(u
, mode
, name
, "%s=", name
);
1530 r
= strv_extend_strv(dirs
, l
, true);
1534 joined
= strv_join_quoted(*dirs
);
1538 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, joined
);
1545 } else if (streq(name
, "ProtectSystem")) {
1549 r
= sd_bus_message_read(message
, "s", &s
);
1553 r
= parse_boolean(s
);
1555 ps
= PROTECT_SYSTEM_YES
;
1557 ps
= PROTECT_SYSTEM_NO
;
1559 ps
= protect_system_from_string(s
);
1561 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Failed to parse protect system value");
1564 if (mode
!= UNIT_CHECK
) {
1565 c
->protect_system
= ps
;
1566 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, s
);
1571 } else if (streq(name
, "ProtectHome")) {
1575 r
= sd_bus_message_read(message
, "s", &s
);
1579 r
= parse_boolean(s
);
1581 ph
= PROTECT_HOME_YES
;
1583 ph
= PROTECT_HOME_NO
;
1585 ph
= protect_home_from_string(s
);
1587 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Failed to parse protect home value");
1590 if (mode
!= UNIT_CHECK
) {
1591 c
->protect_home
= ph
;
1592 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, s
);
1597 } else if (streq(name
, "RuntimeDirectory")) {
1598 _cleanup_strv_free_
char **l
= NULL
;
1601 r
= sd_bus_message_read_strv(message
, &l
);
1605 STRV_FOREACH(p
, l
) {
1606 if (!filename_is_valid(*p
))
1607 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Runtime directory is not valid %s", *p
);
1610 if (mode
!= UNIT_CHECK
) {
1611 _cleanup_free_
char *joined
= NULL
;
1613 if (strv_isempty(l
)) {
1614 c
->runtime_directory
= strv_free(c
->runtime_directory
);
1615 unit_write_drop_in_private_format(u
, mode
, name
, "%s=", name
);
1617 r
= strv_extend_strv(&c
->runtime_directory
, l
, true);
1622 joined
= strv_join_quoted(c
->runtime_directory
);
1626 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, joined
);
1632 } else if (streq(name
, "SELinuxContext")) {
1635 r
= sd_bus_message_read(message
, "s", &s
);
1639 if (mode
!= UNIT_CHECK
) {
1641 c
->selinux_context
= mfree(c
->selinux_context
);
1642 else if (free_and_strdup(&c
->selinux_context
, s
) < 0)
1645 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, strempty(s
));
1649 } else if (streq(name
, "RestrictNamespaces")) {
1652 r
= sd_bus_message_read(message
, "t", &flags
);
1655 if ((flags
& NAMESPACE_FLAGS_ALL
) != flags
)
1656 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown namespace types");
1658 if (mode
!= UNIT_CHECK
) {
1659 _cleanup_free_
char *s
= NULL
;
1661 r
= namespace_flag_to_string_many(flags
, &s
);
1665 c
->restrict_namespaces
= flags
;
1666 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, s
);
1670 } else if (streq(name
, "MountFlags")) {
1673 r
= sd_bus_message_read(message
, "t", &flags
);
1676 if (!IN_SET(flags
, 0, MS_SHARED
, MS_PRIVATE
, MS_SLAVE
))
1677 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount propagation flags");
1679 if (mode
!= UNIT_CHECK
) {
1680 c
->mount_flags
= flags
;
1682 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, mount_propagation_flags_to_string(flags
));
1686 } else if (STR_IN_SET(name
, "BindPaths", "BindReadOnlyPaths")) {
1687 unsigned empty
= true;
1689 r
= sd_bus_message_enter_container(message
, 'a', "(ssbt)");
1693 while ((r
= sd_bus_message_enter_container(message
, 'r', "ssbt")) > 0) {
1694 const char *source
, *destination
;
1696 uint64_t mount_flags
;
1698 r
= sd_bus_message_read(message
, "ssbt", &source
, &destination
, &ignore_enoent
, &mount_flags
);
1702 r
= sd_bus_message_exit_container(message
);
1706 if (!path_is_absolute(source
))
1707 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
1708 if (!path_is_absolute(destination
))
1709 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
1710 if (!IN_SET(mount_flags
, 0, MS_REC
))
1711 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount flags.");
1713 if (mode
!= UNIT_CHECK
) {
1714 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
1716 .source
= strdup(source
),
1717 .destination
= strdup(destination
),
1718 .read_only
= !!strstr(name
, "ReadOnly"),
1719 .recursive
= !!(mount_flags
& MS_REC
),
1720 .ignore_enoent
= ignore_enoent
,
1725 unit_write_drop_in_private_format(
1729 ignore_enoent
? "-" : "",
1732 (mount_flags
& MS_REC
) ? "rbind" : "norbind");
1740 r
= sd_bus_message_exit_container(message
);
1745 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
1746 c
->bind_mounts
= NULL
;
1747 c
->n_bind_mounts
= 0;
1753 ri
= rlimit_from_string(name
);
1755 soft
= endswith(name
, "Soft");
1759 n
= strndupa(name
, soft
- name
);
1760 ri
= rlimit_from_string(n
);
1771 r
= sd_bus_message_read(message
, "t", &rl
);
1775 if (rl
== (uint64_t) -1)
1780 if ((uint64_t) x
!= rl
)
1784 if (mode
!= UNIT_CHECK
) {
1785 _cleanup_free_
char *f
= NULL
;
1788 if (c
->rlimit
[ri
]) {
1789 nl
= *c
->rlimit
[ri
];
1796 /* When the resource limit is not initialized yet, then assign the value to both fields */
1797 nl
= (struct rlimit
) {
1802 r
= rlimit_format(&nl
, &f
);
1807 *c
->rlimit
[ri
] = nl
;
1809 c
->rlimit
[ri
] = newdup(struct rlimit
, &nl
, 1);
1814 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, f
);