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>
35 #include "conf-parser.h"
36 #include "load-fragment.h"
39 #include "securebits.h"
41 #include "unit-name.h"
43 #define COMMENTS "#;\n"
46 #define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \
47 static int function( \
48 const char *filename, \
50 const char *section, \
63 if ((x = name##_from_string(rvalue)) < 0) { \
64 log_error("[%s:%u] " msg ": %s", filename, line, rvalue); \
73 static int config_parse_deps(
82 UnitDependency d
= PTR_TO_UINT(data
);
92 FOREACH_WORD(w
, l
, rvalue
, state
) {
96 if (!(t
= strndup(w
, l
)))
99 k
= unit_name_printf(u
, t
);
105 r
= unit_add_dependency_by_name(u
, d
, k
, NULL
, true);
115 static int config_parse_names(
116 const char *filename
,
134 FOREACH_WORD(w
, l
, rvalue
, state
) {
138 if (!(t
= strndup(w
, l
)))
141 k
= unit_name_printf(u
, t
);
147 r
= unit_merge_by_name(u
, k
);
157 static int config_parse_string_printf(
158 const char *filename
,
176 if (!(k
= unit_full_printf(u
, rvalue
)))
190 static int config_parse_listen(
191 const char *filename
,
210 if (!(p
= new0(SocketPort
, 1)))
213 if (streq(lvalue
, "ListenFIFO")) {
214 p
->type
= SOCKET_FIFO
;
216 if (!(p
->path
= strdup(rvalue
))) {
221 path_kill_slashes(p
->path
);
223 p
->type
= SOCKET_SOCKET
;
225 if ((r
= socket_address_parse(&p
->address
, rvalue
)) < 0) {
226 log_error("[%s:%u] Failed to parse address value: %s", filename
, line
, rvalue
);
231 if (streq(lvalue
, "ListenStream"))
232 p
->address
.type
= SOCK_STREAM
;
233 else if (streq(lvalue
, "ListenDatagram"))
234 p
->address
.type
= SOCK_DGRAM
;
236 assert(streq(lvalue
, "ListenSequentialPacket"));
237 p
->address
.type
= SOCK_SEQPACKET
;
240 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
242 return -EPROTONOSUPPORT
;
247 LIST_PREPEND(SocketPort
, port
, s
->ports
, p
);
252 static int config_parse_socket_bind(
253 const char *filename
,
262 SocketAddressBindIPv6Only b
;
271 if ((b
= socket_address_bind_ipv6_only_from_string(rvalue
)) < 0) {
274 if ((r
= parse_boolean(rvalue
)) < 0) {
275 log_error("[%s:%u] Failed to parse bind IPv6 only value: %s", filename
, line
, rvalue
);
279 s
->bind_ipv6_only
= r
? SOCKET_ADDRESS_IPV6_ONLY
: SOCKET_ADDRESS_BOTH
;
281 s
->bind_ipv6_only
= b
;
286 static int config_parse_nice(
287 const char *filename
,
295 ExecContext
*c
= data
;
303 if ((r
= safe_atoi(rvalue
, &priority
)) < 0) {
304 log_error("[%s:%u] Failed to parse nice priority: %s", filename
, line
, rvalue
);
308 if (priority
< PRIO_MIN
|| priority
>= PRIO_MAX
) {
309 log_error("[%s:%u] Nice priority out of range: %s", filename
, line
, rvalue
);
319 static int config_parse_oom_adjust(
320 const char *filename
,
328 ExecContext
*c
= data
;
336 if ((r
= safe_atoi(rvalue
, &oa
)) < 0) {
337 log_error("[%s:%u] Failed to parse OOM adjust value: %s", filename
, line
, rvalue
);
341 if (oa
< OOM_DISABLE
|| oa
> OOM_ADJUST_MAX
) {
342 log_error("[%s:%u] OOM adjust value out of range: %s", filename
, line
, rvalue
);
347 c
->oom_adjust_set
= true;
352 static int config_parse_mode(
353 const char *filename
,
371 l
= strtol(rvalue
, &x
, 8);
372 if (!x
|| *x
|| errno
) {
373 log_error("[%s:%u] Failed to parse mode value: %s", filename
, line
, rvalue
);
374 return errno
? -errno
: -EINVAL
;
377 if (l
< 0000 || l
> 07777) {
378 log_error("[%s:%u] mode value out of range: %s", filename
, line
, rvalue
);
386 static int config_parse_exec(
387 const char *filename
,
395 ExecCommand
**e
= data
, *nce
= NULL
;
400 char *state
, *path
= NULL
;
401 bool honour_argv0
, write_to_path
;
408 /* We accept an absolute path as first argument, or
409 * alternatively an absolute prefixed with @ to allow
410 * overriding of argv[0]. */
412 honour_argv0
= rvalue
[0] == '@';
414 if (rvalue
[honour_argv0
? 1 : 0] != '/') {
415 log_error("[%s:%u] Invalid executable path in command line: %s", filename
, line
, rvalue
);
420 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
)
423 if (!(n
= new(char*, k
+ (honour_argv0
? 0 : 1))))
427 write_to_path
= honour_argv0
;
428 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
) {
430 if (!(path
= strndup(w
+1, l
-1)))
432 write_to_path
= false;
434 if (!(n
[k
++] = strndup(w
, l
)))
442 log_error("[%s:%u] Invalid command line: %s", filename
, line
, rvalue
);
448 if (!(path
= strdup(n
[0])))
451 assert(path_is_absolute(path
));
453 if (!(nce
= new0(ExecCommand
, 1)))
459 path_kill_slashes(nce
->path
);
461 exec_command_append_list(e
, nce
);
474 static int config_parse_usec(
475 const char *filename
,
491 if ((r
= parse_usec(rvalue
, usec
)) < 0) {
492 log_error("[%s:%u] Failed to parse time value: %s", filename
, line
, rvalue
);
499 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
500 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
502 static int config_parse_bindtodevice(
503 const char *filename
,
519 if (rvalue
[0] && !streq(rvalue
, "*")) {
520 if (!(n
= strdup(rvalue
)))
525 free(s
->bind_to_device
);
526 s
->bind_to_device
= n
;
531 DEFINE_CONFIG_PARSE_ENUM(config_parse_output
, exec_output
, ExecOutput
, "Failed to parse output specifier");
532 DEFINE_CONFIG_PARSE_ENUM(config_parse_input
, exec_input
, ExecInput
, "Failed to parse input specifier");
534 static int config_parse_facility(
535 const char *filename
,
551 if ((x
= log_facility_from_string(rvalue
)) < 0) {
552 log_error("[%s:%u] Failed to parse log facility: %s", filename
, line
, rvalue
);
556 *o
= LOG_MAKEPRI(x
, LOG_PRI(*o
));
561 static int config_parse_level(
562 const char *filename
,
578 if ((x
= log_level_from_string(rvalue
)) < 0) {
579 log_error("[%s:%u] Failed to parse log level: %s", filename
, line
, rvalue
);
583 *o
= LOG_MAKEPRI(LOG_FAC(*o
), x
);
587 static int config_parse_io_class(
588 const char *filename
,
596 ExecContext
*c
= data
;
604 if ((x
= ioprio_class_from_string(rvalue
)) < 0) {
605 log_error("[%s:%u] Failed to parse IO scheduling class: %s", filename
, line
, rvalue
);
609 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
610 c
->ioprio_set
= true;
615 static int config_parse_io_priority(
616 const char *filename
,
624 ExecContext
*c
= data
;
632 if (safe_atoi(rvalue
, &i
) < 0 || i
< 0 || i
>= IOPRIO_BE_NR
) {
633 log_error("[%s:%u] Failed to parse io priority: %s", filename
, line
, rvalue
);
637 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
638 c
->ioprio_set
= true;
643 static int config_parse_cpu_sched_policy(
644 const char *filename
,
653 ExecContext
*c
= data
;
661 if ((x
= sched_policy_from_string(rvalue
)) < 0) {
662 log_error("[%s:%u] Failed to parse CPU scheduling policy: %s", filename
, line
, rvalue
);
666 c
->cpu_sched_policy
= x
;
667 c
->cpu_sched_set
= true;
672 static int config_parse_cpu_sched_prio(
673 const char *filename
,
681 ExecContext
*c
= data
;
689 /* On Linux RR/FIFO have the same range */
690 if (safe_atoi(rvalue
, &i
) < 0 || i
< sched_get_priority_min(SCHED_RR
) || i
> sched_get_priority_max(SCHED_RR
)) {
691 log_error("[%s:%u] Failed to parse CPU scheduling priority: %s", filename
, line
, rvalue
);
695 c
->cpu_sched_priority
= i
;
696 c
->cpu_sched_set
= true;
701 static int config_parse_cpu_affinity(
702 const char *filename
,
710 ExecContext
*c
= data
;
720 FOREACH_WORD(w
, l
, rvalue
, state
) {
725 if (!(t
= strndup(w
, l
)))
729 if (!(c
->cpuset
= cpu_set_malloc(&c
->cpuset_ncpus
)))
732 r
= safe_atou(t
, &cpu
);
735 if (r
< 0 || cpu
>= c
->cpuset_ncpus
) {
736 log_error("[%s:%u] Failed to parse CPU affinity: %s", filename
, line
, rvalue
);
740 CPU_SET_S(cpu
, CPU_ALLOC_SIZE(c
->cpuset_ncpus
), c
->cpuset
);
746 static int config_parse_capabilities(
747 const char *filename
,
755 ExecContext
*c
= data
;
763 if (!(cap
= cap_from_text(rvalue
))) {
767 log_error("[%s:%u] Failed to parse capabilities: %s", filename
, line
, rvalue
);
772 cap_free(c
->capabilities
);
773 c
->capabilities
= cap
;
778 static int config_parse_secure_bits(
779 const char *filename
,
787 ExecContext
*c
= data
;
797 FOREACH_WORD(w
, l
, rvalue
, state
) {
798 if (first_word(w
, "keep-caps"))
799 c
->secure_bits
|= SECURE_KEEP_CAPS
;
800 else if (first_word(w
, "keep-caps-locked"))
801 c
->secure_bits
|= SECURE_KEEP_CAPS_LOCKED
;
802 else if (first_word(w
, "no-setuid-fixup"))
803 c
->secure_bits
|= SECURE_NO_SETUID_FIXUP
;
804 else if (first_word(w
, "no-setuid-fixup-locked"))
805 c
->secure_bits
|= SECURE_NO_SETUID_FIXUP_LOCKED
;
806 else if (first_word(w
, "noroot"))
807 c
->secure_bits
|= SECURE_NOROOT
;
808 else if (first_word(w
, "noroot-locked"))
809 c
->secure_bits
|= SECURE_NOROOT_LOCKED
;
811 log_error("[%s:%u] Failed to parse secure bits: %s", filename
, line
, rvalue
);
819 static int config_parse_bounding_set(
820 const char *filename
,
828 ExecContext
*c
= data
;
838 FOREACH_WORD(w
, l
, rvalue
, state
) {
843 if (!(t
= strndup(w
, l
)))
846 r
= cap_from_name(t
, &cap
);
850 log_error("[%s:%u] Failed to parse capability bounding set: %s", filename
, line
, rvalue
);
854 c
->capability_bounding_set_drop
|= 1 << cap
;
860 static int config_parse_timer_slack_nsec(
861 const char *filename
,
869 ExecContext
*c
= data
;
878 if ((r
= safe_atolu(rvalue
, &u
)) < 0) {
879 log_error("[%s:%u] Failed to parse time slack value: %s", filename
, line
, rvalue
);
883 c
->timer_slack_nsec
= u
;
888 static int config_parse_limit(
889 const char *filename
,
897 struct rlimit
**rl
= data
;
898 unsigned long long u
;
906 if ((r
= safe_atollu(rvalue
, &u
)) < 0) {
907 log_error("[%s:%u] Failed to parse resource value: %s", filename
, line
, rvalue
);
912 if (!(*rl
= new(struct rlimit
, 1)))
915 (*rl
)->rlim_cur
= (*rl
)->rlim_max
= (rlim_t
) u
;
919 static int config_parse_cgroup(
920 const char *filename
,
933 FOREACH_WORD(w
, l
, rvalue
, state
) {
937 if (!(t
= strndup(w
, l
)))
940 r
= unit_add_cgroup_from_text(u
, t
);
950 static int config_parse_sysv_priority(
951 const char *filename
,
959 int *priority
= data
;
967 if ((r
= safe_atoi(rvalue
, &i
)) < 0 || i
< 0) {
968 log_error("[%s:%u] Failed to parse SysV start priority: %s", filename
, line
, rvalue
);
976 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
978 static int config_parse_mount_flags(
979 const char *filename
,
987 ExecContext
*c
= data
;
991 unsigned long flags
= 0;
998 FOREACH_WORD(w
, l
, rvalue
, state
) {
999 if (strncmp(w
, "shared", l
) == 0)
1001 else if (strncmp(w
, "slave", l
) == 0)
1003 else if (strncmp(w
, "private", l
) == 0)
1004 flags
|= MS_PRIVATE
;
1006 log_error("[%s:%u] Failed to parse mount flags: %s", filename
, line
, rvalue
);
1011 c
->mount_flags
= flags
;
1015 static int config_parse_timer(
1016 const char *filename
,
1018 const char *section
,
1035 if ((b
= timer_base_from_string(lvalue
)) < 0) {
1036 log_error("[%s:%u] Failed to parse timer base: %s", filename
, line
, lvalue
);
1040 if ((r
= parse_usec(rvalue
, &u
)) < 0) {
1041 log_error("[%s:%u] Failed to parse timer value: %s", filename
, line
, rvalue
);
1045 if (!(v
= new0(TimerValue
, 1)))
1051 LIST_PREPEND(TimerValue
, value
, t
->values
, v
);
1056 static int config_parse_timer_unit(
1057 const char *filename
,
1059 const char *section
,
1068 if (endswith(rvalue
, ".timer")) {
1069 log_error("[%s:%u] Unit cannot be of type timer: %s", filename
, line
, rvalue
);
1073 if ((r
= manager_load_unit(t
->meta
.manager
, rvalue
, NULL
, &t
->unit
)) < 0) {
1074 log_error("[%s:%u] Failed to load unit: %s", filename
, line
, rvalue
);
1081 static int config_parse_path_spec(
1082 const char *filename
,
1084 const char *section
,
1099 if ((b
= path_type_from_string(lvalue
)) < 0) {
1100 log_error("[%s:%u] Failed to parse path type: %s", filename
, line
, lvalue
);
1104 if (!path_is_absolute(rvalue
)) {
1105 log_error("[%s:%u] Path is not absolute: %s", filename
, line
, rvalue
);
1109 if (!(s
= new0(PathSpec
, 1)))
1112 if (!(s
->path
= strdup(rvalue
))) {
1117 path_kill_slashes(s
->path
);
1122 LIST_PREPEND(PathSpec
, spec
, p
->specs
, s
);
1127 static int config_parse_path_unit(
1128 const char *filename
,
1130 const char *section
,
1139 if (endswith(rvalue
, ".path")) {
1140 log_error("[%s:%u] Unit cannot be of type path: %s", filename
, line
, rvalue
);
1144 if ((r
= manager_load_unit(t
->meta
.manager
, rvalue
, NULL
, &t
->unit
)) < 0) {
1145 log_error("[%s:%u] Failed to load unit: %s", filename
, line
, rvalue
);
1152 static int config_parse_env_file(
1153 const char *filename
,
1155 const char *section
,
1170 if (!(f
= fopen(rvalue
, "re"))) {
1171 log_error("[%s:%u] Failed to open environment file '%s': %m", filename
, line
, rvalue
);
1176 char l
[LINE_MAX
], *p
;
1179 if (!fgets(l
, sizeof(l
), f
)) {
1184 log_error("[%s:%u] Failed to read environment file '%s': %m", filename
, line
, rvalue
);
1193 if (strchr(COMMENTS
, *p
))
1196 t
= strv_env_set(*env
, p
);
1210 static int config_parse_ip_tos(
1211 const char *filename
,
1213 const char *section
,
1219 int *ip_tos
= data
, x
;
1227 if ((x
= ip_tos_from_string(rvalue
)) < 0)
1228 if ((r
= safe_atoi(rvalue
, &x
)) < 0) {
1229 log_error("[%s:%u] Failed to parse IP TOS value: %s", filename
, line
, rvalue
);
1237 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
1239 #define FOLLOW_MAX 8
1241 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
1252 /* This will update the filename pointer if the loaded file is
1253 * reached by a symlink. The old string will be freed. */
1256 char *target
, *name
;
1258 if (c
++ >= FOLLOW_MAX
)
1261 path_kill_slashes(*filename
);
1263 /* Add the file name we are currently looking at to
1264 * the names of this unit */
1265 name
= file_name_from_path(*filename
);
1266 if (!(id
= set_get(names
, name
))) {
1268 if (!(id
= strdup(name
)))
1271 if ((r
= set_put(names
, id
)) < 0) {
1277 /* Try to open the file name, but don't if its a symlink */
1278 if ((fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
)) >= 0)
1284 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
1285 if ((r
= readlink_and_make_absolute(*filename
, &target
)) < 0)
1292 if (!(f
= fdopen(fd
, "r"))) {
1294 close_nointr_nofail(fd
);
1303 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
1311 /* Let's try to add in all symlink names we found */
1312 while ((k
= set_steal_first(names
))) {
1314 /* First try to merge in the other name into our
1316 if ((r
= unit_merge_by_name(*u
, k
)) < 0) {
1319 /* Hmm, we couldn't merge the other unit into
1320 * ours? Then let's try it the other way
1323 other
= manager_get_unit((*u
)->meta
.manager
, k
);
1327 if ((r
= unit_merge(other
, *u
)) >= 0) {
1329 return merge_by_names(u
, names
, NULL
);
1336 unit_choose_id(*u
, id
);
1344 static void dump_items(FILE *f
, const ConfigItem
*items
) {
1345 const ConfigItem
*i
;
1346 const char *prev_section
= NULL
;
1347 bool not_first
= false;
1350 ConfigParserCallback callback
;
1353 { config_parse_int
, "INTEGER" },
1354 { config_parse_unsigned
, "UNSIGNED" },
1355 { config_parse_size
, "SIZE" },
1356 { config_parse_bool
, "BOOLEAN" },
1357 { config_parse_string
, "STRING" },
1358 { config_parse_path
, "PATH" },
1359 { config_parse_strv
, "STRING [...]" },
1360 { config_parse_nice
, "NICE" },
1361 { config_parse_oom_adjust
, "OOMADJUST" },
1362 { config_parse_io_class
, "IOCLASS" },
1363 { config_parse_io_priority
, "IOPRIORITY" },
1364 { config_parse_cpu_sched_policy
, "CPUSCHEDPOLICY" },
1365 { config_parse_cpu_sched_prio
, "CPUSCHEDPRIO" },
1366 { config_parse_cpu_affinity
, "CPUAFFINITY" },
1367 { config_parse_mode
, "MODE" },
1368 { config_parse_env_file
, "FILE" },
1369 { config_parse_output
, "OUTPUT" },
1370 { config_parse_input
, "INPUT" },
1371 { config_parse_facility
, "FACILITY" },
1372 { config_parse_level
, "LEVEL" },
1373 { config_parse_capabilities
, "CAPABILITIES" },
1374 { config_parse_secure_bits
, "SECUREBITS" },
1375 { config_parse_bounding_set
, "BOUNDINGSET" },
1376 { config_parse_timer_slack_nsec
, "TIMERSLACK" },
1377 { config_parse_limit
, "LIMIT" },
1378 { config_parse_cgroup
, "CGROUP [...]" },
1379 { config_parse_deps
, "UNIT [...]" },
1380 { config_parse_names
, "UNIT [...]" },
1381 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
1382 { config_parse_service_type
, "SERVICETYPE" },
1383 { config_parse_service_restart
, "SERVICERESTART" },
1384 { config_parse_sysv_priority
, "SYSVPRIORITY" },
1385 { config_parse_kill_mode
, "KILLMODE" },
1386 { config_parse_listen
, "SOCKET [...]" },
1387 { config_parse_socket_bind
, "SOCKETBIND" },
1388 { config_parse_bindtodevice
, "NETWORKINTERFACE" },
1389 { config_parse_usec
, "SECONDS" },
1390 { config_parse_path_strv
, "PATH [...]" },
1391 { config_parse_mount_flags
, "MOUNTFLAG [...]" },
1392 { config_parse_string_printf
, "STRING" },
1393 { config_parse_timer
, "TIMER" },
1394 { config_parse_timer_unit
, "NAME" },
1395 { config_parse_path_spec
, "PATH" },
1396 { config_parse_path_unit
, "UNIT" },
1397 { config_parse_notify_access
, "ACCESS" },
1398 { config_parse_ip_tos
, "TOS" },
1404 for (i
= items
; i
->lvalue
; i
++) {
1406 const char *rvalue
= "OTHER";
1408 if (!streq_ptr(i
->section
, prev_section
)) {
1414 fprintf(f
, "[%s]\n", i
->section
);
1415 prev_section
= i
->section
;
1418 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
1419 if (i
->parse
== table
[j
].callback
) {
1420 rvalue
= table
[j
].rvalue
;
1424 fprintf(f
, "%s=%s\n", i
->lvalue
, rvalue
);
1428 static int load_from_path(Unit
*u
, const char *path
) {
1430 static const char* const section_table
[_UNIT_TYPE_MAX
] = {
1431 [UNIT_SERVICE
] = "Service",
1432 [UNIT_TIMER
] = "Timer",
1433 [UNIT_SOCKET
] = "Socket",
1434 [UNIT_TARGET
] = "Target",
1435 [UNIT_DEVICE
] = "Device",
1436 [UNIT_MOUNT
] = "Mount",
1437 [UNIT_AUTOMOUNT
] = "Automount",
1438 [UNIT_SNAPSHOT
] = "Snapshot",
1439 [UNIT_SWAP
] = "Swap",
1440 [UNIT_PATH
] = "Path"
1443 #define EXEC_CONTEXT_CONFIG_ITEMS(context, section) \
1444 { "WorkingDirectory", config_parse_path, &(context).working_directory, section }, \
1445 { "RootDirectory", config_parse_path, &(context).root_directory, section }, \
1446 { "User", config_parse_string_printf, &(context).user, section }, \
1447 { "Group", config_parse_string_printf, &(context).group, section }, \
1448 { "SupplementaryGroups", config_parse_strv, &(context).supplementary_groups, section }, \
1449 { "Nice", config_parse_nice, &(context), section }, \
1450 { "OOMAdjust", config_parse_oom_adjust, &(context), section }, \
1451 { "IOSchedulingClass", config_parse_io_class, &(context), section }, \
1452 { "IOSchedulingPriority", config_parse_io_priority, &(context), section }, \
1453 { "CPUSchedulingPolicy", config_parse_cpu_sched_policy,&(context), section }, \
1454 { "CPUSchedulingPriority", config_parse_cpu_sched_prio, &(context), section }, \
1455 { "CPUSchedulingResetOnFork", config_parse_bool, &(context).cpu_sched_reset_on_fork, section }, \
1456 { "CPUAffinity", config_parse_cpu_affinity, &(context), section }, \
1457 { "UMask", config_parse_mode, &(context).umask, section }, \
1458 { "Environment", config_parse_strv, &(context).environment, section }, \
1459 { "EnvironmentFile", config_parse_env_file, &(context).environment, section }, \
1460 { "StandardInput", config_parse_input, &(context).std_input, section }, \
1461 { "StandardOutput", config_parse_output, &(context).std_output, section }, \
1462 { "StandardError", config_parse_output, &(context).std_error, section }, \
1463 { "TTYPath", config_parse_path, &(context).tty_path, section }, \
1464 { "SyslogIdentifier", config_parse_string_printf, &(context).syslog_identifier, section }, \
1465 { "SyslogFacility", config_parse_facility, &(context).syslog_priority, section }, \
1466 { "SyslogLevel", config_parse_level, &(context).syslog_priority, section }, \
1467 { "SyslogLevelPrefix", config_parse_bool, &(context).syslog_level_prefix, section }, \
1468 { "Capabilities", config_parse_capabilities, &(context), section }, \
1469 { "SecureBits", config_parse_secure_bits, &(context), section }, \
1470 { "CapabilityBoundingSetDrop", config_parse_bounding_set, &(context), section }, \
1471 { "TimerSlackNSec", config_parse_timer_slack_nsec,&(context), section }, \
1472 { "LimitCPU", config_parse_limit, &(context).rlimit[RLIMIT_CPU], section }, \
1473 { "LimitFSIZE", config_parse_limit, &(context).rlimit[RLIMIT_FSIZE], section }, \
1474 { "LimitDATA", config_parse_limit, &(context).rlimit[RLIMIT_DATA], section }, \
1475 { "LimitSTACK", config_parse_limit, &(context).rlimit[RLIMIT_STACK], section }, \
1476 { "LimitCORE", config_parse_limit, &(context).rlimit[RLIMIT_CORE], section }, \
1477 { "LimitRSS", config_parse_limit, &(context).rlimit[RLIMIT_RSS], section }, \
1478 { "LimitNOFILE", config_parse_limit, &(context).rlimit[RLIMIT_NOFILE], section }, \
1479 { "LimitAS", config_parse_limit, &(context).rlimit[RLIMIT_AS], section }, \
1480 { "LimitNPROC", config_parse_limit, &(context).rlimit[RLIMIT_NPROC], section }, \
1481 { "LimitMEMLOCK", config_parse_limit, &(context).rlimit[RLIMIT_MEMLOCK], section }, \
1482 { "LimitLOCKS", config_parse_limit, &(context).rlimit[RLIMIT_LOCKS], section }, \
1483 { "LimitSIGPENDING", config_parse_limit, &(context).rlimit[RLIMIT_SIGPENDING], section }, \
1484 { "LimitMSGQUEUE", config_parse_limit, &(context).rlimit[RLIMIT_MSGQUEUE], section }, \
1485 { "LimitNICE", config_parse_limit, &(context).rlimit[RLIMIT_NICE], section }, \
1486 { "LimitRTPRIO", config_parse_limit, &(context).rlimit[RLIMIT_RTPRIO], section }, \
1487 { "LimitRTTIME", config_parse_limit, &(context).rlimit[RLIMIT_RTTIME], section }, \
1488 { "ControlGroup", config_parse_cgroup, u, section }, \
1489 { "ReadWriteDirectories", config_parse_path_strv, &(context).read_write_dirs, section }, \
1490 { "ReadOnlyDirectories", config_parse_path_strv, &(context).read_only_dirs, section }, \
1491 { "InaccessibleDirectories",config_parse_path_strv, &(context).inaccessible_dirs, section }, \
1492 { "PrivateTmp", config_parse_bool, &(context).private_tmp, section }, \
1493 { "MountFlags", config_parse_mount_flags, &(context), section }, \
1494 { "TCPWrapName", config_parse_string_printf, &(context).tcpwrap_name, section }, \
1495 { "PAMName", config_parse_string_printf, &(context).pam_name, section }
1497 const ConfigItem items
[] = {
1498 { "Names", config_parse_names
, u
, "Unit" },
1499 { "Description", config_parse_string_printf
, &u
->meta
.description
, "Unit" },
1500 { "Requires", config_parse_deps
, UINT_TO_PTR(UNIT_REQUIRES
), "Unit" },
1501 { "RequiresOverridable", config_parse_deps
, UINT_TO_PTR(UNIT_REQUIRES_OVERRIDABLE
), "Unit" },
1502 { "Requisite", config_parse_deps
, UINT_TO_PTR(UNIT_REQUISITE
), "Unit" },
1503 { "RequisiteOverridable", config_parse_deps
, UINT_TO_PTR(UNIT_REQUISITE_OVERRIDABLE
), "Unit" },
1504 { "Wants", config_parse_deps
, UINT_TO_PTR(UNIT_WANTS
), "Unit" },
1505 { "Conflicts", config_parse_deps
, UINT_TO_PTR(UNIT_CONFLICTS
), "Unit" },
1506 { "Before", config_parse_deps
, UINT_TO_PTR(UNIT_BEFORE
), "Unit" },
1507 { "After", config_parse_deps
, UINT_TO_PTR(UNIT_AFTER
), "Unit" },
1508 { "RecursiveStop", config_parse_bool
, &u
->meta
.recursive_stop
, "Unit" },
1509 { "StopWhenUnneeded", config_parse_bool
, &u
->meta
.stop_when_unneeded
, "Unit" },
1510 { "OnlyByDependency", config_parse_bool
, &u
->meta
.only_by_dependency
, "Unit" },
1511 { "DefaultDependencies", config_parse_bool
, &u
->meta
.default_dependencies
, "Unit" },
1513 { "PIDFile", config_parse_path
, &u
->service
.pid_file
, "Service" },
1514 { "ExecStartPre", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START_PRE
, "Service" },
1515 { "ExecStart", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START
, "Service" },
1516 { "ExecStartPost", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START_POST
, "Service" },
1517 { "ExecReload", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_RELOAD
, "Service" },
1518 { "ExecStop", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_STOP
, "Service" },
1519 { "ExecStopPost", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_STOP_POST
, "Service" },
1520 { "RestartSec", config_parse_usec
, &u
->service
.restart_usec
, "Service" },
1521 { "TimeoutSec", config_parse_usec
, &u
->service
.timeout_usec
, "Service" },
1522 { "Type", config_parse_service_type
, &u
->service
.type
, "Service" },
1523 { "Restart", config_parse_service_restart
, &u
->service
.restart
, "Service" },
1524 { "PermissionsStartOnly", config_parse_bool
, &u
->service
.permissions_start_only
, "Service" },
1525 { "RootDirectoryStartOnly", config_parse_bool
, &u
->service
.root_directory_start_only
, "Service" },
1526 { "ValidNoProcess", config_parse_bool
, &u
->service
.valid_no_process
, "Service" },
1527 { "SysVStartPriority", config_parse_sysv_priority
, &u
->service
.sysv_start_priority
, "Service" },
1528 { "KillMode", config_parse_kill_mode
, &u
->service
.kill_mode
, "Service" },
1529 { "NonBlocking", config_parse_bool
, &u
->service
.exec_context
.non_blocking
, "Service" },
1530 { "BusName", config_parse_string_printf
, &u
->service
.bus_name
, "Service" },
1531 { "NotifyAccess", config_parse_notify_access
, &u
->service
.notify_access
, "Service" },
1532 EXEC_CONTEXT_CONFIG_ITEMS(u
->service
.exec_context
, "Service"),
1534 { "ListenStream", config_parse_listen
, &u
->socket
, "Socket" },
1535 { "ListenDatagram", config_parse_listen
, &u
->socket
, "Socket" },
1536 { "ListenSequentialPacket", config_parse_listen
, &u
->socket
, "Socket" },
1537 { "ListenFIFO", config_parse_listen
, &u
->socket
, "Socket" },
1538 { "BindIPv6Only", config_parse_socket_bind
, &u
->socket
, "Socket" },
1539 { "Backlog", config_parse_unsigned
, &u
->socket
.backlog
, "Socket" },
1540 { "BindToDevice", config_parse_bindtodevice
, &u
->socket
, "Socket" },
1541 { "ExecStartPre", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_START_PRE
, "Socket" },
1542 { "ExecStartPost", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_START_POST
, "Socket" },
1543 { "ExecStopPre", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_STOP_PRE
, "Socket" },
1544 { "ExecStopPost", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_STOP_POST
, "Socket" },
1545 { "TimeoutSec", config_parse_usec
, &u
->socket
.timeout_usec
, "Socket" },
1546 { "DirectoryMode", config_parse_mode
, &u
->socket
.directory_mode
, "Socket" },
1547 { "SocketMode", config_parse_mode
, &u
->socket
.socket_mode
, "Socket" },
1548 { "KillMode", config_parse_kill_mode
, &u
->socket
.kill_mode
, "Socket" },
1549 { "Accept", config_parse_bool
, &u
->socket
.accept
, "Socket" },
1550 { "MaxConnections", config_parse_unsigned
, &u
->socket
.max_connections
, "Socket" },
1551 { "KeepAlive", config_parse_bool
, &u
->socket
.keep_alive
, "Socket" },
1552 { "Priority", config_parse_int
, &u
->socket
.priority
, "Socket" },
1553 { "ReceiveBuffer", config_parse_size
, &u
->socket
.receive_buffer
, "Socket" },
1554 { "SendBuffer", config_parse_size
, &u
->socket
.send_buffer
, "Socket" },
1555 { "IPTOS", config_parse_ip_tos
, &u
->socket
.ip_tos
, "Socket" },
1556 { "IPTTL", config_parse_int
, &u
->socket
.ip_ttl
, "Socket" },
1557 { "Mark", config_parse_int
, &u
->socket
.mark
, "Socket" },
1558 { "PipeSize", config_parse_size
, &u
->socket
.pipe_size
, "Socket" },
1559 { "FreeBind", config_parse_bool
, &u
->socket
.free_bind
, "Socket" },
1560 EXEC_CONTEXT_CONFIG_ITEMS(u
->socket
.exec_context
, "Socket"),
1562 { "What", config_parse_string
, &u
->mount
.parameters_fragment
.what
, "Mount" },
1563 { "Where", config_parse_path
, &u
->mount
.where
, "Mount" },
1564 { "Options", config_parse_string
, &u
->mount
.parameters_fragment
.options
, "Mount" },
1565 { "Type", config_parse_string
, &u
->mount
.parameters_fragment
.fstype
, "Mount" },
1566 { "TimeoutSec", config_parse_usec
, &u
->mount
.timeout_usec
, "Mount" },
1567 { "KillMode", config_parse_kill_mode
, &u
->mount
.kill_mode
, "Mount" },
1568 { "DirectoryMode", config_parse_mode
, &u
->mount
.directory_mode
, "Mount" },
1569 EXEC_CONTEXT_CONFIG_ITEMS(u
->mount
.exec_context
, "Mount"),
1571 { "Where", config_parse_path
, &u
->automount
.where
, "Automount" },
1572 { "DirectoryMode", config_parse_mode
, &u
->automount
.directory_mode
, "Automount" },
1574 { "What", config_parse_path
, &u
->swap
.parameters_fragment
.what
, "Swap" },
1575 { "Priority", config_parse_int
, &u
->swap
.parameters_fragment
.priority
, "Swap" },
1577 { "OnActiveSec", config_parse_timer
, &u
->timer
, "Timer" },
1578 { "OnBootSec", config_parse_timer
, &u
->timer
, "Timer" },
1579 { "OnStartupSec", config_parse_timer
, &u
->timer
, "Timer" },
1580 { "OnUnitActiveSec", config_parse_timer
, &u
->timer
, "Timer" },
1581 { "OnUnitInactiveSec", config_parse_timer
, &u
->timer
, "Timer" },
1582 { "Unit", config_parse_timer_unit
, &u
->timer
, "Timer" },
1584 { "PathExists", config_parse_path_spec
, &u
->path
, "Path" },
1585 { "PathChanged", config_parse_path_spec
, &u
->path
, "Path" },
1586 { "DirectoryNotEmpty", config_parse_path_spec
, &u
->path
, "Path" },
1587 { "Unit", config_parse_path_unit
, &u
->path
, "Path" },
1589 /* The [Install] section is ignored here. */
1590 { "Alias", NULL
, NULL
, "Install" },
1591 { "WantedBy", NULL
, NULL
, "Install" },
1592 { "Also", NULL
, NULL
, "Install" },
1594 { NULL
, NULL
, NULL
, NULL
}
1597 #undef EXEC_CONTEXT_CONFIG_ITEMS
1599 const char *sections
[4];
1603 char *filename
= NULL
, *id
= NULL
;
1607 /* Dirty dirty hack. */
1608 dump_items((FILE*) path
, items
);
1615 sections
[0] = "Unit";
1616 sections
[1] = section_table
[u
->meta
.type
];
1617 sections
[2] = "Install";
1620 if (!(symlink_names
= set_new(string_hash_func
, string_compare_func
)))
1623 if (path_is_absolute(path
)) {
1625 if (!(filename
= strdup(path
))) {
1630 if ((r
= open_follow(&filename
, &f
, symlink_names
, &id
)) < 0) {
1641 STRV_FOREACH(p
, u
->meta
.manager
->lookup_paths
.unit_path
) {
1643 /* Instead of opening the path right away, we manually
1644 * follow all symlinks and add their name to our unit
1645 * name set while doing so */
1646 if (!(filename
= path_make_absolute(path
, *p
))) {
1651 if ((r
= open_follow(&filename
, &f
, symlink_names
, &id
)) < 0) {
1660 /* Empty the symlink names for the next run */
1661 while ((sn
= set_steal_first(symlink_names
)))
1677 if ((r
= merge_by_names(&merged
, symlink_names
, id
)) < 0)
1681 u
->meta
.load_state
= UNIT_MERGED
;
1686 /* Now, parse the file contents */
1687 if ((r
= config_parse(filename
, f
, sections
, items
, false, u
)) < 0)
1690 free(u
->meta
.fragment_path
);
1691 u
->meta
.fragment_path
= filename
;
1694 u
->meta
.load_state
= UNIT_LOADED
;
1698 set_free_free(symlink_names
);
1707 int unit_load_fragment(Unit
*u
) {
1712 if (u
->meta
.fragment_path
) {
1714 if ((r
= load_from_path(u
, u
->meta
.fragment_path
)) < 0)
1721 /* Try to find the unit under its id */
1722 if ((r
= load_from_path(u
, u
->meta
.id
)) < 0)
1725 /* Try to find an alias we can load this with */
1726 if (u
->meta
.load_state
== UNIT_STUB
)
1727 SET_FOREACH(t
, u
->meta
.names
, i
) {
1729 if (t
== u
->meta
.id
)
1732 if ((r
= load_from_path(u
, t
)) < 0)
1735 if (u
->meta
.load_state
!= UNIT_STUB
)
1739 /* Now, follow the same logic, but look for a template */
1740 if (u
->meta
.load_state
== UNIT_STUB
&& u
->meta
.instance
) {
1743 if (!(k
= unit_name_template(u
->meta
.id
)))
1746 r
= load_from_path(u
, k
);
1752 if (u
->meta
.load_state
== UNIT_STUB
)
1753 SET_FOREACH(t
, u
->meta
.names
, i
) {
1755 if (t
== u
->meta
.id
)
1758 if (!(k
= unit_name_template(t
)))
1761 r
= load_from_path(u
, k
);
1767 if (u
->meta
.load_state
!= UNIT_STUB
)
1776 void unit_dump_config_items(FILE *f
) {
1777 /* OK, this wins a prize for extreme ugliness. */
1779 load_from_path(NULL
, (const void*) f
);