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 if (UNIT_VTABLE(u)->refuse_requires &&
60 (d == UNIT_REQUIRES ||
61 d == UNIT_SOFT_REQUIRES ||
62 d == UNIT_REQUISITE ||
63 d == UNIT_SOFT_REQUISITE)) {
64 log_error("[%s:%u] Dependency of type %s not acceptable for this unit type.", filename, line, lvalue);
68 FOREACH_WORD(w, l, rvalue, state) {
72 if (!(t = strndup(w, l)))
75 r = unit_add_dependency_by_name(u, d, t);
85 static int config_parse_names(
104 FOREACH_WORD(w, l, rvalue, state) {
108 if (!(t = strndup(w, l)))
111 r = unit_merge_by_name(u, t);
121 static int config_parse_listen(
122 const char *filename,
141 if (!(p = new0(SocketPort, 1)))
144 if (streq(lvalue, "ListenFIFO")) {
145 p->type = SOCKET_FIFO;
147 if (!(p->path = strdup(rvalue))) {
152 p->type = SOCKET_SOCKET;
154 if ((r = socket_address_parse(&p->address, rvalue)) < 0) {
155 log_error("[%s:%u] Failed to parse address value: %s", filename, line, rvalue);
160 if (streq(lvalue, "ListenStream"))
161 p->address.type = SOCK_STREAM;
162 else if (streq(lvalue, "ListenDatagram"))
163 p->address.type = SOCK_DGRAM;
165 assert(streq(lvalue, "ListenSequentialPacket"));
166 p->address.type = SOCK_SEQPACKET;
169 if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) {
171 return -EPROTONOSUPPORT;
176 LIST_PREPEND(SocketPort, port, s->ports, p);
181 static int config_parse_socket_bind(
182 const char *filename,
200 if ((r = parse_boolean(rvalue)) < 0) {
201 log_error("[%s:%u] Failed to parse bind IPv6 only value: %s", filename, line, rvalue);
205 s->bind_ipv6_only = r ? SOCKET_ADDRESS_IPV6_ONLY : SOCKET_ADDRESS_BOTH;
210 static int config_parse_nice(
211 const char *filename,
219 ExecContext *c = data;
227 if ((r = safe_atoi(rvalue, &priority)) < 0) {
228 log_error("[%s:%u] Failed to parse nice priority: %s", filename, line, rvalue);
232 if (priority < PRIO_MIN || priority >= PRIO_MAX) {
233 log_error("[%s:%u] Nice priority out of range: %s", filename, line, rvalue);
243 static int config_parse_oom_adjust(
244 const char *filename,
252 ExecContext *c = data;
260 if ((r = safe_atoi(rvalue, &oa)) < 0) {
261 log_error("[%s:%u] Failed to parse OOM adjust value: %s", filename, line, rvalue);
265 if (oa < OOM_DISABLE || oa > OOM_ADJUST_MAX) {
266 log_error("[%s:%u] OOM adjust value out of range: %s", filename, line, rvalue);
271 c->oom_adjust_set = true;
276 static int config_parse_mode(
277 const char *filename,
295 l = strtol(rvalue, &x, 8);
296 if (!x || *x || errno) {
297 log_error("[%s:%u] Failed to parse mode value: %s", filename, line, rvalue);
298 return errno ? -errno : -EINVAL;
301 if (l < 0000 || l > 07777) {
302 log_error("[%s:%u] mode value out of range: %s", filename, line, rvalue);
310 static int config_parse_exec(
311 const char *filename,
319 ExecCommand **e = data, *nce = NULL;
332 FOREACH_WORD_QUOTED(w, l, rvalue, state)
335 if (!(n = new(char*, k+1)))
339 FOREACH_WORD_QUOTED(w, l, rvalue, state)
340 if (!(n[k++] = strndup(w, l)))
345 if (!n[0] || !path_is_absolute(n[0])) {
346 log_error("[%s:%u] Invalid executable path in command line: %s", filename, line, rvalue);
351 if (!(nce = new0(ExecCommand, 1)))
355 if (!(nce->path = strdup(n[0])))
358 exec_command_append_list(e, nce);
372 static int config_parse_usec(
373 const char *filename,
382 unsigned long long u;
390 if ((r = safe_atollu(rvalue, &u)) < 0) {
391 log_error("[%s:%u] Failed to parse time value: %s", filename, line, rvalue);
395 /* We actually assume the user configures seconds. Later on we
396 * might choose to support suffixes for time values, to
397 * configure bigger or smaller units */
399 *usec = u * USEC_PER_SEC;
404 static int config_parse_service_type(
405 const char *filename,
421 if ((x = service_type_from_string(rvalue)) < 0) {
422 log_error("[%s:%u] Failed to parse service type: %s", filename, line, rvalue);
431 static int config_parse_service_restart(
432 const char *filename,
448 if ((x = service_restart_from_string(rvalue)) < 0) {
449 log_error("[%s:%u] Failed to parse service restart specifier: %s", filename, line, rvalue);
458 static int config_parse_bindtodevice(
459 const char *filename,
475 if (rvalue[0] && !streq(rvalue, "*")) {
476 if (!(n = strdup(rvalue)))
481 free(s->bind_to_device);
482 s->bind_to_device = n;
487 static int config_parse_output(
488 const char *filename,
496 ExecOutput *o = data, x;
503 if ((x = exec_output_from_string(rvalue)) < 0) {
504 log_error("[%s:%u] Failed to parse output specifier: %s", filename, line, rvalue);
513 static int config_parse_input(
514 const char *filename,
522 ExecInput *i = data, x;
529 if ((x = exec_input_from_string(rvalue)) < 0) {
530 log_error("[%s:%u] Failed to parse input specifier: %s", filename, line, rvalue);
539 static int config_parse_facility(
540 const char *filename,
556 if ((x = log_facility_from_string(rvalue)) < 0)
558 /* Second try, let's see if this is a number. */
559 if (safe_atoi(rvalue, &x) < 0 || !log_facility_to_string(x)) {
560 log_error("[%s:%u] Failed to parse log facility: %s", filename, line, rvalue);
564 *o = LOG_MAKEPRI(x, LOG_PRI(*o));
569 static int config_parse_level(
570 const char *filename,
586 if ((x = log_level_from_string(rvalue)) < 0)
588 /* Second try, let's see if this is a number. */
589 if (safe_atoi(rvalue, &x) < 0 || !log_level_to_string(x)) {
590 log_error("[%s:%u] Failed to parse log level: %s", filename, line, rvalue);
594 *o = LOG_MAKEPRI(LOG_FAC(*o), x);
598 static int config_parse_io_class(
599 const char *filename,
607 ExecContext *c = data;
615 if ((x = ioprio_class_from_string(rvalue)) < 0)
617 /* Second try, let's see if this is a number. */
618 if (safe_atoi(rvalue, &x) < 0 || !ioprio_class_to_string(x)) {
619 log_error("[%s:%u] Failed to parse IO scheduling class: %s", filename, line, rvalue);
623 c->ioprio = IOPRIO_PRIO_VALUE(x, IOPRIO_PRIO_DATA(c->ioprio));
624 c->ioprio_set = true;
629 static int config_parse_io_priority(
630 const char *filename,
638 ExecContext *c = data;
646 if (safe_atoi(rvalue, &i) < 0 || i < 0 || i >= IOPRIO_BE_NR) {
647 log_error("[%s:%u] Failed to parse io priority: %s", filename, line, rvalue);
651 c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), i);
652 c->ioprio_set = true;
657 static int config_parse_cpu_sched_policy(
658 const char *filename,
667 ExecContext *c = data;
675 if ((x = sched_policy_from_string(rvalue)) < 0)
677 /* Second try, let's see if this is a number. */
678 if (safe_atoi(rvalue, &x) < 0 || !sched_policy_to_string(x)) {
679 log_error("[%s:%u] Failed to parse CPU scheduling policy: %s", filename, line, rvalue);
683 c->cpu_sched_policy = x;
684 c->cpu_sched_set = true;
689 static int config_parse_cpu_sched_prio(
690 const char *filename,
698 ExecContext *c = data;
706 /* On Linux RR/FIFO have the same range */
707 if (safe_atoi(rvalue, &i) < 0 || i < sched_get_priority_min(SCHED_RR) || i > sched_get_priority_max(SCHED_RR)) {
708 log_error("[%s:%u] Failed to parse CPU scheduling priority: %s", filename, line, rvalue);
712 c->cpu_sched_priority = i;
713 c->cpu_sched_set = true;
718 static int config_parse_cpu_affinity(
719 const char *filename,
727 ExecContext *c = data;
737 FOREACH_WORD(w, l, rvalue, state) {
742 if (!(t = strndup(w, l)))
745 r = safe_atou(t, &cpu);
748 if (r < 0 || cpu >= CPU_SETSIZE) {
749 log_error("[%s:%u] Failed to parse CPU affinity: %s", filename, line, rvalue);
753 CPU_SET(cpu, &c->cpu_affinity);
756 c->cpu_affinity_set = true;
761 static int config_parse_capabilities(
762 const char *filename,
770 ExecContext *c = data;
778 if (!(cap = cap_from_text(rvalue))) {
782 log_error("[%s:%u] Failed to parse capabilities: %s", filename, line, rvalue);
787 cap_free(c->capabilities);
788 c->capabilities = cap;
793 static int config_parse_secure_bits(
794 const char *filename,
802 ExecContext *c = data;
812 FOREACH_WORD(w, l, rvalue, state) {
813 if (first_word(w, "keep-caps"))
814 c->secure_bits |= SECURE_KEEP_CAPS;
815 else if (first_word(w, "keep-caps-locked"))
816 c->secure_bits |= SECURE_KEEP_CAPS_LOCKED;
817 else if (first_word(w, "no-setuid-fixup"))
818 c->secure_bits |= SECURE_NO_SETUID_FIXUP;
819 else if (first_word(w, "no-setuid-fixup-locked"))
820 c->secure_bits |= SECURE_NO_SETUID_FIXUP_LOCKED;
821 else if (first_word(w, "noroot"))
822 c->secure_bits |= SECURE_NOROOT;
823 else if (first_word(w, "noroot-locked"))
824 c->secure_bits |= SECURE_NOROOT_LOCKED;
826 log_error("[%s:%u] Failed to parse secure bits: %s", filename, line, rvalue);
834 static int config_parse_bounding_set(
835 const char *filename,
843 ExecContext *c = data;
853 FOREACH_WORD(w, l, rvalue, state) {
858 if (!(t = strndup(w, l)))
861 r = cap_from_name(t, &cap);
865 log_error("[%s:%u] Failed to parse capability bounding set: %s", filename, line, rvalue);
869 c->capability_bounding_set_drop |= 1 << cap;
875 static int config_parse_timer_slack_ns(
876 const char *filename,
884 ExecContext *c = data;
893 if ((r = safe_atolu(rvalue, &u)) < 0) {
894 log_error("[%s:%u] Failed to parse time slack value: %s", filename, line, rvalue);
898 c->timer_slack_ns = u;
903 static int config_parse_limit(
904 const char *filename,
912 struct rlimit **rl = data;
913 unsigned long long u;
921 if ((r = safe_atollu(rvalue, &u)) < 0) {
922 log_error("[%s:%u] Failed to parse resource value: %s", filename, line, rvalue);
927 if (!(*rl = new(struct rlimit, 1)))
930 (*rl)->rlim_cur = (*rl)->rlim_max = (rlim_t) u;
934 static int config_parse_cgroup(
935 const char *filename,
948 FOREACH_WORD(w, l, rvalue, state) {
952 if (!(t = strndup(w, l)))
955 r = unit_add_cgroup_from_text(u, t);
965 static int config_parse_sysv_priority(
966 const char *filename,
974 int *priority = data;
982 if ((r = safe_atoi(rvalue, &i)) < 0 || i < 0) {
983 log_error("[%s:%u] Failed to parse SysV start priority: %s", filename, line, rvalue);
991 static int config_parse_kill_mode(
992 const char *filename,
1000 KillMode *m = data, x;
1007 if ((x = kill_mode_from_string(rvalue)) < 0) {
1008 log_error("[%s:%u] Failed to parse kill mode specifier: %s", filename, line, rvalue);
1017 #define FOLLOW_MAX 8
1019 static int open_follow(char **filename, FILE **_f, Set *names, char **_id) {
1030 /* This will update the filename pointer if the loaded file is
1031 * reached by a symlink. The old string will be freed. */
1034 char *target, *k, *name;
1036 if (c++ >= FOLLOW_MAX)
1039 path_kill_slashes(*filename);
1041 /* Add the file name we are currently looking at to
1042 * the names of this unit */
1043 name = file_name_from_path(*filename);
1044 if (!(id = set_get(names, name))) {
1046 if (!(id = strdup(name)))
1049 if ((r = set_put(names, id)) < 0) {
1055 /* Try to open the file name, but don't if its a symlink */
1056 if ((fd = open(*filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW)) >= 0)
1062 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
1063 if ((r = readlink_malloc(*filename, &target)) < 0)
1066 k = file_in_same_dir(*filename, target);
1076 if (!(f = fdopen(fd, "r"))) {
1078 assert(close_nointr(fd) == 0);
1087 static int merge_by_names(Unit **u, Set *names, const char *id) {
1095 /* Let's try to add in all symlink names we found */
1096 while ((k = set_steal_first(names))) {
1098 /* First try to merge in the other name into our
1100 if ((r = unit_merge_by_name(*u, k)) < 0) {
1103 /* Hmm, we couldn't merge the other unit into
1104 * ours? Then let's try it the other way
1107 other = manager_get_unit((*u)->meta.manager, k);
1111 if ((r = unit_merge(other, *u)) >= 0) {
1113 return merge_by_names(u, names, NULL);
1120 unit_choose_id(*u, id);
1128 static void dump_items(FILE *f, const ConfigItem *items) {
1129 const ConfigItem *i;
1130 const char *prev_section = NULL;
1131 bool not_first = false;
1134 ConfigParserCallback callback;
1137 { config_parse_int, "INTEGER" },
1138 { config_parse_unsigned, "UNSIGNED" },
1139 { config_parse_size, "SIZE" },
1140 { config_parse_bool, "BOOLEAN" },
1141 { config_parse_string, "STRING" },
1142 { config_parse_path, "PATH" },
1143 { config_parse_strv, "STRING [...]" },
1144 { config_parse_nice, "NICE" },
1145 { config_parse_oom_adjust, "OOMADJUST" },
1146 { config_parse_io_class, "IOCLASS" },
1147 { config_parse_io_priority, "IOPRIORITY" },
1148 { config_parse_cpu_sched_policy, "CPUSCHEDPOLICY" },
1149 { config_parse_cpu_sched_prio, "CPUSCHEDPRIO" },
1150 { config_parse_cpu_affinity, "CPUAFFINITY" },
1151 { config_parse_mode, "MODE" },
1152 { config_parse_output, "OUTPUT" },
1153 { config_parse_input, "INPUT" },
1154 { config_parse_facility, "FACILITY" },
1155 { config_parse_level, "LEVEL" },
1156 { config_parse_capabilities, "CAPABILITIES" },
1157 { config_parse_secure_bits, "SECUREBITS" },
1158 { config_parse_bounding_set, "BOUNDINGSET" },
1159 { config_parse_timer_slack_ns, "TIMERSLACK" },
1160 { config_parse_limit, "LIMIT" },
1161 { config_parse_cgroup, "CGROUP [...]" },
1162 { config_parse_deps, "UNIT [...]" },
1163 { config_parse_names, "UNIT [...]" },
1164 { config_parse_exec, "PATH [ARGUMENT [...]]" },
1165 { config_parse_service_type, "SERVICETYPE" },
1166 { config_parse_service_restart, "SERVICERESTART" },
1167 { config_parse_sysv_priority, "SYSVPRIORITY" },
1168 { config_parse_kill_mode, "KILLMODE" },
1169 { config_parse_listen, "SOCKET [...]" },
1170 { config_parse_socket_bind, "SOCKETBIND" },
1171 { config_parse_bindtodevice, "NETWORKINTERFACE" }
1177 for (i = items; i->lvalue; i++) {
1179 const char *rvalue = "OTHER";
1181 if (!streq_ptr(i->section, prev_section)) {
1187 fprintf(f, "[%s]\n", i->section);
1188 prev_section = i->section;
1191 for (j = 0; j < ELEMENTSOF(table); j++)
1192 if (i->parse == table[j].callback) {
1193 rvalue = table[j].rvalue;
1197 fprintf(f, "%s=%s\n", i->lvalue, rvalue);
1201 static int load_from_path(Unit *u, const char *path) {
1203 static const char* const section_table[_UNIT_TYPE_MAX] = {
1204 [UNIT_SERVICE] = "Service",
1205 [UNIT_TIMER] = "Timer",
1206 [UNIT_SOCKET] = "Socket",
1207 [UNIT_TARGET] = "Target",
1208 [UNIT_DEVICE] = "Device",
1209 [UNIT_MOUNT] = "Mount",
1210 [UNIT_AUTOMOUNT] = "Automount",
1211 [UNIT_SNAPSHOT] = "Snapshot"
1214 #define EXEC_CONTEXT_CONFIG_ITEMS(context, section) \
1215 { "WorkingDirectory", config_parse_path, &(context).working_directory, section }, \
1216 { "RootDirectory", config_parse_path, &(context).root_directory, section }, \
1217 { "User", config_parse_string, &(context).user, section }, \
1218 { "Group", config_parse_string, &(context).group, section }, \
1219 { "SupplementaryGroups", config_parse_strv, &(context).supplementary_groups, section }, \
1220 { "Nice", config_parse_nice, &(context), section }, \
1221 { "OOMAdjust", config_parse_oom_adjust, &(context), section }, \
1222 { "IOSchedulingClass", config_parse_io_class, &(context), section }, \
1223 { "IOSchedulingPriority", config_parse_io_priority, &(context), section }, \
1224 { "CPUSchedulingPolicy", config_parse_cpu_sched_policy,&(context), section }, \
1225 { "CPUSchedulingPriority", config_parse_cpu_sched_prio, &(context), section }, \
1226 { "CPUSchedulingResetOnFork", config_parse_bool, &(context).cpu_sched_reset_on_fork, section }, \
1227 { "CPUAffinity", config_parse_cpu_affinity, &(context), section }, \
1228 { "UMask", config_parse_mode, &(context).umask, section }, \
1229 { "Environment", config_parse_strv, &(context).environment, section }, \
1230 { "Output", config_parse_output, &(context).output, section }, \
1231 { "Input", config_parse_input, &(context).input, section }, \
1232 { "SyslogIdentifier", config_parse_string, &(context).syslog_identifier, section }, \
1233 { "SyslogFacility", config_parse_facility, &(context).syslog_priority, section }, \
1234 { "SyslogLevel", config_parse_level, &(context).syslog_priority, section }, \
1235 { "Capabilities", config_parse_capabilities, &(context), section }, \
1236 { "SecureBits", config_parse_secure_bits, &(context), section }, \
1237 { "CapabilityBoundingSetDrop", config_parse_bounding_set, &(context), section }, \
1238 { "TimerSlackNS", config_parse_timer_slack_ns, &(context), section }, \
1239 { "LimitCPU", config_parse_limit, &(context).rlimit[RLIMIT_CPU], section }, \
1240 { "LimitFSIZE", config_parse_limit, &(context).rlimit[RLIMIT_FSIZE], section }, \
1241 { "LimitDATA", config_parse_limit, &(context).rlimit[RLIMIT_DATA], section }, \
1242 { "LimitSTACK", config_parse_limit, &(context).rlimit[RLIMIT_STACK], section }, \
1243 { "LimitCORE", config_parse_limit, &(context).rlimit[RLIMIT_CORE], section }, \
1244 { "LimitRSS", config_parse_limit, &(context).rlimit[RLIMIT_RSS], section }, \
1245 { "LimitNOFILE", config_parse_limit, &(context).rlimit[RLIMIT_NOFILE], section }, \
1246 { "LimitAS", config_parse_limit, &(context).rlimit[RLIMIT_AS], section }, \
1247 { "LimitNPROC", config_parse_limit, &(context).rlimit[RLIMIT_NPROC], section }, \
1248 { "LimitMEMLOCK", config_parse_limit, &(context).rlimit[RLIMIT_MEMLOCK], section }, \
1249 { "LimitLOCKS", config_parse_limit, &(context).rlimit[RLIMIT_LOCKS], section }, \
1250 { "LimitSIGPENDING", config_parse_limit, &(context).rlimit[RLIMIT_SIGPENDING], section }, \
1251 { "LimitMSGQUEUE", config_parse_limit, &(context).rlimit[RLIMIT_MSGQUEUE], section }, \
1252 { "LimitNICE", config_parse_limit, &(context).rlimit[RLIMIT_NICE], section }, \
1253 { "LimitRTPRIO", config_parse_limit, &(context).rlimit[RLIMIT_RTPRIO], section }, \
1254 { "LimitRTTIME", config_parse_limit, &(context).rlimit[RLIMIT_RTTIME], section }, \
1255 { "ControlGroup", config_parse_cgroup, u, section }, \
1256 { "NewSession", config_parse_bool, &(context).new_session, section }
1258 const ConfigItem items[] = {
1259 { "Names", config_parse_names, u, "Meta" },
1260 { "Description", config_parse_string, &u->meta.description, "Meta" },
1261 { "Requires", config_parse_deps, UINT_TO_PTR(UNIT_REQUIRES), "Meta" },
1262 { "SoftRequires", config_parse_deps, UINT_TO_PTR(UNIT_SOFT_REQUIRES), "Meta" },
1263 { "Wants", config_parse_deps, UINT_TO_PTR(UNIT_WANTS), "Meta" },
1264 { "Requisite", config_parse_deps, UINT_TO_PTR(UNIT_REQUISITE), "Meta" },
1265 { "SoftRequisite", config_parse_deps, UINT_TO_PTR(UNIT_SOFT_REQUISITE), "Meta" },
1266 { "Conflicts", config_parse_deps, UINT_TO_PTR(UNIT_CONFLICTS), "Meta" },
1267 { "Before", config_parse_deps, UINT_TO_PTR(UNIT_BEFORE), "Meta" },
1268 { "After", config_parse_deps, UINT_TO_PTR(UNIT_AFTER), "Meta" },
1269 { "RecursiveStop", config_parse_bool, &u->meta.recursive_stop, "Meta" },
1270 { "StopWhenUnneeded", config_parse_bool, &u->meta.stop_when_unneeded, "Meta" },
1272 { "PIDFile", config_parse_path, &u->service.pid_file, "Service" },
1273 { "ExecStartPre", config_parse_exec, u->service.exec_command+SERVICE_EXEC_START_PRE, "Service" },
1274 { "ExecStart", config_parse_exec, u->service.exec_command+SERVICE_EXEC_START, "Service" },
1275 { "ExecStartPost", config_parse_exec, u->service.exec_command+SERVICE_EXEC_START_POST, "Service" },
1276 { "ExecReload", config_parse_exec, u->service.exec_command+SERVICE_EXEC_RELOAD, "Service" },
1277 { "ExecStop", config_parse_exec, u->service.exec_command+SERVICE_EXEC_STOP, "Service" },
1278 { "ExecStopPost", config_parse_exec, u->service.exec_command+SERVICE_EXEC_STOP_POST, "Service" },
1279 { "RestartSec", config_parse_usec, &u->service.restart_usec, "Service" },
1280 { "TimeoutSec", config_parse_usec, &u->service.timeout_usec, "Service" },
1281 { "Type", config_parse_service_type, &u->service, "Service" },
1282 { "Restart", config_parse_service_restart, &u->service, "Service" },
1283 { "PermissionsStartOnly", config_parse_bool, &u->service.permissions_start_only, "Service" },
1284 { "RootDirectoryStartOnly", config_parse_bool, &u->service.root_directory_start_only, "Service" },
1285 { "ValidNoProcess", config_parse_bool, &u->service.valid_no_process, "Service" },
1286 { "SysVStartPriority", config_parse_sysv_priority, &u->service.sysv_start_priority, "Service" },
1287 { "KillMode", config_parse_kill_mode, &u->service.kill_mode, "Service" },
1288 { "NonBlocking", config_parse_bool, &u->service.exec_context.non_blocking, "Service" },
1289 EXEC_CONTEXT_CONFIG_ITEMS(u->service.exec_context, "Service"),
1291 { "ListenStream", config_parse_listen, &u->socket, "Socket" },
1292 { "ListenDatagram", config_parse_listen, &u->socket, "Socket" },
1293 { "ListenSequentialPacket", config_parse_listen, &u->socket, "Socket" },
1294 { "ListenFIFO", config_parse_listen, &u->socket, "Socket" },
1295 { "BindIPv6Only", config_parse_socket_bind, &u->socket, "Socket" },
1296 { "Backlog", config_parse_unsigned, &u->socket.backlog, "Socket" },
1297 { "BindToDevice", config_parse_bindtodevice, &u->socket, "Socket" },
1298 { "ExecStartPre", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_START_PRE, "Socket" },
1299 { "ExecStartPost", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_START_POST, "Socket" },
1300 { "ExecStopPre", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_STOP_PRE, "Socket" },
1301 { "ExecStopPost", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_STOP_POST, "Socket" },
1302 { "TimeoutSec", config_parse_usec, &u->socket.timeout_usec, "Socket" },
1303 { "DirectoryMode", config_parse_mode, &u->socket.directory_mode, "Socket" },
1304 { "SocketMode", config_parse_mode, &u->socket.socket_mode, "Socket" },
1305 { "KillMode", config_parse_kill_mode, &u->socket.kill_mode, "Socket" },
1306 EXEC_CONTEXT_CONFIG_ITEMS(u->socket.exec_context, "Socket"),
1308 { "What", config_parse_string, &u->mount.parameters_fragment.what, "Mount" },
1309 { "Where", config_parse_path, &u->mount.where, "Mount" },
1310 { "Options", config_parse_string, &u->mount.parameters_fragment.options, "Mount" },
1311 { "Type", config_parse_string, &u->mount.parameters_fragment.fstype, "Mount" },
1312 { "TimeoutSec", config_parse_usec, &u->mount.timeout_usec, "Mount" },
1313 { "KillMode", config_parse_kill_mode, &u->mount.kill_mode, "Mount" },
1314 EXEC_CONTEXT_CONFIG_ITEMS(u->mount.exec_context, "Mount"),
1316 { NULL, NULL, NULL, NULL }
1319 #undef EXEC_CONTEXT_CONFIG_ITEMS
1321 const char *sections[3];
1326 char *filename = NULL, *id = NULL;
1330 /* Dirty dirty hack. */
1331 dump_items((FILE*) path, items);
1338 sections[0] = "Meta";
1339 sections[1] = section_table[u->meta.type];
1342 if (!(symlink_names = set_new(string_hash_func, string_compare_func)))
1345 if (path_is_absolute(path)) {
1347 if (!(filename = strdup(path))) {
1352 if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) {
1363 STRV_FOREACH(p, u->meta.manager->unit_path) {
1365 /* Instead of opening the path right away, we manually
1366 * follow all symlinks and add their name to our unit
1367 * name set while doing so */
1368 if (!(filename = path_make_absolute(path, *p))) {
1373 if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) {
1382 /* Empty the symlink names for the next run */
1383 while ((sn = set_steal_first(symlink_names)))
1399 if ((r = merge_by_names(&merged, symlink_names, id)) < 0)
1403 u->meta.load_state = UNIT_MERGED;
1408 /* Now, parse the file contents */
1409 if ((r = config_parse(filename, f, sections, items, u)) < 0)
1412 free(u->meta.fragment_path);
1413 u->meta.fragment_path = filename;
1416 u->meta.load_state = UNIT_LOADED;
1420 while ((k = set_steal_first(symlink_names)))
1423 set_free(symlink_names);
1432 int unit_load_fragment(Unit *u) {
1437 if (u->meta.fragment_path) {
1439 if ((r = load_from_path(u, u->meta.fragment_path)) < 0)
1446 /* Try to find the unit under its id */
1447 if ((t = unit_id(u)))
1448 if ((r = load_from_path(u, t)) < 0)
1451 /* Try to find an alias we can load this with */
1452 if (u->meta.load_state == UNIT_STUB)
1453 SET_FOREACH(t, u->meta.names, i) {
1455 if (unit_id(u) == t)
1458 if ((r = load_from_path(u, t)) < 0)
1461 if (u->meta.load_state != UNIT_STUB)
1469 void unit_dump_config_items(FILE *f) {
1470 /* OK, this wins a prize for extreme ugliness. */
1472 load_from_path(NULL, (const void*) f);