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_description(
154 const char *filename
,
170 if (!(k
= unit_full_printf(u
, rvalue
)))
173 free(u
->meta
.description
);
176 u
->meta
.description
= k
;
179 u
->meta
.description
= NULL
;
185 static int config_parse_listen(
186 const char *filename
,
205 if (!(p
= new0(SocketPort
, 1)))
208 if (streq(lvalue
, "ListenFIFO")) {
209 p
->type
= SOCKET_FIFO
;
211 if (!(p
->path
= strdup(rvalue
))) {
216 p
->type
= SOCKET_SOCKET
;
218 if ((r
= socket_address_parse(&p
->address
, rvalue
)) < 0) {
219 log_error("[%s:%u] Failed to parse address value: %s", filename
, line
, rvalue
);
224 if (streq(lvalue
, "ListenStream"))
225 p
->address
.type
= SOCK_STREAM
;
226 else if (streq(lvalue
, "ListenDatagram"))
227 p
->address
.type
= SOCK_DGRAM
;
229 assert(streq(lvalue
, "ListenSequentialPacket"));
230 p
->address
.type
= SOCK_SEQPACKET
;
233 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
235 return -EPROTONOSUPPORT
;
240 LIST_PREPEND(SocketPort
, port
, s
->ports
, p
);
245 static int config_parse_socket_bind(
246 const char *filename
,
264 if ((r
= parse_boolean(rvalue
)) < 0) {
265 log_error("[%s:%u] Failed to parse bind IPv6 only value: %s", filename
, line
, rvalue
);
269 s
->bind_ipv6_only
= r
? SOCKET_ADDRESS_IPV6_ONLY
: SOCKET_ADDRESS_BOTH
;
274 static int config_parse_nice(
275 const char *filename
,
283 ExecContext
*c
= data
;
291 if ((r
= safe_atoi(rvalue
, &priority
)) < 0) {
292 log_error("[%s:%u] Failed to parse nice priority: %s", filename
, line
, rvalue
);
296 if (priority
< PRIO_MIN
|| priority
>= PRIO_MAX
) {
297 log_error("[%s:%u] Nice priority out of range: %s", filename
, line
, rvalue
);
307 static int config_parse_oom_adjust(
308 const char *filename
,
316 ExecContext
*c
= data
;
324 if ((r
= safe_atoi(rvalue
, &oa
)) < 0) {
325 log_error("[%s:%u] Failed to parse OOM adjust value: %s", filename
, line
, rvalue
);
329 if (oa
< OOM_DISABLE
|| oa
> OOM_ADJUST_MAX
) {
330 log_error("[%s:%u] OOM adjust value out of range: %s", filename
, line
, rvalue
);
335 c
->oom_adjust_set
= true;
340 static int config_parse_mode(
341 const char *filename
,
359 l
= strtol(rvalue
, &x
, 8);
360 if (!x
|| *x
|| errno
) {
361 log_error("[%s:%u] Failed to parse mode value: %s", filename
, line
, rvalue
);
362 return errno
? -errno
: -EINVAL
;
365 if (l
< 0000 || l
> 07777) {
366 log_error("[%s:%u] mode value out of range: %s", filename
, line
, rvalue
);
374 static int config_parse_exec(
375 const char *filename
,
383 ExecCommand
**e
= data
, *nce
= NULL
;
396 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
)
399 if (!(n
= new(char*, k
+1)))
403 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
)
404 if (!(n
[k
++] = strndup(w
, l
)))
409 if (!n
[0] || !path_is_absolute(n
[0])) {
410 log_error("[%s:%u] Invalid executable path in command line: %s", filename
, line
, rvalue
);
415 if (!(nce
= new0(ExecCommand
, 1)))
419 if (!(nce
->path
= strdup(n
[0])))
422 exec_command_append_list(e
, nce
);
436 static int config_parse_usec(
437 const char *filename
,
453 if ((r
= parse_usec(rvalue
, usec
)) < 0) {
454 log_error("[%s:%u] Failed to parse time value: %s", filename
, line
, rvalue
);
461 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
462 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
464 static int config_parse_bindtodevice(
465 const char *filename
,
481 if (rvalue
[0] && !streq(rvalue
, "*")) {
482 if (!(n
= strdup(rvalue
)))
487 free(s
->bind_to_device
);
488 s
->bind_to_device
= n
;
493 DEFINE_CONFIG_PARSE_ENUM(config_parse_output
, exec_output
, ExecOutput
, "Failed to parse output specifier");
494 DEFINE_CONFIG_PARSE_ENUM(config_parse_input
, exec_input
, ExecInput
, "Failed to parse input specifier");
496 static int config_parse_facility(
497 const char *filename
,
513 if ((x
= log_facility_from_string(rvalue
)) < 0) {
514 log_error("[%s:%u] Failed to parse log facility: %s", filename
, line
, rvalue
);
518 *o
= LOG_MAKEPRI(x
, LOG_PRI(*o
));
523 static int config_parse_level(
524 const char *filename
,
540 if ((x
= log_level_from_string(rvalue
)) < 0) {
541 log_error("[%s:%u] Failed to parse log level: %s", filename
, line
, rvalue
);
545 *o
= LOG_MAKEPRI(LOG_FAC(*o
), x
);
549 static int config_parse_io_class(
550 const char *filename
,
558 ExecContext
*c
= data
;
566 if ((x
= ioprio_class_from_string(rvalue
)) < 0) {
567 log_error("[%s:%u] Failed to parse IO scheduling class: %s", filename
, line
, rvalue
);
571 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
572 c
->ioprio_set
= true;
577 static int config_parse_io_priority(
578 const char *filename
,
586 ExecContext
*c
= data
;
594 if (safe_atoi(rvalue
, &i
) < 0 || i
< 0 || i
>= IOPRIO_BE_NR
) {
595 log_error("[%s:%u] Failed to parse io priority: %s", filename
, line
, rvalue
);
599 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
600 c
->ioprio_set
= true;
605 static int config_parse_cpu_sched_policy(
606 const char *filename
,
615 ExecContext
*c
= data
;
623 if ((x
= sched_policy_from_string(rvalue
)) < 0) {
624 log_error("[%s:%u] Failed to parse CPU scheduling policy: %s", filename
, line
, rvalue
);
628 c
->cpu_sched_policy
= x
;
629 c
->cpu_sched_set
= true;
634 static int config_parse_cpu_sched_prio(
635 const char *filename
,
643 ExecContext
*c
= data
;
651 /* On Linux RR/FIFO have the same range */
652 if (safe_atoi(rvalue
, &i
) < 0 || i
< sched_get_priority_min(SCHED_RR
) || i
> sched_get_priority_max(SCHED_RR
)) {
653 log_error("[%s:%u] Failed to parse CPU scheduling priority: %s", filename
, line
, rvalue
);
657 c
->cpu_sched_priority
= i
;
658 c
->cpu_sched_set
= true;
663 static int config_parse_cpu_affinity(
664 const char *filename
,
672 ExecContext
*c
= data
;
682 FOREACH_WORD(w
, l
, rvalue
, state
) {
687 if (!(t
= strndup(w
, l
)))
690 r
= safe_atou(t
, &cpu
);
693 if (r
< 0 || cpu
>= CPU_SETSIZE
) {
694 log_error("[%s:%u] Failed to parse CPU affinity: %s", filename
, line
, rvalue
);
698 CPU_SET(cpu
, &c
->cpu_affinity
);
701 c
->cpu_affinity_set
= true;
706 static int config_parse_capabilities(
707 const char *filename
,
715 ExecContext
*c
= data
;
723 if (!(cap
= cap_from_text(rvalue
))) {
727 log_error("[%s:%u] Failed to parse capabilities: %s", filename
, line
, rvalue
);
732 cap_free(c
->capabilities
);
733 c
->capabilities
= cap
;
738 static int config_parse_secure_bits(
739 const char *filename
,
747 ExecContext
*c
= data
;
757 FOREACH_WORD(w
, l
, rvalue
, state
) {
758 if (first_word(w
, "keep-caps"))
759 c
->secure_bits
|= SECURE_KEEP_CAPS
;
760 else if (first_word(w
, "keep-caps-locked"))
761 c
->secure_bits
|= SECURE_KEEP_CAPS_LOCKED
;
762 else if (first_word(w
, "no-setuid-fixup"))
763 c
->secure_bits
|= SECURE_NO_SETUID_FIXUP
;
764 else if (first_word(w
, "no-setuid-fixup-locked"))
765 c
->secure_bits
|= SECURE_NO_SETUID_FIXUP_LOCKED
;
766 else if (first_word(w
, "noroot"))
767 c
->secure_bits
|= SECURE_NOROOT
;
768 else if (first_word(w
, "noroot-locked"))
769 c
->secure_bits
|= SECURE_NOROOT_LOCKED
;
771 log_error("[%s:%u] Failed to parse secure bits: %s", filename
, line
, rvalue
);
779 static int config_parse_bounding_set(
780 const char *filename
,
788 ExecContext
*c
= data
;
798 FOREACH_WORD(w
, l
, rvalue
, state
) {
803 if (!(t
= strndup(w
, l
)))
806 r
= cap_from_name(t
, &cap
);
810 log_error("[%s:%u] Failed to parse capability bounding set: %s", filename
, line
, rvalue
);
814 c
->capability_bounding_set_drop
|= 1 << cap
;
820 static int config_parse_timer_slack_ns(
821 const char *filename
,
829 ExecContext
*c
= data
;
838 if ((r
= safe_atolu(rvalue
, &u
)) < 0) {
839 log_error("[%s:%u] Failed to parse time slack value: %s", filename
, line
, rvalue
);
843 c
->timer_slack_ns
= u
;
848 static int config_parse_limit(
849 const char *filename
,
857 struct rlimit
**rl
= data
;
858 unsigned long long u
;
866 if ((r
= safe_atollu(rvalue
, &u
)) < 0) {
867 log_error("[%s:%u] Failed to parse resource value: %s", filename
, line
, rvalue
);
872 if (!(*rl
= new(struct rlimit
, 1)))
875 (*rl
)->rlim_cur
= (*rl
)->rlim_max
= (rlim_t
) u
;
879 static int config_parse_cgroup(
880 const char *filename
,
893 FOREACH_WORD(w
, l
, rvalue
, state
) {
897 if (!(t
= strndup(w
, l
)))
900 r
= unit_add_cgroup_from_text(u
, t
);
910 static int config_parse_sysv_priority(
911 const char *filename
,
919 int *priority
= data
;
927 if ((r
= safe_atoi(rvalue
, &i
)) < 0 || i
< 0) {
928 log_error("[%s:%u] Failed to parse SysV start priority: %s", filename
, line
, rvalue
);
936 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
938 static int config_parse_mount_flags(
939 const char *filename
,
947 ExecContext
*c
= data
;
951 unsigned long flags
= 0;
958 FOREACH_WORD(w
, l
, rvalue
, state
) {
959 if (strncmp(w
, "shared", l
) == 0)
961 else if (strncmp(w
, "slave", l
) == 0)
963 else if (strncmp(w
, "private", l
) == 0)
966 log_error("[%s:%u] Failed to parse mount flags: %s", filename
, line
, rvalue
);
971 c
->mount_flags
= flags
;
977 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
988 /* This will update the filename pointer if the loaded file is
989 * reached by a symlink. The old string will be freed. */
992 char *target
, *k
, *name
;
994 if (c
++ >= FOLLOW_MAX
)
997 path_kill_slashes(*filename
);
999 /* Add the file name we are currently looking at to
1000 * the names of this unit */
1001 name
= file_name_from_path(*filename
);
1002 if (!(id
= set_get(names
, name
))) {
1004 if (!(id
= strdup(name
)))
1007 if ((r
= set_put(names
, id
)) < 0) {
1013 /* Try to open the file name, but don't if its a symlink */
1014 if ((fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
)) >= 0)
1020 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
1021 if ((r
= readlink_malloc(*filename
, &target
)) < 0)
1024 k
= file_in_same_dir(*filename
, target
);
1034 if (!(f
= fdopen(fd
, "r"))) {
1036 close_nointr_nofail(fd
);
1045 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
1053 /* Let's try to add in all symlink names we found */
1054 while ((k
= set_steal_first(names
))) {
1056 /* First try to merge in the other name into our
1058 if ((r
= unit_merge_by_name(*u
, k
)) < 0) {
1061 /* Hmm, we couldn't merge the other unit into
1062 * ours? Then let's try it the other way
1065 other
= manager_get_unit((*u
)->meta
.manager
, k
);
1069 if ((r
= unit_merge(other
, *u
)) >= 0) {
1071 return merge_by_names(u
, names
, NULL
);
1078 unit_choose_id(*u
, id
);
1086 static void dump_items(FILE *f
, const ConfigItem
*items
) {
1087 const ConfigItem
*i
;
1088 const char *prev_section
= NULL
;
1089 bool not_first
= false;
1092 ConfigParserCallback callback
;
1095 { config_parse_int
, "INTEGER" },
1096 { config_parse_unsigned
, "UNSIGNED" },
1097 { config_parse_size
, "SIZE" },
1098 { config_parse_bool
, "BOOLEAN" },
1099 { config_parse_string
, "STRING" },
1100 { config_parse_path
, "PATH" },
1101 { config_parse_strv
, "STRING [...]" },
1102 { config_parse_nice
, "NICE" },
1103 { config_parse_oom_adjust
, "OOMADJUST" },
1104 { config_parse_io_class
, "IOCLASS" },
1105 { config_parse_io_priority
, "IOPRIORITY" },
1106 { config_parse_cpu_sched_policy
, "CPUSCHEDPOLICY" },
1107 { config_parse_cpu_sched_prio
, "CPUSCHEDPRIO" },
1108 { config_parse_cpu_affinity
, "CPUAFFINITY" },
1109 { config_parse_mode
, "MODE" },
1110 { config_parse_output
, "OUTPUT" },
1111 { config_parse_input
, "INPUT" },
1112 { config_parse_facility
, "FACILITY" },
1113 { config_parse_level
, "LEVEL" },
1114 { config_parse_capabilities
, "CAPABILITIES" },
1115 { config_parse_secure_bits
, "SECUREBITS" },
1116 { config_parse_bounding_set
, "BOUNDINGSET" },
1117 { config_parse_timer_slack_ns
, "TIMERSLACK" },
1118 { config_parse_limit
, "LIMIT" },
1119 { config_parse_cgroup
, "CGROUP [...]" },
1120 { config_parse_deps
, "UNIT [...]" },
1121 { config_parse_names
, "UNIT [...]" },
1122 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
1123 { config_parse_service_type
, "SERVICETYPE" },
1124 { config_parse_service_restart
, "SERVICERESTART" },
1125 { config_parse_sysv_priority
, "SYSVPRIORITY" },
1126 { config_parse_kill_mode
, "KILLMODE" },
1127 { config_parse_listen
, "SOCKET [...]" },
1128 { config_parse_socket_bind
, "SOCKETBIND" },
1129 { config_parse_bindtodevice
, "NETWORKINTERFACE" },
1130 { config_parse_usec
, "SECONDS" },
1131 { config_parse_path_strv
, "PATH [...]" },
1132 { config_parse_mount_flags
, "MOUNTFLAG [...]" },
1133 { config_parse_description
, "DESCRIPTION" },
1139 for (i
= items
; i
->lvalue
; i
++) {
1141 const char *rvalue
= "OTHER";
1143 if (!streq_ptr(i
->section
, prev_section
)) {
1149 fprintf(f
, "[%s]\n", i
->section
);
1150 prev_section
= i
->section
;
1153 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
1154 if (i
->parse
== table
[j
].callback
) {
1155 rvalue
= table
[j
].rvalue
;
1159 fprintf(f
, "%s=%s\n", i
->lvalue
, rvalue
);
1163 static int load_from_path(Unit
*u
, const char *path
) {
1165 static const char* const section_table
[_UNIT_TYPE_MAX
] = {
1166 [UNIT_SERVICE
] = "Service",
1167 [UNIT_TIMER
] = "Timer",
1168 [UNIT_SOCKET
] = "Socket",
1169 [UNIT_TARGET
] = "Target",
1170 [UNIT_DEVICE
] = "Device",
1171 [UNIT_MOUNT
] = "Mount",
1172 [UNIT_AUTOMOUNT
] = "Automount",
1173 [UNIT_SNAPSHOT
] = "Snapshot"
1176 #define EXEC_CONTEXT_CONFIG_ITEMS(context, section) \
1177 { "WorkingDirectory", config_parse_path, &(context).working_directory, section }, \
1178 { "RootDirectory", config_parse_path, &(context).root_directory, section }, \
1179 { "User", config_parse_string, &(context).user, section }, \
1180 { "Group", config_parse_string, &(context).group, section }, \
1181 { "SupplementaryGroups", config_parse_strv, &(context).supplementary_groups, section }, \
1182 { "Nice", config_parse_nice, &(context), section }, \
1183 { "OOMAdjust", config_parse_oom_adjust, &(context), section }, \
1184 { "IOSchedulingClass", config_parse_io_class, &(context), section }, \
1185 { "IOSchedulingPriority", config_parse_io_priority, &(context), section }, \
1186 { "CPUSchedulingPolicy", config_parse_cpu_sched_policy,&(context), section }, \
1187 { "CPUSchedulingPriority", config_parse_cpu_sched_prio, &(context), section }, \
1188 { "CPUSchedulingResetOnFork", config_parse_bool, &(context).cpu_sched_reset_on_fork, section }, \
1189 { "CPUAffinity", config_parse_cpu_affinity, &(context), section }, \
1190 { "UMask", config_parse_mode, &(context).umask, section }, \
1191 { "Environment", config_parse_strv, &(context).environment, section }, \
1192 { "StandardInput", config_parse_input, &(context).std_input, section }, \
1193 { "StandardOutput", config_parse_output, &(context).std_output, section }, \
1194 { "StandardError", config_parse_output, &(context).std_output, section }, \
1195 { "TTYPath", config_parse_path, &(context).tty_path, section }, \
1196 { "SyslogIdentifier", config_parse_string, &(context).syslog_identifier, section }, \
1197 { "SyslogFacility", config_parse_facility, &(context).syslog_priority, section }, \
1198 { "SyslogLevel", config_parse_level, &(context).syslog_priority, section }, \
1199 { "Capabilities", config_parse_capabilities, &(context), section }, \
1200 { "SecureBits", config_parse_secure_bits, &(context), section }, \
1201 { "CapabilityBoundingSetDrop", config_parse_bounding_set, &(context), section }, \
1202 { "TimerSlackNS", config_parse_timer_slack_ns, &(context), section }, \
1203 { "LimitCPU", config_parse_limit, &(context).rlimit[RLIMIT_CPU], section }, \
1204 { "LimitFSIZE", config_parse_limit, &(context).rlimit[RLIMIT_FSIZE], section }, \
1205 { "LimitDATA", config_parse_limit, &(context).rlimit[RLIMIT_DATA], section }, \
1206 { "LimitSTACK", config_parse_limit, &(context).rlimit[RLIMIT_STACK], section }, \
1207 { "LimitCORE", config_parse_limit, &(context).rlimit[RLIMIT_CORE], section }, \
1208 { "LimitRSS", config_parse_limit, &(context).rlimit[RLIMIT_RSS], section }, \
1209 { "LimitNOFILE", config_parse_limit, &(context).rlimit[RLIMIT_NOFILE], section }, \
1210 { "LimitAS", config_parse_limit, &(context).rlimit[RLIMIT_AS], section }, \
1211 { "LimitNPROC", config_parse_limit, &(context).rlimit[RLIMIT_NPROC], section }, \
1212 { "LimitMEMLOCK", config_parse_limit, &(context).rlimit[RLIMIT_MEMLOCK], section }, \
1213 { "LimitLOCKS", config_parse_limit, &(context).rlimit[RLIMIT_LOCKS], section }, \
1214 { "LimitSIGPENDING", config_parse_limit, &(context).rlimit[RLIMIT_SIGPENDING], section }, \
1215 { "LimitMSGQUEUE", config_parse_limit, &(context).rlimit[RLIMIT_MSGQUEUE], section }, \
1216 { "LimitNICE", config_parse_limit, &(context).rlimit[RLIMIT_NICE], section }, \
1217 { "LimitRTPRIO", config_parse_limit, &(context).rlimit[RLIMIT_RTPRIO], section }, \
1218 { "LimitRTTIME", config_parse_limit, &(context).rlimit[RLIMIT_RTTIME], section }, \
1219 { "ControlGroup", config_parse_cgroup, u, section }, \
1220 { "ReadWriteDirectories", config_parse_path_strv, &(context).read_write_dirs, section }, \
1221 { "ReadOnlyDirectories", config_parse_path_strv, &(context).read_only_dirs, section }, \
1222 { "InaccessibleDirectories",config_parse_path_strv, &(context).inaccessible_dirs, section }, \
1223 { "PrivateTmp", config_parse_bool, &(context).private_tmp, section }, \
1224 { "MountFlags", config_parse_mount_flags, &(context), section }
1226 const ConfigItem items
[] = {
1227 { "Names", config_parse_names
, u
, "Unit" },
1228 { "Description", config_parse_description
, u
, "Unit" },
1229 { "Requires", config_parse_deps
, UINT_TO_PTR(UNIT_REQUIRES
), "Unit" },
1230 { "RequiresOverridable", config_parse_deps
, UINT_TO_PTR(UNIT_REQUIRES_OVERRIDABLE
), "Unit" },
1231 { "Requisite", config_parse_deps
, UINT_TO_PTR(UNIT_REQUISITE
), "Unit" },
1232 { "RequisiteOverridable", config_parse_deps
, UINT_TO_PTR(UNIT_REQUISITE_OVERRIDABLE
), "Unit" },
1233 { "Wants", config_parse_deps
, UINT_TO_PTR(UNIT_WANTS
), "Unit" },
1234 { "Conflicts", config_parse_deps
, UINT_TO_PTR(UNIT_CONFLICTS
), "Unit" },
1235 { "Before", config_parse_deps
, UINT_TO_PTR(UNIT_BEFORE
), "Unit" },
1236 { "After", config_parse_deps
, UINT_TO_PTR(UNIT_AFTER
), "Unit" },
1237 { "RecursiveStop", config_parse_bool
, &u
->meta
.recursive_stop
, "Unit" },
1238 { "StopWhenUnneeded", config_parse_bool
, &u
->meta
.stop_when_unneeded
, "Unit" },
1240 { "PIDFile", config_parse_path
, &u
->service
.pid_file
, "Service" },
1241 { "ExecStartPre", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START_PRE
, "Service" },
1242 { "ExecStart", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START
, "Service" },
1243 { "ExecStartPost", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START_POST
, "Service" },
1244 { "ExecReload", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_RELOAD
, "Service" },
1245 { "ExecStop", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_STOP
, "Service" },
1246 { "ExecStopPost", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_STOP_POST
, "Service" },
1247 { "RestartSec", config_parse_usec
, &u
->service
.restart_usec
, "Service" },
1248 { "TimeoutSec", config_parse_usec
, &u
->service
.timeout_usec
, "Service" },
1249 { "Type", config_parse_service_type
, &u
->service
.type
, "Service" },
1250 { "Restart", config_parse_service_restart
, &u
->service
.restart
, "Service" },
1251 { "PermissionsStartOnly", config_parse_bool
, &u
->service
.permissions_start_only
, "Service" },
1252 { "RootDirectoryStartOnly", config_parse_bool
, &u
->service
.root_directory_start_only
, "Service" },
1253 { "ValidNoProcess", config_parse_bool
, &u
->service
.valid_no_process
, "Service" },
1254 { "SysVStartPriority", config_parse_sysv_priority
, &u
->service
.sysv_start_priority
, "Service" },
1255 { "KillMode", config_parse_kill_mode
, &u
->service
.kill_mode
, "Service" },
1256 { "NonBlocking", config_parse_bool
, &u
->service
.exec_context
.non_blocking
, "Service" },
1257 { "BusName", config_parse_string
, &u
->service
.bus_name
, "Service" },
1258 EXEC_CONTEXT_CONFIG_ITEMS(u
->service
.exec_context
, "Service"),
1260 { "ListenStream", config_parse_listen
, &u
->socket
, "Socket" },
1261 { "ListenDatagram", config_parse_listen
, &u
->socket
, "Socket" },
1262 { "ListenSequentialPacket", config_parse_listen
, &u
->socket
, "Socket" },
1263 { "ListenFIFO", config_parse_listen
, &u
->socket
, "Socket" },
1264 { "BindIPv6Only", config_parse_socket_bind
, &u
->socket
, "Socket" },
1265 { "Backlog", config_parse_unsigned
, &u
->socket
.backlog
, "Socket" },
1266 { "BindToDevice", config_parse_bindtodevice
, &u
->socket
, "Socket" },
1267 { "ExecStartPre", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_START_PRE
, "Socket" },
1268 { "ExecStartPost", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_START_POST
, "Socket" },
1269 { "ExecStopPre", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_STOP_PRE
, "Socket" },
1270 { "ExecStopPost", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_STOP_POST
, "Socket" },
1271 { "TimeoutSec", config_parse_usec
, &u
->socket
.timeout_usec
, "Socket" },
1272 { "DirectoryMode", config_parse_mode
, &u
->socket
.directory_mode
, "Socket" },
1273 { "SocketMode", config_parse_mode
, &u
->socket
.socket_mode
, "Socket" },
1274 { "KillMode", config_parse_kill_mode
, &u
->socket
.kill_mode
, "Socket" },
1275 { "Accept", config_parse_bool
, &u
->socket
.accept
, "Socket" },
1276 EXEC_CONTEXT_CONFIG_ITEMS(u
->socket
.exec_context
, "Socket"),
1278 { "What", config_parse_string
, &u
->mount
.parameters_fragment
.what
, "Mount" },
1279 { "Where", config_parse_path
, &u
->mount
.where
, "Mount" },
1280 { "Options", config_parse_string
, &u
->mount
.parameters_fragment
.options
, "Mount" },
1281 { "Type", config_parse_string
, &u
->mount
.parameters_fragment
.fstype
, "Mount" },
1282 { "TimeoutSec", config_parse_usec
, &u
->mount
.timeout_usec
, "Mount" },
1283 { "KillMode", config_parse_kill_mode
, &u
->mount
.kill_mode
, "Mount" },
1284 EXEC_CONTEXT_CONFIG_ITEMS(u
->mount
.exec_context
, "Mount"),
1286 { "Where", config_parse_path
, &u
->automount
.where
, "Automount" },
1288 { NULL
, NULL
, NULL
, NULL
}
1291 #undef EXEC_CONTEXT_CONFIG_ITEMS
1293 const char *sections
[3];
1298 char *filename
= NULL
, *id
= NULL
;
1302 /* Dirty dirty hack. */
1303 dump_items((FILE*) path
, items
);
1310 sections
[0] = "Unit";
1311 sections
[1] = section_table
[u
->meta
.type
];
1314 if (!(symlink_names
= set_new(string_hash_func
, string_compare_func
)))
1317 if (path_is_absolute(path
)) {
1319 if (!(filename
= strdup(path
))) {
1324 if ((r
= open_follow(&filename
, &f
, symlink_names
, &id
)) < 0) {
1335 STRV_FOREACH(p
, u
->meta
.manager
->unit_path
) {
1337 /* Instead of opening the path right away, we manually
1338 * follow all symlinks and add their name to our unit
1339 * name set while doing so */
1340 if (!(filename
= path_make_absolute(path
, *p
))) {
1345 if ((r
= open_follow(&filename
, &f
, symlink_names
, &id
)) < 0) {
1354 /* Empty the symlink names for the next run */
1355 while ((sn
= set_steal_first(symlink_names
)))
1371 if ((r
= merge_by_names(&merged
, symlink_names
, id
)) < 0)
1375 u
->meta
.load_state
= UNIT_MERGED
;
1380 /* Now, parse the file contents */
1381 if ((r
= config_parse(filename
, f
, sections
, items
, u
)) < 0)
1384 free(u
->meta
.fragment_path
);
1385 u
->meta
.fragment_path
= filename
;
1388 u
->meta
.load_state
= UNIT_LOADED
;
1392 while ((k
= set_steal_first(symlink_names
)))
1395 set_free(symlink_names
);
1404 int unit_load_fragment(Unit
*u
) {
1409 if (u
->meta
.fragment_path
) {
1411 if ((r
= load_from_path(u
, u
->meta
.fragment_path
)) < 0)
1418 /* Try to find the unit under its id */
1419 if ((r
= load_from_path(u
, u
->meta
.id
)) < 0)
1422 /* Try to find an alias we can load this with */
1423 if (u
->meta
.load_state
== UNIT_STUB
)
1424 SET_FOREACH(t
, u
->meta
.names
, i
) {
1426 if (t
== u
->meta
.id
)
1429 if ((r
= load_from_path(u
, t
)) < 0)
1432 if (u
->meta
.load_state
!= UNIT_STUB
)
1436 /* Now, follow the same logic, but look for a template */
1437 if (u
->meta
.load_state
== UNIT_STUB
&& u
->meta
.instance
) {
1440 if (!(k
= unit_name_template(u
->meta
.id
)))
1443 r
= load_from_path(u
, k
);
1449 if (u
->meta
.load_state
== UNIT_STUB
)
1450 SET_FOREACH(t
, u
->meta
.names
, i
) {
1452 if (t
== u
->meta
.id
)
1455 if (!(k
= unit_name_template(t
)))
1458 r
= load_from_path(u
, k
);
1464 if (u
->meta
.load_state
!= UNIT_STUB
)
1473 void unit_dump_config_items(FILE *f
) {
1474 /* OK, this wins a prize for extreme ugliness. */
1476 load_from_path(NULL
, (const void*) f
);