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>
33 #include "conf-parser.h"
34 #include "load-fragment.h"
37 #include "securebits.h"
39 #include "unit-name.h"
41 #define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \
42 static int function( \
43 const char *filename, \
45 const char *section, \
58 if ((x = name##_from_string(rvalue)) < 0) { \
59 log_error("[%s:%u] " msg ": %s", filename, line, rvalue); \
68 static int config_parse_deps(
77 UnitDependency d
= PTR_TO_UINT(data
);
87 FOREACH_WORD(w
, l
, rvalue
, state
) {
91 if (!(t
= strndup(w
, l
)))
94 k
= unit_name_printf(u
, t
);
100 r
= unit_add_dependency_by_name(u
, d
, k
, NULL
);
110 static int config_parse_names(
111 const char *filename
,
129 FOREACH_WORD(w
, l
, rvalue
, state
) {
133 if (!(t
= strndup(w
, l
)))
136 k
= unit_name_printf(u
, t
);
142 r
= unit_merge_by_name(u
, k
);
152 static int config_parse_listen(
153 const char *filename
,
172 if (!(p
= new0(SocketPort
, 1)))
175 if (streq(lvalue
, "ListenFIFO")) {
176 p
->type
= SOCKET_FIFO
;
178 if (!(p
->path
= strdup(rvalue
))) {
183 p
->type
= SOCKET_SOCKET
;
185 if ((r
= socket_address_parse(&p
->address
, rvalue
)) < 0) {
186 log_error("[%s:%u] Failed to parse address value: %s", filename
, line
, rvalue
);
191 if (streq(lvalue
, "ListenStream"))
192 p
->address
.type
= SOCK_STREAM
;
193 else if (streq(lvalue
, "ListenDatagram"))
194 p
->address
.type
= SOCK_DGRAM
;
196 assert(streq(lvalue
, "ListenSequentialPacket"));
197 p
->address
.type
= SOCK_SEQPACKET
;
200 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
202 return -EPROTONOSUPPORT
;
207 LIST_PREPEND(SocketPort
, port
, s
->ports
, p
);
212 static int config_parse_socket_bind(
213 const char *filename
,
231 if ((r
= parse_boolean(rvalue
)) < 0) {
232 log_error("[%s:%u] Failed to parse bind IPv6 only value: %s", filename
, line
, rvalue
);
236 s
->bind_ipv6_only
= r
? SOCKET_ADDRESS_IPV6_ONLY
: SOCKET_ADDRESS_BOTH
;
241 static int config_parse_nice(
242 const char *filename
,
250 ExecContext
*c
= data
;
258 if ((r
= safe_atoi(rvalue
, &priority
)) < 0) {
259 log_error("[%s:%u] Failed to parse nice priority: %s", filename
, line
, rvalue
);
263 if (priority
< PRIO_MIN
|| priority
>= PRIO_MAX
) {
264 log_error("[%s:%u] Nice priority out of range: %s", filename
, line
, rvalue
);
274 static int config_parse_oom_adjust(
275 const char *filename
,
283 ExecContext
*c
= data
;
291 if ((r
= safe_atoi(rvalue
, &oa
)) < 0) {
292 log_error("[%s:%u] Failed to parse OOM adjust value: %s", filename
, line
, rvalue
);
296 if (oa
< OOM_DISABLE
|| oa
> OOM_ADJUST_MAX
) {
297 log_error("[%s:%u] OOM adjust value out of range: %s", filename
, line
, rvalue
);
302 c
->oom_adjust_set
= true;
307 static int config_parse_mode(
308 const char *filename
,
326 l
= strtol(rvalue
, &x
, 8);
327 if (!x
|| *x
|| errno
) {
328 log_error("[%s:%u] Failed to parse mode value: %s", filename
, line
, rvalue
);
329 return errno
? -errno
: -EINVAL
;
332 if (l
< 0000 || l
> 07777) {
333 log_error("[%s:%u] mode value out of range: %s", filename
, line
, rvalue
);
341 static int config_parse_exec(
342 const char *filename
,
350 ExecCommand
**e
= data
, *nce
= NULL
;
363 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
)
366 if (!(n
= new(char*, k
+1)))
370 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
)
371 if (!(n
[k
++] = strndup(w
, l
)))
376 if (!n
[0] || !path_is_absolute(n
[0])) {
377 log_error("[%s:%u] Invalid executable path in command line: %s", filename
, line
, rvalue
);
382 if (!(nce
= new0(ExecCommand
, 1)))
386 if (!(nce
->path
= strdup(n
[0])))
389 exec_command_append_list(e
, nce
);
403 static int config_parse_usec(
404 const char *filename
,
413 unsigned long long u
;
421 if ((r
= safe_atollu(rvalue
, &u
)) < 0) {
422 log_error("[%s:%u] Failed to parse time value: %s", filename
, line
, rvalue
);
426 /* We actually assume the user configures seconds. Later on we
427 * might choose to support suffixes for time values, to
428 * configure bigger or smaller units */
430 *usec
= u
* USEC_PER_SEC
;
435 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
436 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
438 static int config_parse_bindtodevice(
439 const char *filename
,
455 if (rvalue
[0] && !streq(rvalue
, "*")) {
456 if (!(n
= strdup(rvalue
)))
461 free(s
->bind_to_device
);
462 s
->bind_to_device
= n
;
467 DEFINE_CONFIG_PARSE_ENUM(config_parse_output
, exec_output
, ExecOutput
, "Failed to parse output specifier");
468 DEFINE_CONFIG_PARSE_ENUM(config_parse_input
, exec_input
, ExecInput
, "Failed to parse input specifier");
470 static int config_parse_facility(
471 const char *filename
,
487 if ((x
= log_facility_from_string(rvalue
)) < 0) {
488 log_error("[%s:%u] Failed to parse log facility: %s", filename
, line
, rvalue
);
492 *o
= LOG_MAKEPRI(x
, LOG_PRI(*o
));
497 static int config_parse_level(
498 const char *filename
,
514 if ((x
= log_level_from_string(rvalue
)) < 0) {
515 log_error("[%s:%u] Failed to parse log level: %s", filename
, line
, rvalue
);
519 *o
= LOG_MAKEPRI(LOG_FAC(*o
), x
);
523 static int config_parse_io_class(
524 const char *filename
,
532 ExecContext
*c
= data
;
540 if ((x
= ioprio_class_from_string(rvalue
)) < 0) {
541 log_error("[%s:%u] Failed to parse IO scheduling class: %s", filename
, line
, rvalue
);
545 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
546 c
->ioprio_set
= true;
551 static int config_parse_io_priority(
552 const char *filename
,
560 ExecContext
*c
= data
;
568 if (safe_atoi(rvalue
, &i
) < 0 || i
< 0 || i
>= IOPRIO_BE_NR
) {
569 log_error("[%s:%u] Failed to parse io priority: %s", filename
, line
, rvalue
);
573 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
574 c
->ioprio_set
= true;
579 static int config_parse_cpu_sched_policy(
580 const char *filename
,
589 ExecContext
*c
= data
;
597 if ((x
= sched_policy_from_string(rvalue
)) < 0) {
598 log_error("[%s:%u] Failed to parse CPU scheduling policy: %s", filename
, line
, rvalue
);
602 c
->cpu_sched_policy
= x
;
603 c
->cpu_sched_set
= true;
608 static int config_parse_cpu_sched_prio(
609 const char *filename
,
617 ExecContext
*c
= data
;
625 /* On Linux RR/FIFO have the same range */
626 if (safe_atoi(rvalue
, &i
) < 0 || i
< sched_get_priority_min(SCHED_RR
) || i
> sched_get_priority_max(SCHED_RR
)) {
627 log_error("[%s:%u] Failed to parse CPU scheduling priority: %s", filename
, line
, rvalue
);
631 c
->cpu_sched_priority
= i
;
632 c
->cpu_sched_set
= true;
637 static int config_parse_cpu_affinity(
638 const char *filename
,
646 ExecContext
*c
= data
;
656 FOREACH_WORD(w
, l
, rvalue
, state
) {
661 if (!(t
= strndup(w
, l
)))
664 r
= safe_atou(t
, &cpu
);
667 if (r
< 0 || cpu
>= CPU_SETSIZE
) {
668 log_error("[%s:%u] Failed to parse CPU affinity: %s", filename
, line
, rvalue
);
672 CPU_SET(cpu
, &c
->cpu_affinity
);
675 c
->cpu_affinity_set
= true;
680 static int config_parse_capabilities(
681 const char *filename
,
689 ExecContext
*c
= data
;
697 if (!(cap
= cap_from_text(rvalue
))) {
701 log_error("[%s:%u] Failed to parse capabilities: %s", filename
, line
, rvalue
);
706 cap_free(c
->capabilities
);
707 c
->capabilities
= cap
;
712 static int config_parse_secure_bits(
713 const char *filename
,
721 ExecContext
*c
= data
;
731 FOREACH_WORD(w
, l
, rvalue
, state
) {
732 if (first_word(w
, "keep-caps"))
733 c
->secure_bits
|= SECURE_KEEP_CAPS
;
734 else if (first_word(w
, "keep-caps-locked"))
735 c
->secure_bits
|= SECURE_KEEP_CAPS_LOCKED
;
736 else if (first_word(w
, "no-setuid-fixup"))
737 c
->secure_bits
|= SECURE_NO_SETUID_FIXUP
;
738 else if (first_word(w
, "no-setuid-fixup-locked"))
739 c
->secure_bits
|= SECURE_NO_SETUID_FIXUP_LOCKED
;
740 else if (first_word(w
, "noroot"))
741 c
->secure_bits
|= SECURE_NOROOT
;
742 else if (first_word(w
, "noroot-locked"))
743 c
->secure_bits
|= SECURE_NOROOT_LOCKED
;
745 log_error("[%s:%u] Failed to parse secure bits: %s", filename
, line
, rvalue
);
753 static int config_parse_bounding_set(
754 const char *filename
,
762 ExecContext
*c
= data
;
772 FOREACH_WORD(w
, l
, rvalue
, state
) {
777 if (!(t
= strndup(w
, l
)))
780 r
= cap_from_name(t
, &cap
);
784 log_error("[%s:%u] Failed to parse capability bounding set: %s", filename
, line
, rvalue
);
788 c
->capability_bounding_set_drop
|= 1 << cap
;
794 static int config_parse_timer_slack_ns(
795 const char *filename
,
803 ExecContext
*c
= data
;
812 if ((r
= safe_atolu(rvalue
, &u
)) < 0) {
813 log_error("[%s:%u] Failed to parse time slack value: %s", filename
, line
, rvalue
);
817 c
->timer_slack_ns
= u
;
822 static int config_parse_limit(
823 const char *filename
,
831 struct rlimit
**rl
= data
;
832 unsigned long long u
;
840 if ((r
= safe_atollu(rvalue
, &u
)) < 0) {
841 log_error("[%s:%u] Failed to parse resource value: %s", filename
, line
, rvalue
);
846 if (!(*rl
= new(struct rlimit
, 1)))
849 (*rl
)->rlim_cur
= (*rl
)->rlim_max
= (rlim_t
) u
;
853 static int config_parse_cgroup(
854 const char *filename
,
867 FOREACH_WORD(w
, l
, rvalue
, state
) {
871 if (!(t
= strndup(w
, l
)))
874 r
= unit_add_cgroup_from_text(u
, t
);
884 static int config_parse_sysv_priority(
885 const char *filename
,
893 int *priority
= data
;
901 if ((r
= safe_atoi(rvalue
, &i
)) < 0 || i
< 0) {
902 log_error("[%s:%u] Failed to parse SysV start priority: %s", filename
, line
, rvalue
);
910 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
914 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
925 /* This will update the filename pointer if the loaded file is
926 * reached by a symlink. The old string will be freed. */
929 char *target
, *k
, *name
;
931 if (c
++ >= FOLLOW_MAX
)
934 path_kill_slashes(*filename
);
936 /* Add the file name we are currently looking at to
937 * the names of this unit */
938 name
= file_name_from_path(*filename
);
939 if (!(id
= set_get(names
, name
))) {
941 if (!(id
= strdup(name
)))
944 if ((r
= set_put(names
, id
)) < 0) {
950 /* Try to open the file name, but don't if its a symlink */
951 if ((fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
)) >= 0)
957 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
958 if ((r
= readlink_malloc(*filename
, &target
)) < 0)
961 k
= file_in_same_dir(*filename
, target
);
971 if (!(f
= fdopen(fd
, "r"))) {
973 close_nointr_nofail(fd
);
982 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
990 /* Let's try to add in all symlink names we found */
991 while ((k
= set_steal_first(names
))) {
993 /* First try to merge in the other name into our
995 if ((r
= unit_merge_by_name(*u
, k
)) < 0) {
998 /* Hmm, we couldn't merge the other unit into
999 * ours? Then let's try it the other way
1002 other
= manager_get_unit((*u
)->meta
.manager
, k
);
1006 if ((r
= unit_merge(other
, *u
)) >= 0) {
1008 return merge_by_names(u
, names
, NULL
);
1015 unit_choose_id(*u
, id
);
1023 static void dump_items(FILE *f
, const ConfigItem
*items
) {
1024 const ConfigItem
*i
;
1025 const char *prev_section
= NULL
;
1026 bool not_first
= false;
1029 ConfigParserCallback callback
;
1032 { config_parse_int
, "INTEGER" },
1033 { config_parse_unsigned
, "UNSIGNED" },
1034 { config_parse_size
, "SIZE" },
1035 { config_parse_bool
, "BOOLEAN" },
1036 { config_parse_string
, "STRING" },
1037 { config_parse_path
, "PATH" },
1038 { config_parse_strv
, "STRING [...]" },
1039 { config_parse_nice
, "NICE" },
1040 { config_parse_oom_adjust
, "OOMADJUST" },
1041 { config_parse_io_class
, "IOCLASS" },
1042 { config_parse_io_priority
, "IOPRIORITY" },
1043 { config_parse_cpu_sched_policy
, "CPUSCHEDPOLICY" },
1044 { config_parse_cpu_sched_prio
, "CPUSCHEDPRIO" },
1045 { config_parse_cpu_affinity
, "CPUAFFINITY" },
1046 { config_parse_mode
, "MODE" },
1047 { config_parse_output
, "OUTPUT" },
1048 { config_parse_input
, "INPUT" },
1049 { config_parse_facility
, "FACILITY" },
1050 { config_parse_level
, "LEVEL" },
1051 { config_parse_capabilities
, "CAPABILITIES" },
1052 { config_parse_secure_bits
, "SECUREBITS" },
1053 { config_parse_bounding_set
, "BOUNDINGSET" },
1054 { config_parse_timer_slack_ns
, "TIMERSLACK" },
1055 { config_parse_limit
, "LIMIT" },
1056 { config_parse_cgroup
, "CGROUP [...]" },
1057 { config_parse_deps
, "UNIT [...]" },
1058 { config_parse_names
, "UNIT [...]" },
1059 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
1060 { config_parse_service_type
, "SERVICETYPE" },
1061 { config_parse_service_restart
, "SERVICERESTART" },
1062 { config_parse_sysv_priority
, "SYSVPRIORITY" },
1063 { config_parse_kill_mode
, "KILLMODE" },
1064 { config_parse_listen
, "SOCKET [...]" },
1065 { config_parse_socket_bind
, "SOCKETBIND" },
1066 { config_parse_bindtodevice
, "NETWORKINTERFACE" }
1072 for (i
= items
; i
->lvalue
; i
++) {
1074 const char *rvalue
= "OTHER";
1076 if (!streq_ptr(i
->section
, prev_section
)) {
1082 fprintf(f
, "[%s]\n", i
->section
);
1083 prev_section
= i
->section
;
1086 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
1087 if (i
->parse
== table
[j
].callback
) {
1088 rvalue
= table
[j
].rvalue
;
1092 fprintf(f
, "%s=%s\n", i
->lvalue
, rvalue
);
1096 static int load_from_path(Unit
*u
, const char *path
) {
1098 static const char* const section_table
[_UNIT_TYPE_MAX
] = {
1099 [UNIT_SERVICE
] = "Service",
1100 [UNIT_TIMER
] = "Timer",
1101 [UNIT_SOCKET
] = "Socket",
1102 [UNIT_TARGET
] = "Target",
1103 [UNIT_DEVICE
] = "Device",
1104 [UNIT_MOUNT
] = "Mount",
1105 [UNIT_AUTOMOUNT
] = "Automount",
1106 [UNIT_SNAPSHOT
] = "Snapshot"
1109 #define EXEC_CONTEXT_CONFIG_ITEMS(context, section) \
1110 { "WorkingDirectory", config_parse_path, &(context).working_directory, section }, \
1111 { "RootDirectory", config_parse_path, &(context).root_directory, section }, \
1112 { "User", config_parse_string, &(context).user, section }, \
1113 { "Group", config_parse_string, &(context).group, section }, \
1114 { "SupplementaryGroups", config_parse_strv, &(context).supplementary_groups, section }, \
1115 { "Nice", config_parse_nice, &(context), section }, \
1116 { "OOMAdjust", config_parse_oom_adjust, &(context), section }, \
1117 { "IOSchedulingClass", config_parse_io_class, &(context), section }, \
1118 { "IOSchedulingPriority", config_parse_io_priority, &(context), section }, \
1119 { "CPUSchedulingPolicy", config_parse_cpu_sched_policy,&(context), section }, \
1120 { "CPUSchedulingPriority", config_parse_cpu_sched_prio, &(context), section }, \
1121 { "CPUSchedulingResetOnFork", config_parse_bool, &(context).cpu_sched_reset_on_fork, section }, \
1122 { "CPUAffinity", config_parse_cpu_affinity, &(context), section }, \
1123 { "UMask", config_parse_mode, &(context).umask, section }, \
1124 { "Environment", config_parse_strv, &(context).environment, section }, \
1125 { "StandardInput", config_parse_input, &(context).std_input, section }, \
1126 { "StandardOutput", config_parse_output, &(context).std_output, section }, \
1127 { "StandardError", config_parse_output, &(context).std_output, section }, \
1128 { "TTYPath", config_parse_path, &(context).tty_path, section }, \
1129 { "SyslogIdentifier", config_parse_string, &(context).syslog_identifier, section }, \
1130 { "SyslogFacility", config_parse_facility, &(context).syslog_priority, section }, \
1131 { "SyslogLevel", config_parse_level, &(context).syslog_priority, section }, \
1132 { "Capabilities", config_parse_capabilities, &(context), section }, \
1133 { "SecureBits", config_parse_secure_bits, &(context), section }, \
1134 { "CapabilityBoundingSetDrop", config_parse_bounding_set, &(context), section }, \
1135 { "TimerSlackNS", config_parse_timer_slack_ns, &(context), section }, \
1136 { "LimitCPU", config_parse_limit, &(context).rlimit[RLIMIT_CPU], section }, \
1137 { "LimitFSIZE", config_parse_limit, &(context).rlimit[RLIMIT_FSIZE], section }, \
1138 { "LimitDATA", config_parse_limit, &(context).rlimit[RLIMIT_DATA], section }, \
1139 { "LimitSTACK", config_parse_limit, &(context).rlimit[RLIMIT_STACK], section }, \
1140 { "LimitCORE", config_parse_limit, &(context).rlimit[RLIMIT_CORE], section }, \
1141 { "LimitRSS", config_parse_limit, &(context).rlimit[RLIMIT_RSS], section }, \
1142 { "LimitNOFILE", config_parse_limit, &(context).rlimit[RLIMIT_NOFILE], section }, \
1143 { "LimitAS", config_parse_limit, &(context).rlimit[RLIMIT_AS], section }, \
1144 { "LimitNPROC", config_parse_limit, &(context).rlimit[RLIMIT_NPROC], section }, \
1145 { "LimitMEMLOCK", config_parse_limit, &(context).rlimit[RLIMIT_MEMLOCK], section }, \
1146 { "LimitLOCKS", config_parse_limit, &(context).rlimit[RLIMIT_LOCKS], section }, \
1147 { "LimitSIGPENDING", config_parse_limit, &(context).rlimit[RLIMIT_SIGPENDING], section }, \
1148 { "LimitMSGQUEUE", config_parse_limit, &(context).rlimit[RLIMIT_MSGQUEUE], section }, \
1149 { "LimitNICE", config_parse_limit, &(context).rlimit[RLIMIT_NICE], section }, \
1150 { "LimitRTPRIO", config_parse_limit, &(context).rlimit[RLIMIT_RTPRIO], section }, \
1151 { "LimitRTTIME", config_parse_limit, &(context).rlimit[RLIMIT_RTTIME], section }, \
1152 { "ControlGroup", config_parse_cgroup, u, section }
1154 const ConfigItem items
[] = {
1155 { "Names", config_parse_names
, u
, "Unit" },
1156 { "Description", config_parse_string
, &u
->meta
.description
, "Unit" },
1157 { "Requires", config_parse_deps
, UINT_TO_PTR(UNIT_REQUIRES
), "Unit" },
1158 { "RequiresOverridable", config_parse_deps
, UINT_TO_PTR(UNIT_REQUIRES_OVERRIDABLE
), "Unit" },
1159 { "Requisite", config_parse_deps
, UINT_TO_PTR(UNIT_REQUISITE
), "Unit" },
1160 { "RequisiteOverridable", config_parse_deps
, UINT_TO_PTR(UNIT_REQUISITE_OVERRIDABLE
), "Unit" },
1161 { "Wants", config_parse_deps
, UINT_TO_PTR(UNIT_WANTS
), "Unit" },
1162 { "Conflicts", config_parse_deps
, UINT_TO_PTR(UNIT_CONFLICTS
), "Unit" },
1163 { "Before", config_parse_deps
, UINT_TO_PTR(UNIT_BEFORE
), "Unit" },
1164 { "After", config_parse_deps
, UINT_TO_PTR(UNIT_AFTER
), "Unit" },
1165 { "RecursiveStop", config_parse_bool
, &u
->meta
.recursive_stop
, "Unit" },
1166 { "StopWhenUnneeded", config_parse_bool
, &u
->meta
.stop_when_unneeded
, "Unit" },
1168 { "PIDFile", config_parse_path
, &u
->service
.pid_file
, "Service" },
1169 { "ExecStartPre", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START_PRE
, "Service" },
1170 { "ExecStart", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START
, "Service" },
1171 { "ExecStartPost", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START_POST
, "Service" },
1172 { "ExecReload", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_RELOAD
, "Service" },
1173 { "ExecStop", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_STOP
, "Service" },
1174 { "ExecStopPost", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_STOP_POST
, "Service" },
1175 { "RestartSec", config_parse_usec
, &u
->service
.restart_usec
, "Service" },
1176 { "TimeoutSec", config_parse_usec
, &u
->service
.timeout_usec
, "Service" },
1177 { "Type", config_parse_service_type
, &u
->service
.type
, "Service" },
1178 { "Restart", config_parse_service_restart
, &u
->service
.restart
, "Service" },
1179 { "PermissionsStartOnly", config_parse_bool
, &u
->service
.permissions_start_only
, "Service" },
1180 { "RootDirectoryStartOnly", config_parse_bool
, &u
->service
.root_directory_start_only
, "Service" },
1181 { "ValidNoProcess", config_parse_bool
, &u
->service
.valid_no_process
, "Service" },
1182 { "SysVStartPriority", config_parse_sysv_priority
, &u
->service
.sysv_start_priority
, "Service" },
1183 { "KillMode", config_parse_kill_mode
, &u
->service
.kill_mode
, "Service" },
1184 { "NonBlocking", config_parse_bool
, &u
->service
.exec_context
.non_blocking
, "Service" },
1185 { "BusName", config_parse_string
, &u
->service
.bus_name
, "Service" },
1186 EXEC_CONTEXT_CONFIG_ITEMS(u
->service
.exec_context
, "Service"),
1188 { "ListenStream", config_parse_listen
, &u
->socket
, "Socket" },
1189 { "ListenDatagram", config_parse_listen
, &u
->socket
, "Socket" },
1190 { "ListenSequentialPacket", config_parse_listen
, &u
->socket
, "Socket" },
1191 { "ListenFIFO", config_parse_listen
, &u
->socket
, "Socket" },
1192 { "BindIPv6Only", config_parse_socket_bind
, &u
->socket
, "Socket" },
1193 { "Backlog", config_parse_unsigned
, &u
->socket
.backlog
, "Socket" },
1194 { "BindToDevice", config_parse_bindtodevice
, &u
->socket
, "Socket" },
1195 { "ExecStartPre", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_START_PRE
, "Socket" },
1196 { "ExecStartPost", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_START_POST
, "Socket" },
1197 { "ExecStopPre", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_STOP_PRE
, "Socket" },
1198 { "ExecStopPost", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_STOP_POST
, "Socket" },
1199 { "TimeoutSec", config_parse_usec
, &u
->socket
.timeout_usec
, "Socket" },
1200 { "DirectoryMode", config_parse_mode
, &u
->socket
.directory_mode
, "Socket" },
1201 { "SocketMode", config_parse_mode
, &u
->socket
.socket_mode
, "Socket" },
1202 { "KillMode", config_parse_kill_mode
, &u
->socket
.kill_mode
, "Socket" },
1203 { "Accept", config_parse_bool
, &u
->socket
.accept
, "Socket" },
1204 EXEC_CONTEXT_CONFIG_ITEMS(u
->socket
.exec_context
, "Socket"),
1206 { "What", config_parse_string
, &u
->mount
.parameters_fragment
.what
, "Mount" },
1207 { "Where", config_parse_path
, &u
->mount
.where
, "Mount" },
1208 { "Options", config_parse_string
, &u
->mount
.parameters_fragment
.options
, "Mount" },
1209 { "Type", config_parse_string
, &u
->mount
.parameters_fragment
.fstype
, "Mount" },
1210 { "TimeoutSec", config_parse_usec
, &u
->mount
.timeout_usec
, "Mount" },
1211 { "KillMode", config_parse_kill_mode
, &u
->mount
.kill_mode
, "Mount" },
1212 EXEC_CONTEXT_CONFIG_ITEMS(u
->mount
.exec_context
, "Mount"),
1214 { "Where", config_parse_path
, &u
->automount
.where
, "Automount" },
1216 { NULL
, NULL
, NULL
, NULL
}
1219 #undef EXEC_CONTEXT_CONFIG_ITEMS
1221 const char *sections
[3];
1226 char *filename
= NULL
, *id
= NULL
;
1230 /* Dirty dirty hack. */
1231 dump_items((FILE*) path
, items
);
1238 sections
[0] = "Unit";
1239 sections
[1] = section_table
[u
->meta
.type
];
1242 if (!(symlink_names
= set_new(string_hash_func
, string_compare_func
)))
1245 if (path_is_absolute(path
)) {
1247 if (!(filename
= strdup(path
))) {
1252 if ((r
= open_follow(&filename
, &f
, symlink_names
, &id
)) < 0) {
1263 STRV_FOREACH(p
, u
->meta
.manager
->unit_path
) {
1265 /* Instead of opening the path right away, we manually
1266 * follow all symlinks and add their name to our unit
1267 * name set while doing so */
1268 if (!(filename
= path_make_absolute(path
, *p
))) {
1273 if ((r
= open_follow(&filename
, &f
, symlink_names
, &id
)) < 0) {
1282 /* Empty the symlink names for the next run */
1283 while ((sn
= set_steal_first(symlink_names
)))
1299 if ((r
= merge_by_names(&merged
, symlink_names
, id
)) < 0)
1303 u
->meta
.load_state
= UNIT_MERGED
;
1308 /* Now, parse the file contents */
1309 if ((r
= config_parse(filename
, f
, sections
, items
, u
)) < 0)
1312 free(u
->meta
.fragment_path
);
1313 u
->meta
.fragment_path
= filename
;
1316 u
->meta
.load_state
= UNIT_LOADED
;
1320 while ((k
= set_steal_first(symlink_names
)))
1323 set_free(symlink_names
);
1332 int unit_load_fragment(Unit
*u
) {
1337 if (u
->meta
.fragment_path
) {
1339 if ((r
= load_from_path(u
, u
->meta
.fragment_path
)) < 0)
1346 /* Try to find the unit under its id */
1347 if ((r
= load_from_path(u
, u
->meta
.id
)) < 0)
1350 /* Try to find an alias we can load this with */
1351 if (u
->meta
.load_state
== UNIT_STUB
)
1352 SET_FOREACH(t
, u
->meta
.names
, i
) {
1354 if (t
== u
->meta
.id
)
1357 if ((r
= load_from_path(u
, t
)) < 0)
1360 if (u
->meta
.load_state
!= UNIT_STUB
)
1364 /* Now, follow the same logic, but look for a template */
1365 if (u
->meta
.load_state
== UNIT_STUB
&& u
->meta
.instance
) {
1368 if (!(k
= unit_name_template(u
->meta
.id
)))
1371 r
= load_from_path(u
, k
);
1377 if (u
->meta
.load_state
== UNIT_STUB
)
1378 SET_FOREACH(t
, u
->meta
.names
, i
) {
1380 if (t
== u
->meta
.id
)
1383 if (!(k
= unit_name_template(t
)))
1386 r
= load_from_path(u
, k
);
1392 if (u
->meta
.load_state
!= UNIT_STUB
)
1401 void unit_dump_config_items(FILE *f
) {
1402 /* OK, this wins a prize for extreme ugliness. */
1404 load_from_path(NULL
, (const void*) f
);