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"
40 static int config_parse_deps(
49 UnitDependency d
= PTR_TO_UINT(data
);
59 FOREACH_WORD(w
, l
, rvalue
, state
) {
63 if (!(t
= strndup(w
, l
)))
66 r
= unit_add_dependency_by_name(u
, d
, t
);
76 static int config_parse_names(
95 FOREACH_WORD(w
, l
, rvalue
, state
) {
99 if (!(t
= strndup(w
, l
)))
102 r
= unit_merge_by_name(u
, t
);
112 static int config_parse_listen(
113 const char *filename
,
132 if (!(p
= new0(SocketPort
, 1)))
135 if (streq(lvalue
, "ListenFIFO")) {
136 p
->type
= SOCKET_FIFO
;
138 if (!(p
->path
= strdup(rvalue
))) {
143 p
->type
= SOCKET_SOCKET
;
145 if ((r
= socket_address_parse(&p
->address
, rvalue
)) < 0) {
146 log_error("[%s:%u] Failed to parse address value: %s", filename
, line
, rvalue
);
151 if (streq(lvalue
, "ListenStream"))
152 p
->address
.type
= SOCK_STREAM
;
153 else if (streq(lvalue
, "ListenDatagram"))
154 p
->address
.type
= SOCK_DGRAM
;
156 assert(streq(lvalue
, "ListenSequentialPacket"));
157 p
->address
.type
= SOCK_SEQPACKET
;
160 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
162 return -EPROTONOSUPPORT
;
167 LIST_PREPEND(SocketPort
, port
, s
->ports
, p
);
172 static int config_parse_socket_bind(
173 const char *filename
,
191 if ((r
= parse_boolean(rvalue
)) < 0) {
192 log_error("[%s:%u] Failed to parse bind IPv6 only value: %s", filename
, line
, rvalue
);
196 s
->bind_ipv6_only
= r
? SOCKET_ADDRESS_IPV6_ONLY
: SOCKET_ADDRESS_BOTH
;
201 static int config_parse_nice(
202 const char *filename
,
210 ExecContext
*c
= data
;
218 if ((r
= safe_atoi(rvalue
, &priority
)) < 0) {
219 log_error("[%s:%u] Failed to parse nice priority: %s", filename
, line
, rvalue
);
223 if (priority
< PRIO_MIN
|| priority
>= PRIO_MAX
) {
224 log_error("[%s:%u] Nice priority out of range: %s", filename
, line
, rvalue
);
234 static int config_parse_oom_adjust(
235 const char *filename
,
243 ExecContext
*c
= data
;
251 if ((r
= safe_atoi(rvalue
, &oa
)) < 0) {
252 log_error("[%s:%u] Failed to parse OOM adjust value: %s", filename
, line
, rvalue
);
256 if (oa
< OOM_DISABLE
|| oa
> OOM_ADJUST_MAX
) {
257 log_error("[%s:%u] OOM adjust value out of range: %s", filename
, line
, rvalue
);
262 c
->oom_adjust_set
= true;
267 static int config_parse_mode(
268 const char *filename
,
286 l
= strtol(rvalue
, &x
, 8);
287 if (!x
|| *x
|| errno
) {
288 log_error("[%s:%u] Failed to parse mode value: %s", filename
, line
, rvalue
);
289 return errno
? -errno
: -EINVAL
;
292 if (l
< 0000 || l
> 07777) {
293 log_error("[%s:%u] mode value out of range: %s", filename
, line
, rvalue
);
301 static int config_parse_exec(
302 const char *filename
,
310 ExecCommand
**e
= data
, *nce
= NULL
;
323 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
)
326 if (!(n
= new(char*, k
+1)))
330 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
)
331 if (!(n
[k
++] = strndup(w
, l
)))
336 if (!n
[0] || !path_is_absolute(n
[0])) {
337 log_error("[%s:%u] Invalid executable path in command line: %s", filename
, line
, rvalue
);
342 if (!(nce
= new0(ExecCommand
, 1)))
346 if (!(nce
->path
= strdup(n
[0])))
349 exec_command_append_list(e
, nce
);
363 static int config_parse_usec(
364 const char *filename
,
373 unsigned long long u
;
381 if ((r
= safe_atollu(rvalue
, &u
)) < 0) {
382 log_error("[%s:%u] Failed to parse time value: %s", filename
, line
, rvalue
);
386 /* We actually assume the user configures seconds. Later on we
387 * might choose to support suffixes for time values, to
388 * configure bigger or smaller units */
390 *usec
= u
* USEC_PER_SEC
;
395 static int config_parse_service_type(
396 const char *filename
,
412 if ((x
= service_type_from_string(rvalue
)) < 0) {
413 log_error("[%s:%u] Failed to parse service type: %s", filename
, line
, rvalue
);
422 static int config_parse_service_restart(
423 const char *filename
,
439 if ((x
= service_restart_from_string(rvalue
)) < 0) {
440 log_error("[%s:%u] Failed to parse service restart specifier: %s", filename
, line
, rvalue
);
449 static int config_parse_bindtodevice(
450 const char *filename
,
466 if (rvalue
[0] && !streq(rvalue
, "*")) {
467 if (!(n
= strdup(rvalue
)))
472 free(s
->bind_to_device
);
473 s
->bind_to_device
= n
;
478 static int config_parse_output(
479 const char *filename
,
487 ExecOutput
*o
= data
, x
;
494 if ((x
= exec_output_from_string(rvalue
)) < 0) {
495 log_error("[%s:%u] Failed to parse output specifier: %s", filename
, line
, rvalue
);
504 static int config_parse_input(
505 const char *filename
,
513 ExecInput
*i
= data
, x
;
520 if ((x
= exec_input_from_string(rvalue
)) < 0) {
521 log_error("[%s:%u] Failed to parse input specifier: %s", filename
, line
, rvalue
);
530 static int config_parse_facility(
531 const char *filename
,
547 if ((x
= log_facility_from_string(rvalue
)) < 0)
549 /* Second try, let's see if this is a number. */
550 if (safe_atoi(rvalue
, &x
) < 0 || !log_facility_to_string(x
)) {
551 log_error("[%s:%u] Failed to parse log facility: %s", filename
, line
, rvalue
);
555 *o
= LOG_MAKEPRI(x
, LOG_PRI(*o
));
560 static int config_parse_level(
561 const char *filename
,
577 if ((x
= log_level_from_string(rvalue
)) < 0)
579 /* Second try, let's see if this is a number. */
580 if (safe_atoi(rvalue
, &x
) < 0 || !log_level_to_string(x
)) {
581 log_error("[%s:%u] Failed to parse log level: %s", filename
, line
, rvalue
);
585 *o
= LOG_MAKEPRI(LOG_FAC(*o
), x
);
589 static int config_parse_io_class(
590 const char *filename
,
598 ExecContext
*c
= data
;
606 if ((x
= ioprio_class_from_string(rvalue
)) < 0)
608 /* Second try, let's see if this is a number. */
609 if (safe_atoi(rvalue
, &x
) < 0 || !ioprio_class_to_string(x
)) {
610 log_error("[%s:%u] Failed to parse IO scheduling class: %s", filename
, line
, rvalue
);
614 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
615 c
->ioprio_set
= true;
620 static int config_parse_io_priority(
621 const char *filename
,
629 ExecContext
*c
= data
;
637 if (safe_atoi(rvalue
, &i
) < 0 || i
< 0 || i
>= IOPRIO_BE_NR
) {
638 log_error("[%s:%u] Failed to parse io priority: %s", filename
, line
, rvalue
);
642 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
643 c
->ioprio_set
= true;
648 static int config_parse_cpu_sched_policy(
649 const char *filename
,
658 ExecContext
*c
= data
;
666 if ((x
= sched_policy_from_string(rvalue
)) < 0)
668 /* Second try, let's see if this is a number. */
669 if (safe_atoi(rvalue
, &x
) < 0 || !sched_policy_to_string(x
)) {
670 log_error("[%s:%u] Failed to parse CPU scheduling policy: %s", filename
, line
, rvalue
);
674 c
->cpu_sched_policy
= x
;
675 c
->cpu_sched_set
= true;
680 static int config_parse_cpu_sched_prio(
681 const char *filename
,
689 ExecContext
*c
= data
;
697 /* On Linux RR/FIFO have the same range */
698 if (safe_atoi(rvalue
, &i
) < 0 || i
< sched_get_priority_min(SCHED_RR
) || i
> sched_get_priority_max(SCHED_RR
)) {
699 log_error("[%s:%u] Failed to parse CPU scheduling priority: %s", filename
, line
, rvalue
);
703 c
->cpu_sched_priority
= i
;
704 c
->cpu_sched_set
= true;
709 static int config_parse_cpu_affinity(
710 const char *filename
,
718 ExecContext
*c
= data
;
728 FOREACH_WORD(w
, l
, rvalue
, state
) {
733 if (!(t
= strndup(w
, l
)))
736 r
= safe_atou(t
, &cpu
);
739 if (r
< 0 || cpu
>= CPU_SETSIZE
) {
740 log_error("[%s:%u] Failed to parse CPU affinity: %s", filename
, line
, rvalue
);
744 CPU_SET(cpu
, &c
->cpu_affinity
);
747 c
->cpu_affinity_set
= true;
752 static int config_parse_capabilities(
753 const char *filename
,
761 ExecContext
*c
= data
;
769 if (!(cap
= cap_from_text(rvalue
))) {
773 log_error("[%s:%u] Failed to parse capabilities: %s", filename
, line
, rvalue
);
778 cap_free(c
->capabilities
);
779 c
->capabilities
= cap
;
784 static int config_parse_secure_bits(
785 const char *filename
,
793 ExecContext
*c
= data
;
803 FOREACH_WORD(w
, l
, rvalue
, state
) {
804 if (first_word(w
, "keep-caps"))
805 c
->secure_bits
|= SECURE_KEEP_CAPS
;
806 else if (first_word(w
, "keep-caps-locked"))
807 c
->secure_bits
|= SECURE_KEEP_CAPS_LOCKED
;
808 else if (first_word(w
, "no-setuid-fixup"))
809 c
->secure_bits
|= SECURE_NO_SETUID_FIXUP
;
810 else if (first_word(w
, "no-setuid-fixup-locked"))
811 c
->secure_bits
|= SECURE_NO_SETUID_FIXUP_LOCKED
;
812 else if (first_word(w
, "noroot"))
813 c
->secure_bits
|= SECURE_NOROOT
;
814 else if (first_word(w
, "noroot-locked"))
815 c
->secure_bits
|= SECURE_NOROOT_LOCKED
;
817 log_error("[%s:%u] Failed to parse secure bits: %s", filename
, line
, rvalue
);
825 static int config_parse_bounding_set(
826 const char *filename
,
834 ExecContext
*c
= data
;
844 FOREACH_WORD(w
, l
, rvalue
, state
) {
849 if (!(t
= strndup(w
, l
)))
852 r
= cap_from_name(t
, &cap
);
856 log_error("[%s:%u] Failed to parse capability bounding set: %s", filename
, line
, rvalue
);
860 c
->capability_bounding_set_drop
|= 1 << cap
;
866 static int config_parse_timer_slack_ns(
867 const char *filename
,
875 ExecContext
*c
= data
;
884 if ((r
= safe_atolu(rvalue
, &u
)) < 0) {
885 log_error("[%s:%u] Failed to parse time slack value: %s", filename
, line
, rvalue
);
889 c
->timer_slack_ns
= u
;
894 static int config_parse_limit(
895 const char *filename
,
903 struct rlimit
**rl
= data
;
904 unsigned long long u
;
912 if ((r
= safe_atollu(rvalue
, &u
)) < 0) {
913 log_error("[%s:%u] Failed to parse resource value: %s", filename
, line
, rvalue
);
918 if (!(*rl
= new(struct rlimit
, 1)))
921 (*rl
)->rlim_cur
= (*rl
)->rlim_max
= (rlim_t
) u
;
925 static int config_parse_cgroup(
926 const char *filename
,
939 FOREACH_WORD(w
, l
, rvalue
, state
) {
943 if (!(t
= strndup(w
, l
)))
946 r
= unit_add_cgroup_from_text(u
, t
);
956 static int config_parse_sysv_priority(
957 const char *filename
,
965 int *priority
= data
;
973 if ((r
= safe_atoi(rvalue
, &i
)) < 0 || i
< 0) {
974 log_error("[%s:%u] Failed to parse SysV start priority: %s", filename
, line
, rvalue
);
982 static int config_parse_kill_mode(
983 const char *filename
,
991 KillMode
*m
= data
, x
;
998 if ((x
= kill_mode_from_string(rvalue
)) < 0) {
999 log_error("[%s:%u] Failed to parse kill mode specifier: %s", filename
, line
, rvalue
);
1008 #define FOLLOW_MAX 8
1010 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_id
) {
1021 /* This will update the filename pointer if the loaded file is
1022 * reached by a symlink. The old string will be freed. */
1025 char *target
, *k
, *name
;
1027 if (c
++ >= FOLLOW_MAX
)
1030 path_kill_slashes(*filename
);
1032 /* Add the file name we are currently looking at to
1033 * the names of this unit */
1034 name
= file_name_from_path(*filename
);
1035 if (!(id
= set_get(names
, name
))) {
1037 if (!(id
= strdup(name
)))
1040 if ((r
= set_put(names
, id
)) < 0) {
1046 /* Try to open the file name, but don't if its a symlink */
1047 if ((fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
)) >= 0)
1053 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
1054 if ((r
= readlink_malloc(*filename
, &target
)) < 0)
1057 k
= file_in_same_dir(*filename
, target
);
1067 if (!(f
= fdopen(fd
, "r"))) {
1069 assert(close_nointr(fd
) == 0);
1078 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
1086 /* Let's try to add in all symlink names we found */
1087 while ((k
= set_steal_first(names
))) {
1089 /* First try to merge in the other name into our
1091 if ((r
= unit_merge_by_name(*u
, k
)) < 0) {
1094 /* Hmm, we couldn't merge the other unit into
1095 * ours? Then let's try it the other way
1098 other
= manager_get_unit((*u
)->meta
.manager
, k
);
1102 if ((r
= unit_merge(other
, *u
)) >= 0) {
1104 return merge_by_names(u
, names
, NULL
);
1111 unit_choose_id(*u
, id
);
1119 static int load_from_path(Unit
*u
, const char *path
, UnitLoadState
*new_state
) {
1121 static const char* const section_table
[_UNIT_TYPE_MAX
] = {
1122 [UNIT_SERVICE
] = "Service",
1123 [UNIT_TIMER
] = "Timer",
1124 [UNIT_SOCKET
] = "Socket",
1125 [UNIT_TARGET
] = "Target",
1126 [UNIT_DEVICE
] = "Device",
1127 [UNIT_MOUNT
] = "Mount",
1128 [UNIT_AUTOMOUNT
] = "Automount",
1129 [UNIT_SNAPSHOT
] = "Snapshot"
1132 #define EXEC_CONTEXT_CONFIG_ITEMS(context, section) \
1133 { "WorkingDirectory", config_parse_path, &(context).working_directory, section }, \
1134 { "RootDirectory", config_parse_path, &(context).root_directory, section }, \
1135 { "User", config_parse_string, &(context).user, section }, \
1136 { "Group", config_parse_string, &(context).group, section }, \
1137 { "SupplementaryGroups", config_parse_strv, &(context).supplementary_groups, section }, \
1138 { "Nice", config_parse_nice, &(context), section }, \
1139 { "OOMAdjust", config_parse_oom_adjust, &(context), section }, \
1140 { "IOSchedulingClass", config_parse_io_class, &(context), section }, \
1141 { "IOSchedulingPriority", config_parse_io_priority, &(context), section }, \
1142 { "CPUSchedulingPolicy", config_parse_cpu_sched_policy,&(context), section }, \
1143 { "CPUSchedulingPriority", config_parse_cpu_sched_prio, &(context), section }, \
1144 { "CPUSchedulingResetOnFork", config_parse_bool, &(context).cpu_sched_reset_on_fork, section }, \
1145 { "CPUAffinity", config_parse_cpu_affinity, &(context), section }, \
1146 { "UMask", config_parse_mode, &(context).umask, section }, \
1147 { "Environment", config_parse_strv, &(context).environment, section }, \
1148 { "Output", config_parse_output, &(context).output, section }, \
1149 { "Input", config_parse_input, &(context).input, section }, \
1150 { "SyslogIdentifier", config_parse_string, &(context).syslog_identifier, section }, \
1151 { "SyslogFacility", config_parse_facility, &(context).syslog_priority, section }, \
1152 { "SyslogLevel", config_parse_level, &(context).syslog_priority, section }, \
1153 { "Capabilities", config_parse_capabilities, &(context), section }, \
1154 { "SecureBits", config_parse_secure_bits, &(context), section }, \
1155 { "CapabilityBoundingSetDrop", config_parse_bounding_set, &(context), section }, \
1156 { "TimerSlackNS", config_parse_timer_slack_ns, &(context), section }, \
1157 { "LimitCPU", config_parse_limit, &(context).rlimit[RLIMIT_CPU], section }, \
1158 { "LimitFSIZE", config_parse_limit, &(context).rlimit[RLIMIT_FSIZE], section }, \
1159 { "LimitDATA", config_parse_limit, &(context).rlimit[RLIMIT_DATA], section }, \
1160 { "LimitSTACK", config_parse_limit, &(context).rlimit[RLIMIT_STACK], section }, \
1161 { "LimitCORE", config_parse_limit, &(context).rlimit[RLIMIT_CORE], section }, \
1162 { "LimitRSS", config_parse_limit, &(context).rlimit[RLIMIT_RSS], section }, \
1163 { "LimitNOFILE", config_parse_limit, &(context).rlimit[RLIMIT_NOFILE], section }, \
1164 { "LimitAS", config_parse_limit, &(context).rlimit[RLIMIT_AS], section }, \
1165 { "LimitNPROC", config_parse_limit, &(context).rlimit[RLIMIT_NPROC], section }, \
1166 { "LimitMEMLOCK", config_parse_limit, &(context).rlimit[RLIMIT_MEMLOCK], section }, \
1167 { "LimitLOCKS", config_parse_limit, &(context).rlimit[RLIMIT_LOCKS], section }, \
1168 { "LimitSIGPENDING", config_parse_limit, &(context).rlimit[RLIMIT_SIGPENDING], section }, \
1169 { "LimitMSGQUEUE", config_parse_limit, &(context).rlimit[RLIMIT_MSGQUEUE], section }, \
1170 { "LimitNICE", config_parse_limit, &(context).rlimit[RLIMIT_NICE], section }, \
1171 { "LimitRTPRIO", config_parse_limit, &(context).rlimit[RLIMIT_RTPRIO], section }, \
1172 { "LimitRTTIME", config_parse_limit, &(context).rlimit[RLIMIT_RTTIME], section }, \
1173 { "NonBlocking", config_parse_bool, &(context).non_blocking, section }, \
1174 { "ControlGroup", config_parse_cgroup, u, section }, \
1175 { "NewSession", config_parse_bool, &(context).new_session, section }
1177 const ConfigItem items
[] = {
1178 { "Names", config_parse_names
, u
, "Meta" },
1179 { "Description", config_parse_string
, &u
->meta
.description
, "Meta" },
1180 { "Requires", config_parse_deps
, UINT_TO_PTR(UNIT_REQUIRES
), "Meta" },
1181 { "SoftRequires", config_parse_deps
, UINT_TO_PTR(UNIT_SOFT_REQUIRES
), "Meta" },
1182 { "Wants", config_parse_deps
, UINT_TO_PTR(UNIT_WANTS
), "Meta" },
1183 { "Requisite", config_parse_deps
, UINT_TO_PTR(UNIT_REQUISITE
), "Meta" },
1184 { "SoftRequisite", config_parse_deps
, UINT_TO_PTR(UNIT_SOFT_REQUISITE
), "Meta" },
1185 { "Conflicts", config_parse_deps
, UINT_TO_PTR(UNIT_CONFLICTS
), "Meta" },
1186 { "Before", config_parse_deps
, UINT_TO_PTR(UNIT_BEFORE
), "Meta" },
1187 { "After", config_parse_deps
, UINT_TO_PTR(UNIT_AFTER
), "Meta" },
1188 { "RecursiveStop", config_parse_bool
, &u
->meta
.recursive_stop
, "Meta" },
1189 { "StopWhenUnneeded", config_parse_bool
, &u
->meta
.stop_when_unneeded
, "Meta" },
1191 { "PIDFile", config_parse_path
, &u
->service
.pid_file
, "Service" },
1192 { "ExecStartPre", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START_PRE
, "Service" },
1193 { "ExecStart", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START
, "Service" },
1194 { "ExecStartPost", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START_POST
, "Service" },
1195 { "ExecReload", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_RELOAD
, "Service" },
1196 { "ExecStop", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_STOP
, "Service" },
1197 { "ExecStopPost", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_STOP_POST
, "Service" },
1198 { "RestartSec", config_parse_usec
, &u
->service
.restart_usec
, "Service" },
1199 { "TimeoutSec", config_parse_usec
, &u
->service
.timeout_usec
, "Service" },
1200 { "Type", config_parse_service_type
, &u
->service
, "Service" },
1201 { "Restart", config_parse_service_restart
, &u
->service
, "Service" },
1202 { "PermissionsStartOnly", config_parse_bool
, &u
->service
.permissions_start_only
, "Service" },
1203 { "RootDirectoryStartOnly", config_parse_bool
, &u
->service
.root_directory_start_only
, "Service" },
1204 { "ValidNoProcess", config_parse_bool
, &u
->service
.valid_no_process
, "Service" },
1205 { "SysVStartPriority", config_parse_sysv_priority
, &u
->service
.sysv_start_priority
, "Service" },
1206 { "KillMode", config_parse_kill_mode
, &u
->service
.kill_mode
, "Service" },
1207 EXEC_CONTEXT_CONFIG_ITEMS(u
->service
.exec_context
, "Service"),
1209 { "ListenStream", config_parse_listen
, &u
->socket
, "Socket" },
1210 { "ListenDatagram", config_parse_listen
, &u
->socket
, "Socket" },
1211 { "ListenSequentialPacket", config_parse_listen
, &u
->socket
, "Socket" },
1212 { "ListenFIFO", config_parse_listen
, &u
->socket
, "Socket" },
1213 { "BindIPv6Only", config_parse_socket_bind
, &u
->socket
, "Socket" },
1214 { "Backlog", config_parse_unsigned
, &u
->socket
.backlog
, "Socket" },
1215 { "BindToDevice", config_parse_bindtodevice
, &u
->socket
, "Socket" },
1216 { "ExecStartPre", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_START_PRE
, "Socket" },
1217 { "ExecStartPost", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_START_POST
, "Socket" },
1218 { "ExecStopPre", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_STOP_PRE
, "Socket" },
1219 { "ExecStopPost", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_STOP_POST
, "Socket" },
1220 { "DirectoryMode", config_parse_mode
, &u
->socket
.directory_mode
, "Socket" },
1221 { "SocketMode", config_parse_mode
, &u
->socket
.socket_mode
, "Socket" },
1222 { "KillMode", config_parse_kill_mode
, &u
->socket
.kill_mode
, "Socket" },
1223 EXEC_CONTEXT_CONFIG_ITEMS(u
->socket
.exec_context
, "Socket"),
1225 EXEC_CONTEXT_CONFIG_ITEMS(u
->automount
.exec_context
, "Automount"),
1227 { NULL
, NULL
, NULL
, NULL
}
1230 #undef EXEC_CONTEXT_CONFIG_ITEMS
1232 const char *sections
[3];
1237 char *filename
= NULL
, *id
= NULL
;
1243 sections
[0] = "Meta";
1244 sections
[1] = section_table
[u
->meta
.type
];
1247 if (!(symlink_names
= set_new(string_hash_func
, string_compare_func
)))
1250 if (path_is_absolute(path
)) {
1252 if (!(filename
= strdup(path
))) {
1257 if ((r
= open_follow(&filename
, &f
, symlink_names
, &id
)) < 0) {
1268 STRV_FOREACH(p
, u
->meta
.manager
->unit_path
) {
1270 /* Instead of opening the path right away, we manually
1271 * follow all symlinks and add their name to our unit
1272 * name set while doing so */
1273 if (!(filename
= path_make_absolute(path
, *p
))) {
1278 if ((r
= open_follow(&filename
, &f
, symlink_names
, &id
)) < 0) {
1287 /* Empty the symlink names for the next run */
1288 while ((sn
= set_steal_first(symlink_names
)))
1304 if ((r
= merge_by_names(&merged
, symlink_names
, id
)) < 0)
1308 *new_state
= UNIT_MERGED
;
1313 /* Now, parse the file contents */
1314 if ((r
= config_parse(filename
, f
, sections
, items
, u
)) < 0)
1317 free(u
->meta
.fragment_path
);
1318 u
->meta
.fragment_path
= filename
;
1321 *new_state
= UNIT_LOADED
;
1325 while ((k
= set_steal_first(symlink_names
)))
1328 set_free(symlink_names
);
1337 int unit_load_fragment(Unit
*u
, UnitLoadState
*new_state
) {
1342 assert(*new_state
== UNIT_STUB
);
1344 if (u
->meta
.fragment_path
) {
1346 if ((r
= load_from_path(u
, u
->meta
.fragment_path
, new_state
)) < 0)
1353 /* Try to find the unit under its id */
1354 if ((t
= unit_id(u
)))
1355 if ((r
= load_from_path(u
, t
, new_state
)) < 0)
1358 /* Try to find an alias we can load this with */
1359 if (*new_state
== UNIT_STUB
)
1360 SET_FOREACH(t
, u
->meta
.names
, i
) {
1362 if (unit_id(u
) == t
)
1365 if ((r
= load_from_path(u
, t
, new_state
)) < 0)
1368 if (*new_state
!= UNIT_STUB
)