1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include <linux/oom.h>
29 #include <sys/prctl.h>
30 #include <sys/mount.h>
34 #include "conf-parser.h"
35 #include "load-fragment.h"
38 #include "securebits.h"
40 #include "unit-name.h"
42 #define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \
43 static int function( \
44 const char *filename, \
46 const char *section, \
59 if ((x = name##_from_string(rvalue)) < 0) { \
60 log_error("[%s:%u] " msg ": %s", filename, line, rvalue); \
69 static int config_parse_deps(
78 UnitDependency d
= PTR_TO_UINT(data
);
88 FOREACH_WORD(w
, l
, rvalue
, state
) {
92 if (!(t
= strndup(w
, l
)))
95 k
= unit_name_printf(u
, t
);
101 r
= unit_add_dependency_by_name(u
, d
, k
, NULL
, true);
111 static int config_parse_names(
112 const char *filename
,
130 FOREACH_WORD(w
, l
, rvalue
, state
) {
134 if (!(t
= strndup(w
, l
)))
137 k
= unit_name_printf(u
, t
);
143 r
= unit_merge_by_name(u
, k
);
153 static int config_parse_listen(
154 const char *filename
,
173 if (!(p
= new0(SocketPort
, 1)))
176 if (streq(lvalue
, "ListenFIFO")) {
177 p
->type
= SOCKET_FIFO
;
179 if (!(p
->path
= strdup(rvalue
))) {
184 p
->type
= SOCKET_SOCKET
;
186 if ((r
= socket_address_parse(&p
->address
, rvalue
)) < 0) {
187 log_error("[%s:%u] Failed to parse address value: %s", filename
, line
, rvalue
);
192 if (streq(lvalue
, "ListenStream"))
193 p
->address
.type
= SOCK_STREAM
;
194 else if (streq(lvalue
, "ListenDatagram"))
195 p
->address
.type
= SOCK_DGRAM
;
197 assert(streq(lvalue
, "ListenSequentialPacket"));
198 p
->address
.type
= SOCK_SEQPACKET
;
201 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
203 return -EPROTONOSUPPORT
;
208 LIST_PREPEND(SocketPort
, port
, s
->ports
, p
);
213 static int config_parse_socket_bind(
214 const char *filename
,
232 if ((r
= parse_boolean(rvalue
)) < 0) {
233 log_error("[%s:%u] Failed to parse bind IPv6 only value: %s", filename
, line
, rvalue
);
237 s
->bind_ipv6_only
= r
? SOCKET_ADDRESS_IPV6_ONLY
: SOCKET_ADDRESS_BOTH
;
242 static int config_parse_nice(
243 const char *filename
,
251 ExecContext
*c
= data
;
259 if ((r
= safe_atoi(rvalue
, &priority
)) < 0) {
260 log_error("[%s:%u] Failed to parse nice priority: %s", filename
, line
, rvalue
);
264 if (priority
< PRIO_MIN
|| priority
>= PRIO_MAX
) {
265 log_error("[%s:%u] Nice priority out of range: %s", filename
, line
, rvalue
);
275 static int config_parse_oom_adjust(
276 const char *filename
,
284 ExecContext
*c
= data
;
292 if ((r
= safe_atoi(rvalue
, &oa
)) < 0) {
293 log_error("[%s:%u] Failed to parse OOM adjust value: %s", filename
, line
, rvalue
);
297 if (oa
< OOM_DISABLE
|| oa
> OOM_ADJUST_MAX
) {
298 log_error("[%s:%u] OOM adjust value out of range: %s", filename
, line
, rvalue
);
303 c
->oom_adjust_set
= true;
308 static int config_parse_mode(
309 const char *filename
,
327 l
= strtol(rvalue
, &x
, 8);
328 if (!x
|| *x
|| errno
) {
329 log_error("[%s:%u] Failed to parse mode value: %s", filename
, line
, rvalue
);
330 return errno
? -errno
: -EINVAL
;
333 if (l
< 0000 || l
> 07777) {
334 log_error("[%s:%u] mode value out of range: %s", filename
, line
, rvalue
);
342 static int config_parse_exec(
343 const char *filename
,
351 ExecCommand
**e
= data
, *nce
= NULL
;
364 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
)
367 if (!(n
= new(char*, k
+1)))
371 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
)
372 if (!(n
[k
++] = strndup(w
, l
)))
377 if (!n
[0] || !path_is_absolute(n
[0])) {
378 log_error("[%s:%u] Invalid executable path in command line: %s", filename
, line
, rvalue
);
383 if (!(nce
= new0(ExecCommand
, 1)))
387 if (!(nce
->path
= strdup(n
[0])))
390 exec_command_append_list(e
, nce
);
404 static int config_parse_usec(
405 const char *filename
,
414 unsigned long long u
;
422 if ((r
= safe_atollu(rvalue
, &u
)) < 0) {
423 log_error("[%s:%u] Failed to parse time value: %s", filename
, line
, rvalue
);
427 /* We actually assume the user configures seconds. Later on we
428 * might choose to support suffixes for time values, to
429 * configure bigger or smaller units */
431 *usec
= u
* USEC_PER_SEC
;
436 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
437 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
439 static int config_parse_bindtodevice(
440 const char *filename
,
456 if (rvalue
[0] && !streq(rvalue
, "*")) {
457 if (!(n
= strdup(rvalue
)))
462 free(s
->bind_to_device
);
463 s
->bind_to_device
= n
;
468 DEFINE_CONFIG_PARSE_ENUM(config_parse_output
, exec_output
, ExecOutput
, "Failed to parse output specifier");
469 DEFINE_CONFIG_PARSE_ENUM(config_parse_input
, exec_input
, ExecInput
, "Failed to parse input specifier");
471 static int config_parse_facility(
472 const char *filename
,
488 if ((x
= log_facility_from_string(rvalue
)) < 0) {
489 log_error("[%s:%u] Failed to parse log facility: %s", filename
, line
, rvalue
);
493 *o
= LOG_MAKEPRI(x
, LOG_PRI(*o
));
498 static int config_parse_level(
499 const char *filename
,
515 if ((x
= log_level_from_string(rvalue
)) < 0) {
516 log_error("[%s:%u] Failed to parse log level: %s", filename
, line
, rvalue
);
520 *o
= LOG_MAKEPRI(LOG_FAC(*o
), x
);
524 static int config_parse_io_class(
525 const char *filename
,
533 ExecContext
*c
= data
;
541 if ((x
= ioprio_class_from_string(rvalue
)) < 0) {
542 log_error("[%s:%u] Failed to parse IO scheduling class: %s", filename
, line
, rvalue
);
546 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
547 c
->ioprio_set
= true;
552 static int config_parse_io_priority(
553 const char *filename
,
561 ExecContext
*c
= data
;
569 if (safe_atoi(rvalue
, &i
) < 0 || i
< 0 || i
>= IOPRIO_BE_NR
) {
570 log_error("[%s:%u] Failed to parse io priority: %s", filename
, line
, rvalue
);
574 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
575 c
->ioprio_set
= true;
580 static int config_parse_cpu_sched_policy(
581 const char *filename
,
590 ExecContext
*c
= data
;
598 if ((x
= sched_policy_from_string(rvalue
)) < 0) {
599 log_error("[%s:%u] Failed to parse CPU scheduling policy: %s", filename
, line
, rvalue
);
603 c
->cpu_sched_policy
= x
;
604 c
->cpu_sched_set
= true;
609 static int config_parse_cpu_sched_prio(
610 const char *filename
,
618 ExecContext
*c
= data
;
626 /* On Linux RR/FIFO have the same range */
627 if (safe_atoi(rvalue
, &i
) < 0 || i
< sched_get_priority_min(SCHED_RR
) || i
> sched_get_priority_max(SCHED_RR
)) {
628 log_error("[%s:%u] Failed to parse CPU scheduling priority: %s", filename
, line
, rvalue
);
632 c
->cpu_sched_priority
= i
;
633 c
->cpu_sched_set
= true;
638 static int config_parse_cpu_affinity(
639 const char *filename
,
647 ExecContext
*c
= data
;
657 FOREACH_WORD(w
, l
, rvalue
, state
) {
662 if (!(t
= strndup(w
, l
)))
665 r
= safe_atou(t
, &cpu
);
668 if (r
< 0 || cpu
>= CPU_SETSIZE
) {
669 log_error("[%s:%u] Failed to parse CPU affinity: %s", filename
, line
, rvalue
);
673 CPU_SET(cpu
, &c
->cpu_affinity
);
676 c
->cpu_affinity_set
= true;
681 static int config_parse_capabilities(
682 const char *filename
,
690 ExecContext
*c
= data
;
698 if (!(cap
= cap_from_text(rvalue
))) {
702 log_error("[%s:%u] Failed to parse capabilities: %s", filename
, line
, rvalue
);
707 cap_free(c
->capabilities
);
708 c
->capabilities
= cap
;
713 static int config_parse_secure_bits(
714 const char *filename
,
722 ExecContext
*c
= data
;
732 FOREACH_WORD(w
, l
, rvalue
, state
) {
733 if (first_word(w
, "keep-caps"))
734 c
->secure_bits
|= SECURE_KEEP_CAPS
;
735 else if (first_word(w
, "keep-caps-locked"))
736 c
->secure_bits
|= SECURE_KEEP_CAPS_LOCKED
;
737 else if (first_word(w
, "no-setuid-fixup"))
738 c
->secure_bits
|= SECURE_NO_SETUID_FIXUP
;
739 else if (first_word(w
, "no-setuid-fixup-locked"))
740 c
->secure_bits
|= SECURE_NO_SETUID_FIXUP_LOCKED
;
741 else if (first_word(w
, "noroot"))
742 c
->secure_bits
|= SECURE_NOROOT
;
743 else if (first_word(w
, "noroot-locked"))
744 c
->secure_bits
|= SECURE_NOROOT_LOCKED
;
746 log_error("[%s:%u] Failed to parse secure bits: %s", filename
, line
, rvalue
);
754 static int config_parse_bounding_set(
755 const char *filename
,
763 ExecContext
*c
= data
;
773 FOREACH_WORD(w
, l
, rvalue
, state
) {
778 if (!(t
= strndup(w
, l
)))
781 r
= cap_from_name(t
, &cap
);
785 log_error("[%s:%u] Failed to parse capability bounding set: %s", filename
, line
, rvalue
);
789 c
->capability_bounding_set_drop
|= 1 << cap
;
795 static int config_parse_timer_slack_ns(
796 const char *filename
,
804 ExecContext
*c
= data
;
813 if ((r
= safe_atolu(rvalue
, &u
)) < 0) {
814 log_error("[%s:%u] Failed to parse time slack value: %s", filename
, line
, rvalue
);
818 c
->timer_slack_ns
= u
;
823 static int config_parse_limit(
824 const char *filename
,
832 struct rlimit
**rl
= data
;
833 unsigned long long u
;
841 if ((r
= safe_atollu(rvalue
, &u
)) < 0) {
842 log_error("[%s:%u] Failed to parse resource value: %s", filename
, line
, rvalue
);
847 if (!(*rl
= new(struct rlimit
, 1)))
850 (*rl
)->rlim_cur
= (*rl
)->rlim_max
= (rlim_t
) u
;
854 static int config_parse_cgroup(
855 const char *filename
,
868 FOREACH_WORD(w
, l
, rvalue
, state
) {
872 if (!(t
= strndup(w
, l
)))
875 r
= unit_add_cgroup_from_text(u
, t
);
885 static int config_parse_sysv_priority(
886 const char *filename
,
894 int *priority
= data
;
902 if ((r
= safe_atoi(rvalue
, &i
)) < 0 || i
< 0) {
903 log_error("[%s:%u] Failed to parse SysV start priority: %s", filename
, line
, rvalue
);
911 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
913 static int config_parse_mount_flags(
914 const char *filename
,
922 ExecContext
*c
= data
;
926 unsigned long flags
= 0;
933 FOREACH_WORD(w
, l
, rvalue
, state
) {
934 if (strncmp(w
, "shared", l
) == 0)
936 else if (strncmp(w
, "slave", l
) == 0)
938 else if (strncmp(w
, "private", l
) == 0)
941 log_error("[%s:%u] Failed to parse mount flags: %s", filename
, line
, rvalue
);
946 c
->mount_flags
= flags
;
952 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
963 /* This will update the filename pointer if the loaded file is
964 * reached by a symlink. The old string will be freed. */
967 char *target
, *k
, *name
;
969 if (c
++ >= FOLLOW_MAX
)
972 path_kill_slashes(*filename
);
974 /* Add the file name we are currently looking at to
975 * the names of this unit */
976 name
= file_name_from_path(*filename
);
977 if (!(id
= set_get(names
, name
))) {
979 if (!(id
= strdup(name
)))
982 if ((r
= set_put(names
, id
)) < 0) {
988 /* Try to open the file name, but don't if its a symlink */
989 if ((fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
)) >= 0)
995 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
996 if ((r
= readlink_malloc(*filename
, &target
)) < 0)
999 k
= file_in_same_dir(*filename
, target
);
1009 if (!(f
= fdopen(fd
, "r"))) {
1011 close_nointr_nofail(fd
);
1020 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
1028 /* Let's try to add in all symlink names we found */
1029 while ((k
= set_steal_first(names
))) {
1031 /* First try to merge in the other name into our
1033 if ((r
= unit_merge_by_name(*u
, k
)) < 0) {
1036 /* Hmm, we couldn't merge the other unit into
1037 * ours? Then let's try it the other way
1040 other
= manager_get_unit((*u
)->meta
.manager
, k
);
1044 if ((r
= unit_merge(other
, *u
)) >= 0) {
1046 return merge_by_names(u
, names
, NULL
);
1053 unit_choose_id(*u
, id
);
1061 static void dump_items(FILE *f
, const ConfigItem
*items
) {
1062 const ConfigItem
*i
;
1063 const char *prev_section
= NULL
;
1064 bool not_first
= false;
1067 ConfigParserCallback callback
;
1070 { config_parse_int
, "INTEGER" },
1071 { config_parse_unsigned
, "UNSIGNED" },
1072 { config_parse_size
, "SIZE" },
1073 { config_parse_bool
, "BOOLEAN" },
1074 { config_parse_string
, "STRING" },
1075 { config_parse_path
, "PATH" },
1076 { config_parse_strv
, "STRING [...]" },
1077 { config_parse_nice
, "NICE" },
1078 { config_parse_oom_adjust
, "OOMADJUST" },
1079 { config_parse_io_class
, "IOCLASS" },
1080 { config_parse_io_priority
, "IOPRIORITY" },
1081 { config_parse_cpu_sched_policy
, "CPUSCHEDPOLICY" },
1082 { config_parse_cpu_sched_prio
, "CPUSCHEDPRIO" },
1083 { config_parse_cpu_affinity
, "CPUAFFINITY" },
1084 { config_parse_mode
, "MODE" },
1085 { config_parse_output
, "OUTPUT" },
1086 { config_parse_input
, "INPUT" },
1087 { config_parse_facility
, "FACILITY" },
1088 { config_parse_level
, "LEVEL" },
1089 { config_parse_capabilities
, "CAPABILITIES" },
1090 { config_parse_secure_bits
, "SECUREBITS" },
1091 { config_parse_bounding_set
, "BOUNDINGSET" },
1092 { config_parse_timer_slack_ns
, "TIMERSLACK" },
1093 { config_parse_limit
, "LIMIT" },
1094 { config_parse_cgroup
, "CGROUP [...]" },
1095 { config_parse_deps
, "UNIT [...]" },
1096 { config_parse_names
, "UNIT [...]" },
1097 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
1098 { config_parse_service_type
, "SERVICETYPE" },
1099 { config_parse_service_restart
, "SERVICERESTART" },
1100 { config_parse_sysv_priority
, "SYSVPRIORITY" },
1101 { config_parse_kill_mode
, "KILLMODE" },
1102 { config_parse_listen
, "SOCKET [...]" },
1103 { config_parse_socket_bind
, "SOCKETBIND" },
1104 { config_parse_bindtodevice
, "NETWORKINTERFACE" }
1110 for (i
= items
; i
->lvalue
; i
++) {
1112 const char *rvalue
= "OTHER";
1114 if (!streq_ptr(i
->section
, prev_section
)) {
1120 fprintf(f
, "[%s]\n", i
->section
);
1121 prev_section
= i
->section
;
1124 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
1125 if (i
->parse
== table
[j
].callback
) {
1126 rvalue
= table
[j
].rvalue
;
1130 fprintf(f
, "%s=%s\n", i
->lvalue
, rvalue
);
1134 static int load_from_path(Unit
*u
, const char *path
) {
1136 static const char* const section_table
[_UNIT_TYPE_MAX
] = {
1137 [UNIT_SERVICE
] = "Service",
1138 [UNIT_TIMER
] = "Timer",
1139 [UNIT_SOCKET
] = "Socket",
1140 [UNIT_TARGET
] = "Target",
1141 [UNIT_DEVICE
] = "Device",
1142 [UNIT_MOUNT
] = "Mount",
1143 [UNIT_AUTOMOUNT
] = "Automount",
1144 [UNIT_SNAPSHOT
] = "Snapshot"
1147 #define EXEC_CONTEXT_CONFIG_ITEMS(context, section) \
1148 { "WorkingDirectory", config_parse_path, &(context).working_directory, section }, \
1149 { "RootDirectory", config_parse_path, &(context).root_directory, section }, \
1150 { "User", config_parse_string, &(context).user, section }, \
1151 { "Group", config_parse_string, &(context).group, section }, \
1152 { "SupplementaryGroups", config_parse_strv, &(context).supplementary_groups, section }, \
1153 { "Nice", config_parse_nice, &(context), section }, \
1154 { "OOMAdjust", config_parse_oom_adjust, &(context), section }, \
1155 { "IOSchedulingClass", config_parse_io_class, &(context), section }, \
1156 { "IOSchedulingPriority", config_parse_io_priority, &(context), section }, \
1157 { "CPUSchedulingPolicy", config_parse_cpu_sched_policy,&(context), section }, \
1158 { "CPUSchedulingPriority", config_parse_cpu_sched_prio, &(context), section }, \
1159 { "CPUSchedulingResetOnFork", config_parse_bool, &(context).cpu_sched_reset_on_fork, section }, \
1160 { "CPUAffinity", config_parse_cpu_affinity, &(context), section }, \
1161 { "UMask", config_parse_mode, &(context).umask, section }, \
1162 { "Environment", config_parse_strv, &(context).environment, section }, \
1163 { "StandardInput", config_parse_input, &(context).std_input, section }, \
1164 { "StandardOutput", config_parse_output, &(context).std_output, section }, \
1165 { "StandardError", config_parse_output, &(context).std_output, section }, \
1166 { "TTYPath", config_parse_path, &(context).tty_path, section }, \
1167 { "SyslogIdentifier", config_parse_string, &(context).syslog_identifier, section }, \
1168 { "SyslogFacility", config_parse_facility, &(context).syslog_priority, section }, \
1169 { "SyslogLevel", config_parse_level, &(context).syslog_priority, section }, \
1170 { "Capabilities", config_parse_capabilities, &(context), section }, \
1171 { "SecureBits", config_parse_secure_bits, &(context), section }, \
1172 { "CapabilityBoundingSetDrop", config_parse_bounding_set, &(context), section }, \
1173 { "TimerSlackNS", config_parse_timer_slack_ns, &(context), section }, \
1174 { "LimitCPU", config_parse_limit, &(context).rlimit[RLIMIT_CPU], section }, \
1175 { "LimitFSIZE", config_parse_limit, &(context).rlimit[RLIMIT_FSIZE], section }, \
1176 { "LimitDATA", config_parse_limit, &(context).rlimit[RLIMIT_DATA], section }, \
1177 { "LimitSTACK", config_parse_limit, &(context).rlimit[RLIMIT_STACK], section }, \
1178 { "LimitCORE", config_parse_limit, &(context).rlimit[RLIMIT_CORE], section }, \
1179 { "LimitRSS", config_parse_limit, &(context).rlimit[RLIMIT_RSS], section }, \
1180 { "LimitNOFILE", config_parse_limit, &(context).rlimit[RLIMIT_NOFILE], section }, \
1181 { "LimitAS", config_parse_limit, &(context).rlimit[RLIMIT_AS], section }, \
1182 { "LimitNPROC", config_parse_limit, &(context).rlimit[RLIMIT_NPROC], section }, \
1183 { "LimitMEMLOCK", config_parse_limit, &(context).rlimit[RLIMIT_MEMLOCK], section }, \
1184 { "LimitLOCKS", config_parse_limit, &(context).rlimit[RLIMIT_LOCKS], section }, \
1185 { "LimitSIGPENDING", config_parse_limit, &(context).rlimit[RLIMIT_SIGPENDING], section }, \
1186 { "LimitMSGQUEUE", config_parse_limit, &(context).rlimit[RLIMIT_MSGQUEUE], section }, \
1187 { "LimitNICE", config_parse_limit, &(context).rlimit[RLIMIT_NICE], section }, \
1188 { "LimitRTPRIO", config_parse_limit, &(context).rlimit[RLIMIT_RTPRIO], section }, \
1189 { "LimitRTTIME", config_parse_limit, &(context).rlimit[RLIMIT_RTTIME], section }, \
1190 { "ControlGroup", config_parse_cgroup, u, section }, \
1191 { "ReadWriteDirectories", config_parse_path_strv, &(context).read_write_dirs, section }, \
1192 { "ReadOnlyDirectories", config_parse_path_strv, &(context).read_only_dirs, section }, \
1193 { "InaccessibleDirectories",config_parse_path_strv, &(context).inaccessible_dirs, section }, \
1194 { "PrivateTmp", config_parse_bool, &(context).private_tmp, section }, \
1195 { "MountFlags", config_parse_mount_flags, &(context), section }
1197 const ConfigItem items
[] = {
1198 { "Names", config_parse_names
, u
, "Unit" },
1199 { "Description", config_parse_string
, &u
->meta
.description
, "Unit" },
1200 { "Requires", config_parse_deps
, UINT_TO_PTR(UNIT_REQUIRES
), "Unit" },
1201 { "RequiresOverridable", config_parse_deps
, UINT_TO_PTR(UNIT_REQUIRES_OVERRIDABLE
), "Unit" },
1202 { "Requisite", config_parse_deps
, UINT_TO_PTR(UNIT_REQUISITE
), "Unit" },
1203 { "RequisiteOverridable", config_parse_deps
, UINT_TO_PTR(UNIT_REQUISITE_OVERRIDABLE
), "Unit" },
1204 { "Wants", config_parse_deps
, UINT_TO_PTR(UNIT_WANTS
), "Unit" },
1205 { "Conflicts", config_parse_deps
, UINT_TO_PTR(UNIT_CONFLICTS
), "Unit" },
1206 { "Before", config_parse_deps
, UINT_TO_PTR(UNIT_BEFORE
), "Unit" },
1207 { "After", config_parse_deps
, UINT_TO_PTR(UNIT_AFTER
), "Unit" },
1208 { "RecursiveStop", config_parse_bool
, &u
->meta
.recursive_stop
, "Unit" },
1209 { "StopWhenUnneeded", config_parse_bool
, &u
->meta
.stop_when_unneeded
, "Unit" },
1211 { "PIDFile", config_parse_path
, &u
->service
.pid_file
, "Service" },
1212 { "ExecStartPre", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START_PRE
, "Service" },
1213 { "ExecStart", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START
, "Service" },
1214 { "ExecStartPost", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START_POST
, "Service" },
1215 { "ExecReload", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_RELOAD
, "Service" },
1216 { "ExecStop", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_STOP
, "Service" },
1217 { "ExecStopPost", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_STOP_POST
, "Service" },
1218 { "RestartSec", config_parse_usec
, &u
->service
.restart_usec
, "Service" },
1219 { "TimeoutSec", config_parse_usec
, &u
->service
.timeout_usec
, "Service" },
1220 { "Type", config_parse_service_type
, &u
->service
.type
, "Service" },
1221 { "Restart", config_parse_service_restart
, &u
->service
.restart
, "Service" },
1222 { "PermissionsStartOnly", config_parse_bool
, &u
->service
.permissions_start_only
, "Service" },
1223 { "RootDirectoryStartOnly", config_parse_bool
, &u
->service
.root_directory_start_only
, "Service" },
1224 { "ValidNoProcess", config_parse_bool
, &u
->service
.valid_no_process
, "Service" },
1225 { "SysVStartPriority", config_parse_sysv_priority
, &u
->service
.sysv_start_priority
, "Service" },
1226 { "KillMode", config_parse_kill_mode
, &u
->service
.kill_mode
, "Service" },
1227 { "NonBlocking", config_parse_bool
, &u
->service
.exec_context
.non_blocking
, "Service" },
1228 { "BusName", config_parse_string
, &u
->service
.bus_name
, "Service" },
1229 EXEC_CONTEXT_CONFIG_ITEMS(u
->service
.exec_context
, "Service"),
1231 { "ListenStream", config_parse_listen
, &u
->socket
, "Socket" },
1232 { "ListenDatagram", config_parse_listen
, &u
->socket
, "Socket" },
1233 { "ListenSequentialPacket", config_parse_listen
, &u
->socket
, "Socket" },
1234 { "ListenFIFO", config_parse_listen
, &u
->socket
, "Socket" },
1235 { "BindIPv6Only", config_parse_socket_bind
, &u
->socket
, "Socket" },
1236 { "Backlog", config_parse_unsigned
, &u
->socket
.backlog
, "Socket" },
1237 { "BindToDevice", config_parse_bindtodevice
, &u
->socket
, "Socket" },
1238 { "ExecStartPre", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_START_PRE
, "Socket" },
1239 { "ExecStartPost", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_START_POST
, "Socket" },
1240 { "ExecStopPre", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_STOP_PRE
, "Socket" },
1241 { "ExecStopPost", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_STOP_POST
, "Socket" },
1242 { "TimeoutSec", config_parse_usec
, &u
->socket
.timeout_usec
, "Socket" },
1243 { "DirectoryMode", config_parse_mode
, &u
->socket
.directory_mode
, "Socket" },
1244 { "SocketMode", config_parse_mode
, &u
->socket
.socket_mode
, "Socket" },
1245 { "KillMode", config_parse_kill_mode
, &u
->socket
.kill_mode
, "Socket" },
1246 { "Accept", config_parse_bool
, &u
->socket
.accept
, "Socket" },
1247 EXEC_CONTEXT_CONFIG_ITEMS(u
->socket
.exec_context
, "Socket"),
1249 { "What", config_parse_string
, &u
->mount
.parameters_fragment
.what
, "Mount" },
1250 { "Where", config_parse_path
, &u
->mount
.where
, "Mount" },
1251 { "Options", config_parse_string
, &u
->mount
.parameters_fragment
.options
, "Mount" },
1252 { "Type", config_parse_string
, &u
->mount
.parameters_fragment
.fstype
, "Mount" },
1253 { "TimeoutSec", config_parse_usec
, &u
->mount
.timeout_usec
, "Mount" },
1254 { "KillMode", config_parse_kill_mode
, &u
->mount
.kill_mode
, "Mount" },
1255 EXEC_CONTEXT_CONFIG_ITEMS(u
->mount
.exec_context
, "Mount"),
1257 { "Where", config_parse_path
, &u
->automount
.where
, "Automount" },
1259 { NULL
, NULL
, NULL
, NULL
}
1262 #undef EXEC_CONTEXT_CONFIG_ITEMS
1264 const char *sections
[3];
1269 char *filename
= NULL
, *id
= NULL
;
1273 /* Dirty dirty hack. */
1274 dump_items((FILE*) path
, items
);
1281 sections
[0] = "Unit";
1282 sections
[1] = section_table
[u
->meta
.type
];
1285 if (!(symlink_names
= set_new(string_hash_func
, string_compare_func
)))
1288 if (path_is_absolute(path
)) {
1290 if (!(filename
= strdup(path
))) {
1295 if ((r
= open_follow(&filename
, &f
, symlink_names
, &id
)) < 0) {
1306 STRV_FOREACH(p
, u
->meta
.manager
->unit_path
) {
1308 /* Instead of opening the path right away, we manually
1309 * follow all symlinks and add their name to our unit
1310 * name set while doing so */
1311 if (!(filename
= path_make_absolute(path
, *p
))) {
1316 if ((r
= open_follow(&filename
, &f
, symlink_names
, &id
)) < 0) {
1325 /* Empty the symlink names for the next run */
1326 while ((sn
= set_steal_first(symlink_names
)))
1342 if ((r
= merge_by_names(&merged
, symlink_names
, id
)) < 0)
1346 u
->meta
.load_state
= UNIT_MERGED
;
1351 /* Now, parse the file contents */
1352 if ((r
= config_parse(filename
, f
, sections
, items
, u
)) < 0)
1355 free(u
->meta
.fragment_path
);
1356 u
->meta
.fragment_path
= filename
;
1359 u
->meta
.load_state
= UNIT_LOADED
;
1363 while ((k
= set_steal_first(symlink_names
)))
1366 set_free(symlink_names
);
1375 int unit_load_fragment(Unit
*u
) {
1380 if (u
->meta
.fragment_path
) {
1382 if ((r
= load_from_path(u
, u
->meta
.fragment_path
)) < 0)
1389 /* Try to find the unit under its id */
1390 if ((r
= load_from_path(u
, u
->meta
.id
)) < 0)
1393 /* Try to find an alias we can load this with */
1394 if (u
->meta
.load_state
== UNIT_STUB
)
1395 SET_FOREACH(t
, u
->meta
.names
, i
) {
1397 if (t
== u
->meta
.id
)
1400 if ((r
= load_from_path(u
, t
)) < 0)
1403 if (u
->meta
.load_state
!= UNIT_STUB
)
1407 /* Now, follow the same logic, but look for a template */
1408 if (u
->meta
.load_state
== UNIT_STUB
&& u
->meta
.instance
) {
1411 if (!(k
= unit_name_template(u
->meta
.id
)))
1414 r
= load_from_path(u
, k
);
1420 if (u
->meta
.load_state
== UNIT_STUB
)
1421 SET_FOREACH(t
, u
->meta
.names
, i
) {
1423 if (t
== u
->meta
.id
)
1426 if (!(k
= unit_name_template(t
)))
1429 r
= load_from_path(u
, k
);
1435 if (u
->meta
.load_state
!= UNIT_STUB
)
1444 void unit_dump_config_items(FILE *f
) {
1445 /* OK, this wins a prize for extreme ugliness. */
1447 load_from_path(NULL
, (const void*) f
);