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 #define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \
41 static int function( \
42 const char *filename, \
44 const char *section, \
57 if ((x = name##_from_string(rvalue)) < 0) { \
58 log_error("[%s:%u] " msg ": %s", filename, line, rvalue); \
67 static int config_parse_deps(
76 UnitDependency d = PTR_TO_UINT(data);
86 if (UNIT_VTABLE(u)->refuse_requires &&
87 (d == UNIT_REQUIRES ||
88 d == UNIT_SOFT_REQUIRES ||
89 d == UNIT_REQUISITE ||
90 d == UNIT_SOFT_REQUISITE)) {
91 log_error("[%s:%u] Dependency of type %s not acceptable for this unit type.", filename, line, lvalue);
95 FOREACH_WORD(w, l, rvalue, state) {
99 if (!(t = strndup(w, l)))
102 r = unit_add_dependency_by_name(u, d, t);
112 static int config_parse_names(
113 const char *filename,
131 FOREACH_WORD(w, l, rvalue, state) {
135 if (!(t = strndup(w, l)))
138 r = unit_merge_by_name(u, t);
148 static int config_parse_listen(
149 const char *filename,
168 if (!(p = new0(SocketPort, 1)))
171 if (streq(lvalue, "ListenFIFO")) {
172 p->type = SOCKET_FIFO;
174 if (!(p->path = strdup(rvalue))) {
179 p->type = SOCKET_SOCKET;
181 if ((r = socket_address_parse(&p->address, rvalue)) < 0) {
182 log_error("[%s:%u] Failed to parse address value: %s", filename, line, rvalue);
187 if (streq(lvalue, "ListenStream"))
188 p->address.type = SOCK_STREAM;
189 else if (streq(lvalue, "ListenDatagram"))
190 p->address.type = SOCK_DGRAM;
192 assert(streq(lvalue, "ListenSequentialPacket"));
193 p->address.type = SOCK_SEQPACKET;
196 if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) {
198 return -EPROTONOSUPPORT;
203 LIST_PREPEND(SocketPort, port, s->ports, p);
208 static int config_parse_socket_bind(
209 const char *filename,
227 if ((r = parse_boolean(rvalue)) < 0) {
228 log_error("[%s:%u] Failed to parse bind IPv6 only value: %s", filename, line, rvalue);
232 s->bind_ipv6_only = r ? SOCKET_ADDRESS_IPV6_ONLY : SOCKET_ADDRESS_BOTH;
237 static int config_parse_nice(
238 const char *filename,
246 ExecContext *c = data;
254 if ((r = safe_atoi(rvalue, &priority)) < 0) {
255 log_error("[%s:%u] Failed to parse nice priority: %s", filename, line, rvalue);
259 if (priority < PRIO_MIN || priority >= PRIO_MAX) {
260 log_error("[%s:%u] Nice priority out of range: %s", filename, line, rvalue);
270 static int config_parse_oom_adjust(
271 const char *filename,
279 ExecContext *c = data;
287 if ((r = safe_atoi(rvalue, &oa)) < 0) {
288 log_error("[%s:%u] Failed to parse OOM adjust value: %s", filename, line, rvalue);
292 if (oa < OOM_DISABLE || oa > OOM_ADJUST_MAX) {
293 log_error("[%s:%u] OOM adjust value out of range: %s", filename, line, rvalue);
298 c->oom_adjust_set = true;
303 static int config_parse_mode(
304 const char *filename,
322 l = strtol(rvalue, &x, 8);
323 if (!x || *x || errno) {
324 log_error("[%s:%u] Failed to parse mode value: %s", filename, line, rvalue);
325 return errno ? -errno : -EINVAL;
328 if (l < 0000 || l > 07777) {
329 log_error("[%s:%u] mode value out of range: %s", filename, line, rvalue);
337 static int config_parse_exec(
338 const char *filename,
346 ExecCommand **e = data, *nce = NULL;
359 FOREACH_WORD_QUOTED(w, l, rvalue, state)
362 if (!(n = new(char*, k+1)))
366 FOREACH_WORD_QUOTED(w, l, rvalue, state)
367 if (!(n[k++] = strndup(w, l)))
372 if (!n[0] || !path_is_absolute(n[0])) {
373 log_error("[%s:%u] Invalid executable path in command line: %s", filename, line, rvalue);
378 if (!(nce = new0(ExecCommand, 1)))
382 if (!(nce->path = strdup(n[0])))
385 exec_command_append_list(e, nce);
399 static int config_parse_usec(
400 const char *filename,
409 unsigned long long u;
417 if ((r = safe_atollu(rvalue, &u)) < 0) {
418 log_error("[%s:%u] Failed to parse time value: %s", filename, line, rvalue);
422 /* We actually assume the user configures seconds. Later on we
423 * might choose to support suffixes for time values, to
424 * configure bigger or smaller units */
426 *usec = u * USEC_PER_SEC;
431 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type");
432 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier");
434 static int config_parse_bindtodevice(
435 const char *filename,
451 if (rvalue[0] && !streq(rvalue, "*")) {
452 if (!(n = strdup(rvalue)))
457 free(s->bind_to_device);
458 s->bind_to_device = n;
463 DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output specifier");
464 DEFINE_CONFIG_PARSE_ENUM(config_parse_input, exec_input, ExecInput, "Failed to parse input specifier");
466 static int config_parse_facility(
467 const char *filename,
483 if ((x = log_facility_from_string(rvalue)) < 0) {
484 log_error("[%s:%u] Failed to parse log facility: %s", filename, line, rvalue);
488 *o = LOG_MAKEPRI(x, LOG_PRI(*o));
493 static int config_parse_level(
494 const char *filename,
510 if ((x = log_level_from_string(rvalue)) < 0) {
511 log_error("[%s:%u] Failed to parse log level: %s", filename, line, rvalue);
515 *o = LOG_MAKEPRI(LOG_FAC(*o), x);
519 static int config_parse_io_class(
520 const char *filename,
528 ExecContext *c = data;
536 if ((x = ioprio_class_from_string(rvalue)) < 0) {
537 log_error("[%s:%u] Failed to parse IO scheduling class: %s", filename, line, rvalue);
541 c->ioprio = IOPRIO_PRIO_VALUE(x, IOPRIO_PRIO_DATA(c->ioprio));
542 c->ioprio_set = true;
547 static int config_parse_io_priority(
548 const char *filename,
556 ExecContext *c = data;
564 if (safe_atoi(rvalue, &i) < 0 || i < 0 || i >= IOPRIO_BE_NR) {
565 log_error("[%s:%u] Failed to parse io priority: %s", filename, line, rvalue);
569 c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), i);
570 c->ioprio_set = true;
575 static int config_parse_cpu_sched_policy(
576 const char *filename,
585 ExecContext *c = data;
593 if ((x = sched_policy_from_string(rvalue)) < 0) {
594 log_error("[%s:%u] Failed to parse CPU scheduling policy: %s", filename, line, rvalue);
598 c->cpu_sched_policy = x;
599 c->cpu_sched_set = true;
604 static int config_parse_cpu_sched_prio(
605 const char *filename,
613 ExecContext *c = data;
621 /* On Linux RR/FIFO have the same range */
622 if (safe_atoi(rvalue, &i) < 0 || i < sched_get_priority_min(SCHED_RR) || i > sched_get_priority_max(SCHED_RR)) {
623 log_error("[%s:%u] Failed to parse CPU scheduling priority: %s", filename, line, rvalue);
627 c->cpu_sched_priority = i;
628 c->cpu_sched_set = true;
633 static int config_parse_cpu_affinity(
634 const char *filename,
642 ExecContext *c = data;
652 FOREACH_WORD(w, l, rvalue, state) {
657 if (!(t = strndup(w, l)))
660 r = safe_atou(t, &cpu);
663 if (r < 0 || cpu >= CPU_SETSIZE) {
664 log_error("[%s:%u] Failed to parse CPU affinity: %s", filename, line, rvalue);
668 CPU_SET(cpu, &c->cpu_affinity);
671 c->cpu_affinity_set = true;
676 static int config_parse_capabilities(
677 const char *filename,
685 ExecContext *c = data;
693 if (!(cap = cap_from_text(rvalue))) {
697 log_error("[%s:%u] Failed to parse capabilities: %s", filename, line, rvalue);
702 cap_free(c->capabilities);
703 c->capabilities = cap;
708 static int config_parse_secure_bits(
709 const char *filename,
717 ExecContext *c = data;
727 FOREACH_WORD(w, l, rvalue, state) {
728 if (first_word(w, "keep-caps"))
729 c->secure_bits |= SECURE_KEEP_CAPS;
730 else if (first_word(w, "keep-caps-locked"))
731 c->secure_bits |= SECURE_KEEP_CAPS_LOCKED;
732 else if (first_word(w, "no-setuid-fixup"))
733 c->secure_bits |= SECURE_NO_SETUID_FIXUP;
734 else if (first_word(w, "no-setuid-fixup-locked"))
735 c->secure_bits |= SECURE_NO_SETUID_FIXUP_LOCKED;
736 else if (first_word(w, "noroot"))
737 c->secure_bits |= SECURE_NOROOT;
738 else if (first_word(w, "noroot-locked"))
739 c->secure_bits |= SECURE_NOROOT_LOCKED;
741 log_error("[%s:%u] Failed to parse secure bits: %s", filename, line, rvalue);
749 static int config_parse_bounding_set(
750 const char *filename,
758 ExecContext *c = data;
768 FOREACH_WORD(w, l, rvalue, state) {
773 if (!(t = strndup(w, l)))
776 r = cap_from_name(t, &cap);
780 log_error("[%s:%u] Failed to parse capability bounding set: %s", filename, line, rvalue);
784 c->capability_bounding_set_drop |= 1 << cap;
790 static int config_parse_timer_slack_ns(
791 const char *filename,
799 ExecContext *c = data;
808 if ((r = safe_atolu(rvalue, &u)) < 0) {
809 log_error("[%s:%u] Failed to parse time slack value: %s", filename, line, rvalue);
813 c->timer_slack_ns = u;
818 static int config_parse_limit(
819 const char *filename,
827 struct rlimit **rl = data;
828 unsigned long long u;
836 if ((r = safe_atollu(rvalue, &u)) < 0) {
837 log_error("[%s:%u] Failed to parse resource value: %s", filename, line, rvalue);
842 if (!(*rl = new(struct rlimit, 1)))
845 (*rl)->rlim_cur = (*rl)->rlim_max = (rlim_t) u;
849 static int config_parse_cgroup(
850 const char *filename,
863 FOREACH_WORD(w, l, rvalue, state) {
867 if (!(t = strndup(w, l)))
870 r = unit_add_cgroup_from_text(u, t);
880 static int config_parse_sysv_priority(
881 const char *filename,
889 int *priority = data;
897 if ((r = safe_atoi(rvalue, &i)) < 0 || i < 0) {
898 log_error("[%s:%u] Failed to parse SysV start priority: %s", filename, line, rvalue);
906 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode");
910 static int open_follow(char **filename, FILE **_f, Set *names, char **_id) {
921 /* This will update the filename pointer if the loaded file is
922 * reached by a symlink. The old string will be freed. */
925 char *target, *k, *name;
927 if (c++ >= FOLLOW_MAX)
930 path_kill_slashes(*filename);
932 /* Add the file name we are currently looking at to
933 * the names of this unit */
934 name = file_name_from_path(*filename);
935 if (!(id = set_get(names, name))) {
937 if (!(id = strdup(name)))
940 if ((r = set_put(names, id)) < 0) {
946 /* Try to open the file name, but don't if its a symlink */
947 if ((fd = open(*filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW)) >= 0)
953 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
954 if ((r = readlink_malloc(*filename, &target)) < 0)
957 k = file_in_same_dir(*filename, target);
967 if (!(f = fdopen(fd, "r"))) {
969 assert(close_nointr(fd) == 0);
978 static int merge_by_names(Unit **u, Set *names, const char *id) {
986 /* Let's try to add in all symlink names we found */
987 while ((k = set_steal_first(names))) {
989 /* First try to merge in the other name into our
991 if ((r = unit_merge_by_name(*u, k)) < 0) {
994 /* Hmm, we couldn't merge the other unit into
995 * ours? Then let's try it the other way
998 other = manager_get_unit((*u)->meta.manager, k);
1002 if ((r = unit_merge(other, *u)) >= 0) {
1004 return merge_by_names(u, names, NULL);
1011 unit_choose_id(*u, id);
1019 static void dump_items(FILE *f, const ConfigItem *items) {
1020 const ConfigItem *i;
1021 const char *prev_section = NULL;
1022 bool not_first = false;
1025 ConfigParserCallback callback;
1028 { config_parse_int, "INTEGER" },
1029 { config_parse_unsigned, "UNSIGNED" },
1030 { config_parse_size, "SIZE" },
1031 { config_parse_bool, "BOOLEAN" },
1032 { config_parse_string, "STRING" },
1033 { config_parse_path, "PATH" },
1034 { config_parse_strv, "STRING [...]" },
1035 { config_parse_nice, "NICE" },
1036 { config_parse_oom_adjust, "OOMADJUST" },
1037 { config_parse_io_class, "IOCLASS" },
1038 { config_parse_io_priority, "IOPRIORITY" },
1039 { config_parse_cpu_sched_policy, "CPUSCHEDPOLICY" },
1040 { config_parse_cpu_sched_prio, "CPUSCHEDPRIO" },
1041 { config_parse_cpu_affinity, "CPUAFFINITY" },
1042 { config_parse_mode, "MODE" },
1043 { config_parse_output, "OUTPUT" },
1044 { config_parse_input, "INPUT" },
1045 { config_parse_facility, "FACILITY" },
1046 { config_parse_level, "LEVEL" },
1047 { config_parse_capabilities, "CAPABILITIES" },
1048 { config_parse_secure_bits, "SECUREBITS" },
1049 { config_parse_bounding_set, "BOUNDINGSET" },
1050 { config_parse_timer_slack_ns, "TIMERSLACK" },
1051 { config_parse_limit, "LIMIT" },
1052 { config_parse_cgroup, "CGROUP [...]" },
1053 { config_parse_deps, "UNIT [...]" },
1054 { config_parse_names, "UNIT [...]" },
1055 { config_parse_exec, "PATH [ARGUMENT [...]]" },
1056 { config_parse_service_type, "SERVICETYPE" },
1057 { config_parse_service_restart, "SERVICERESTART" },
1058 { config_parse_sysv_priority, "SYSVPRIORITY" },
1059 { config_parse_kill_mode, "KILLMODE" },
1060 { config_parse_listen, "SOCKET [...]" },
1061 { config_parse_socket_bind, "SOCKETBIND" },
1062 { config_parse_bindtodevice, "NETWORKINTERFACE" }
1068 for (i = items; i->lvalue; i++) {
1070 const char *rvalue = "OTHER";
1072 if (!streq_ptr(i->section, prev_section)) {
1078 fprintf(f, "[%s]\n", i->section);
1079 prev_section = i->section;
1082 for (j = 0; j < ELEMENTSOF(table); j++)
1083 if (i->parse == table[j].callback) {
1084 rvalue = table[j].rvalue;
1088 fprintf(f, "%s=%s\n", i->lvalue, rvalue);
1092 static int load_from_path(Unit *u, const char *path) {
1094 static const char* const section_table[_UNIT_TYPE_MAX] = {
1095 [UNIT_SERVICE] = "Service",
1096 [UNIT_TIMER] = "Timer",
1097 [UNIT_SOCKET] = "Socket",
1098 [UNIT_TARGET] = "Target",
1099 [UNIT_DEVICE] = "Device",
1100 [UNIT_MOUNT] = "Mount",
1101 [UNIT_AUTOMOUNT] = "Automount",
1102 [UNIT_SNAPSHOT] = "Snapshot"
1105 #define EXEC_CONTEXT_CONFIG_ITEMS(context, section) \
1106 { "WorkingDirectory", config_parse_path, &(context).working_directory, section }, \
1107 { "RootDirectory", config_parse_path, &(context).root_directory, section }, \
1108 { "User", config_parse_string, &(context).user, section }, \
1109 { "Group", config_parse_string, &(context).group, section }, \
1110 { "SupplementaryGroups", config_parse_strv, &(context).supplementary_groups, section }, \
1111 { "Nice", config_parse_nice, &(context), section }, \
1112 { "OOMAdjust", config_parse_oom_adjust, &(context), section }, \
1113 { "IOSchedulingClass", config_parse_io_class, &(context), section }, \
1114 { "IOSchedulingPriority", config_parse_io_priority, &(context), section }, \
1115 { "CPUSchedulingPolicy", config_parse_cpu_sched_policy,&(context), section }, \
1116 { "CPUSchedulingPriority", config_parse_cpu_sched_prio, &(context), section }, \
1117 { "CPUSchedulingResetOnFork", config_parse_bool, &(context).cpu_sched_reset_on_fork, section }, \
1118 { "CPUAffinity", config_parse_cpu_affinity, &(context), section }, \
1119 { "UMask", config_parse_mode, &(context).umask, section }, \
1120 { "Environment", config_parse_strv, &(context).environment, section }, \
1121 { "StandardInput", config_parse_input, &(context).std_input, section }, \
1122 { "StandardOutput", config_parse_output, &(context).std_output, section }, \
1123 { "StandardError", config_parse_output, &(context).std_output, section }, \
1124 { "TTYPath", config_parse_path, &(context).tty_path, section }, \
1125 { "SyslogIdentifier", config_parse_string, &(context).syslog_identifier, section }, \
1126 { "SyslogFacility", config_parse_facility, &(context).syslog_priority, section }, \
1127 { "SyslogLevel", config_parse_level, &(context).syslog_priority, section }, \
1128 { "Capabilities", config_parse_capabilities, &(context), section }, \
1129 { "SecureBits", config_parse_secure_bits, &(context), section }, \
1130 { "CapabilityBoundingSetDrop", config_parse_bounding_set, &(context), section }, \
1131 { "TimerSlackNS", config_parse_timer_slack_ns, &(context), section }, \
1132 { "LimitCPU", config_parse_limit, &(context).rlimit[RLIMIT_CPU], section }, \
1133 { "LimitFSIZE", config_parse_limit, &(context).rlimit[RLIMIT_FSIZE], section }, \
1134 { "LimitDATA", config_parse_limit, &(context).rlimit[RLIMIT_DATA], section }, \
1135 { "LimitSTACK", config_parse_limit, &(context).rlimit[RLIMIT_STACK], section }, \
1136 { "LimitCORE", config_parse_limit, &(context).rlimit[RLIMIT_CORE], section }, \
1137 { "LimitRSS", config_parse_limit, &(context).rlimit[RLIMIT_RSS], section }, \
1138 { "LimitNOFILE", config_parse_limit, &(context).rlimit[RLIMIT_NOFILE], section }, \
1139 { "LimitAS", config_parse_limit, &(context).rlimit[RLIMIT_AS], section }, \
1140 { "LimitNPROC", config_parse_limit, &(context).rlimit[RLIMIT_NPROC], section }, \
1141 { "LimitMEMLOCK", config_parse_limit, &(context).rlimit[RLIMIT_MEMLOCK], section }, \
1142 { "LimitLOCKS", config_parse_limit, &(context).rlimit[RLIMIT_LOCKS], section }, \
1143 { "LimitSIGPENDING", config_parse_limit, &(context).rlimit[RLIMIT_SIGPENDING], section }, \
1144 { "LimitMSGQUEUE", config_parse_limit, &(context).rlimit[RLIMIT_MSGQUEUE], section }, \
1145 { "LimitNICE", config_parse_limit, &(context).rlimit[RLIMIT_NICE], section }, \
1146 { "LimitRTPRIO", config_parse_limit, &(context).rlimit[RLIMIT_RTPRIO], section }, \
1147 { "LimitRTTIME", config_parse_limit, &(context).rlimit[RLIMIT_RTTIME], section }, \
1148 { "ControlGroup", config_parse_cgroup, u, section }
1150 const ConfigItem items[] = {
1151 { "Names", config_parse_names, u, "Meta" },
1152 { "Description", config_parse_string, &u->meta.description, "Meta" },
1153 { "Requires", config_parse_deps, UINT_TO_PTR(UNIT_REQUIRES), "Meta" },
1154 { "SoftRequires", config_parse_deps, UINT_TO_PTR(UNIT_SOFT_REQUIRES), "Meta" },
1155 { "Wants", config_parse_deps, UINT_TO_PTR(UNIT_WANTS), "Meta" },
1156 { "Requisite", config_parse_deps, UINT_TO_PTR(UNIT_REQUISITE), "Meta" },
1157 { "SoftRequisite", config_parse_deps, UINT_TO_PTR(UNIT_SOFT_REQUISITE), "Meta" },
1158 { "Conflicts", config_parse_deps, UINT_TO_PTR(UNIT_CONFLICTS), "Meta" },
1159 { "Before", config_parse_deps, UINT_TO_PTR(UNIT_BEFORE), "Meta" },
1160 { "After", config_parse_deps, UINT_TO_PTR(UNIT_AFTER), "Meta" },
1161 { "RecursiveStop", config_parse_bool, &u->meta.recursive_stop, "Meta" },
1162 { "StopWhenUnneeded", config_parse_bool, &u->meta.stop_when_unneeded, "Meta" },
1164 { "PIDFile", config_parse_path, &u->service.pid_file, "Service" },
1165 { "ExecStartPre", config_parse_exec, u->service.exec_command+SERVICE_EXEC_START_PRE, "Service" },
1166 { "ExecStart", config_parse_exec, u->service.exec_command+SERVICE_EXEC_START, "Service" },
1167 { "ExecStartPost", config_parse_exec, u->service.exec_command+SERVICE_EXEC_START_POST, "Service" },
1168 { "ExecReload", config_parse_exec, u->service.exec_command+SERVICE_EXEC_RELOAD, "Service" },
1169 { "ExecStop", config_parse_exec, u->service.exec_command+SERVICE_EXEC_STOP, "Service" },
1170 { "ExecStopPost", config_parse_exec, u->service.exec_command+SERVICE_EXEC_STOP_POST, "Service" },
1171 { "RestartSec", config_parse_usec, &u->service.restart_usec, "Service" },
1172 { "TimeoutSec", config_parse_usec, &u->service.timeout_usec, "Service" },
1173 { "Type", config_parse_service_type, &u->service.type, "Service" },
1174 { "Restart", config_parse_service_restart, &u->service.restart, "Service" },
1175 { "PermissionsStartOnly", config_parse_bool, &u->service.permissions_start_only, "Service" },
1176 { "RootDirectoryStartOnly", config_parse_bool, &u->service.root_directory_start_only, "Service" },
1177 { "ValidNoProcess", config_parse_bool, &u->service.valid_no_process, "Service" },
1178 { "SysVStartPriority", config_parse_sysv_priority, &u->service.sysv_start_priority, "Service" },
1179 { "KillMode", config_parse_kill_mode, &u->service.kill_mode, "Service" },
1180 { "NonBlocking", config_parse_bool, &u->service.exec_context.non_blocking, "Service" },
1181 EXEC_CONTEXT_CONFIG_ITEMS(u->service.exec_context, "Service"),
1183 { "ListenStream", config_parse_listen, &u->socket, "Socket" },
1184 { "ListenDatagram", config_parse_listen, &u->socket, "Socket" },
1185 { "ListenSequentialPacket", config_parse_listen, &u->socket, "Socket" },
1186 { "ListenFIFO", config_parse_listen, &u->socket, "Socket" },
1187 { "BindIPv6Only", config_parse_socket_bind, &u->socket, "Socket" },
1188 { "Backlog", config_parse_unsigned, &u->socket.backlog, "Socket" },
1189 { "BindToDevice", config_parse_bindtodevice, &u->socket, "Socket" },
1190 { "ExecStartPre", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_START_PRE, "Socket" },
1191 { "ExecStartPost", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_START_POST, "Socket" },
1192 { "ExecStopPre", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_STOP_PRE, "Socket" },
1193 { "ExecStopPost", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_STOP_POST, "Socket" },
1194 { "TimeoutSec", config_parse_usec, &u->socket.timeout_usec, "Socket" },
1195 { "DirectoryMode", config_parse_mode, &u->socket.directory_mode, "Socket" },
1196 { "SocketMode", config_parse_mode, &u->socket.socket_mode, "Socket" },
1197 { "KillMode", config_parse_kill_mode, &u->socket.kill_mode, "Socket" },
1198 EXEC_CONTEXT_CONFIG_ITEMS(u->socket.exec_context, "Socket"),
1200 { "What", config_parse_string, &u->mount.parameters_fragment.what, "Mount" },
1201 { "Where", config_parse_path, &u->mount.where, "Mount" },
1202 { "Options", config_parse_string, &u->mount.parameters_fragment.options, "Mount" },
1203 { "Type", config_parse_string, &u->mount.parameters_fragment.fstype, "Mount" },
1204 { "TimeoutSec", config_parse_usec, &u->mount.timeout_usec, "Mount" },
1205 { "KillMode", config_parse_kill_mode, &u->mount.kill_mode, "Mount" },
1206 EXEC_CONTEXT_CONFIG_ITEMS(u->mount.exec_context, "Mount"),
1208 { NULL, NULL, NULL, NULL }
1211 #undef EXEC_CONTEXT_CONFIG_ITEMS
1213 const char *sections[3];
1218 char *filename = NULL, *id = NULL;
1222 /* Dirty dirty hack. */
1223 dump_items((FILE*) path, items);
1230 sections[0] = "Meta";
1231 sections[1] = section_table[u->meta.type];
1234 if (!(symlink_names = set_new(string_hash_func, string_compare_func)))
1237 if (path_is_absolute(path)) {
1239 if (!(filename = strdup(path))) {
1244 if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) {
1255 STRV_FOREACH(p, u->meta.manager->unit_path) {
1257 /* Instead of opening the path right away, we manually
1258 * follow all symlinks and add their name to our unit
1259 * name set while doing so */
1260 if (!(filename = path_make_absolute(path, *p))) {
1265 if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) {
1274 /* Empty the symlink names for the next run */
1275 while ((sn = set_steal_first(symlink_names)))
1291 if ((r = merge_by_names(&merged, symlink_names, id)) < 0)
1295 u->meta.load_state = UNIT_MERGED;
1300 /* Now, parse the file contents */
1301 if ((r = config_parse(filename, f, sections, items, u)) < 0)
1304 free(u->meta.fragment_path);
1305 u->meta.fragment_path = filename;
1308 u->meta.load_state = UNIT_LOADED;
1312 while ((k = set_steal_first(symlink_names)))
1315 set_free(symlink_names);
1324 int unit_load_fragment(Unit *u) {
1329 if (u->meta.fragment_path) {
1331 if ((r = load_from_path(u, u->meta.fragment_path)) < 0)
1338 /* Try to find the unit under its id */
1339 if ((t = unit_id(u)))
1340 if ((r = load_from_path(u, t)) < 0)
1343 /* Try to find an alias we can load this with */
1344 if (u->meta.load_state == UNIT_STUB)
1345 SET_FOREACH(t, u->meta.names, i) {
1347 if (unit_id(u) == t)
1350 if ((r = load_from_path(u, t)) < 0)
1353 if (u->meta.load_state != UNIT_STUB)
1361 void unit_dump_config_items(FILE *f) {
1362 /* OK, this wins a prize for extreme ugliness. */
1364 load_from_path(NULL, (const void*) f);