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 DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \
44 static int function( \
45 const char *filename, \
47 const char *section, \
60 if ((x = name##_from_string(rvalue)) < 0) { \
61 log_error("[%s:%u] " msg ": %s", filename, line, rvalue); \
70 static int config_parse_deps(
79 UnitDependency d = PTR_TO_UINT(data);
89 FOREACH_WORD(w, l, rvalue, state) {
93 if (!(t = strndup(w, l)))
96 k = unit_name_printf(u, t);
102 r = unit_add_dependency_by_name(u, d, k, NULL, true);
112 static int config_parse_names(
113 const char *filename,
131 FOREACH_WORD(w, l, rvalue, state) {
135 if (!(t = strndup(w, l)))
138 k = unit_name_printf(u, t);
144 r = unit_merge_by_name(u, k);
154 static int config_parse_description(
155 const char *filename,
171 if (!(k = unit_full_printf(u, rvalue)))
174 free(u->meta.description);
177 u->meta.description = k;
180 u->meta.description = NULL;
186 static int config_parse_listen(
187 const char *filename,
206 if (!(p = new0(SocketPort, 1)))
209 if (streq(lvalue, "ListenFIFO")) {
210 p->type = SOCKET_FIFO;
212 if (!(p->path = strdup(rvalue))) {
217 p->type = SOCKET_SOCKET;
219 if ((r = socket_address_parse(&p->address, rvalue)) < 0) {
220 log_error("[%s:%u] Failed to parse address value: %s", filename, line, rvalue);
225 if (streq(lvalue, "ListenStream"))
226 p->address.type = SOCK_STREAM;
227 else if (streq(lvalue, "ListenDatagram"))
228 p->address.type = SOCK_DGRAM;
230 assert(streq(lvalue, "ListenSequentialPacket"));
231 p->address.type = SOCK_SEQPACKET;
234 if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) {
236 return -EPROTONOSUPPORT;
241 LIST_PREPEND(SocketPort, port, s->ports, p);
246 static int config_parse_socket_bind(
247 const char *filename,
265 if ((r = parse_boolean(rvalue)) < 0) {
266 log_error("[%s:%u] Failed to parse bind IPv6 only value: %s", filename, line, rvalue);
270 s->bind_ipv6_only = r ? SOCKET_ADDRESS_IPV6_ONLY : SOCKET_ADDRESS_BOTH;
275 static int config_parse_nice(
276 const char *filename,
284 ExecContext *c = data;
292 if ((r = safe_atoi(rvalue, &priority)) < 0) {
293 log_error("[%s:%u] Failed to parse nice priority: %s", filename, line, rvalue);
297 if (priority < PRIO_MIN || priority >= PRIO_MAX) {
298 log_error("[%s:%u] Nice priority out of range: %s", filename, line, rvalue);
308 static int config_parse_oom_adjust(
309 const char *filename,
317 ExecContext *c = data;
325 if ((r = safe_atoi(rvalue, &oa)) < 0) {
326 log_error("[%s:%u] Failed to parse OOM adjust value: %s", filename, line, rvalue);
330 if (oa < OOM_DISABLE || oa > OOM_ADJUST_MAX) {
331 log_error("[%s:%u] OOM adjust value out of range: %s", filename, line, rvalue);
336 c->oom_adjust_set = true;
341 static int config_parse_mode(
342 const char *filename,
360 l = strtol(rvalue, &x, 8);
361 if (!x || *x || errno) {
362 log_error("[%s:%u] Failed to parse mode value: %s", filename, line, rvalue);
363 return errno ? -errno : -EINVAL;
366 if (l < 0000 || l > 07777) {
367 log_error("[%s:%u] mode value out of range: %s", filename, line, rvalue);
375 static int config_parse_exec(
376 const char *filename,
384 ExecCommand **e = data, *nce = NULL;
397 FOREACH_WORD_QUOTED(w, l, rvalue, state)
400 if (!(n = new(char*, k+1)))
404 FOREACH_WORD_QUOTED(w, l, rvalue, state)
405 if (!(n[k++] = strndup(w, l)))
410 if (!n[0] || !path_is_absolute(n[0])) {
411 log_error("[%s:%u] Invalid executable path in command line: %s", filename, line, rvalue);
416 if (!(nce = new0(ExecCommand, 1)))
420 if (!(nce->path = strdup(n[0])))
423 exec_command_append_list(e, nce);
437 static int config_parse_usec(
438 const char *filename,
454 if ((r = parse_usec(rvalue, usec)) < 0) {
455 log_error("[%s:%u] Failed to parse time value: %s", filename, line, rvalue);
462 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type");
463 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier");
465 static int config_parse_bindtodevice(
466 const char *filename,
482 if (rvalue[0] && !streq(rvalue, "*")) {
483 if (!(n = strdup(rvalue)))
488 free(s->bind_to_device);
489 s->bind_to_device = n;
494 DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output specifier");
495 DEFINE_CONFIG_PARSE_ENUM(config_parse_input, exec_input, ExecInput, "Failed to parse input specifier");
497 static int config_parse_facility(
498 const char *filename,
514 if ((x = log_facility_from_string(rvalue)) < 0) {
515 log_error("[%s:%u] Failed to parse log facility: %s", filename, line, rvalue);
519 *o = LOG_MAKEPRI(x, LOG_PRI(*o));
524 static int config_parse_level(
525 const char *filename,
541 if ((x = log_level_from_string(rvalue)) < 0) {
542 log_error("[%s:%u] Failed to parse log level: %s", filename, line, rvalue);
546 *o = LOG_MAKEPRI(LOG_FAC(*o), x);
550 static int config_parse_io_class(
551 const char *filename,
559 ExecContext *c = data;
567 if ((x = ioprio_class_from_string(rvalue)) < 0) {
568 log_error("[%s:%u] Failed to parse IO scheduling class: %s", filename, line, rvalue);
572 c->ioprio = IOPRIO_PRIO_VALUE(x, IOPRIO_PRIO_DATA(c->ioprio));
573 c->ioprio_set = true;
578 static int config_parse_io_priority(
579 const char *filename,
587 ExecContext *c = data;
595 if (safe_atoi(rvalue, &i) < 0 || i < 0 || i >= IOPRIO_BE_NR) {
596 log_error("[%s:%u] Failed to parse io priority: %s", filename, line, rvalue);
600 c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), i);
601 c->ioprio_set = true;
606 static int config_parse_cpu_sched_policy(
607 const char *filename,
616 ExecContext *c = data;
624 if ((x = sched_policy_from_string(rvalue)) < 0) {
625 log_error("[%s:%u] Failed to parse CPU scheduling policy: %s", filename, line, rvalue);
629 c->cpu_sched_policy = x;
630 c->cpu_sched_set = true;
635 static int config_parse_cpu_sched_prio(
636 const char *filename,
644 ExecContext *c = data;
652 /* On Linux RR/FIFO have the same range */
653 if (safe_atoi(rvalue, &i) < 0 || i < sched_get_priority_min(SCHED_RR) || i > sched_get_priority_max(SCHED_RR)) {
654 log_error("[%s:%u] Failed to parse CPU scheduling priority: %s", filename, line, rvalue);
658 c->cpu_sched_priority = i;
659 c->cpu_sched_set = true;
664 static int config_parse_cpu_affinity(
665 const char *filename,
673 ExecContext *c = data;
683 FOREACH_WORD(w, l, rvalue, state) {
688 if (!(t = strndup(w, l)))
691 r = safe_atou(t, &cpu);
694 if (r < 0 || cpu >= CPU_SETSIZE) {
695 log_error("[%s:%u] Failed to parse CPU affinity: %s", filename, line, rvalue);
699 CPU_SET(cpu, &c->cpu_affinity);
702 c->cpu_affinity_set = true;
707 static int config_parse_capabilities(
708 const char *filename,
716 ExecContext *c = data;
724 if (!(cap = cap_from_text(rvalue))) {
728 log_error("[%s:%u] Failed to parse capabilities: %s", filename, line, rvalue);
733 cap_free(c->capabilities);
734 c->capabilities = cap;
739 static int config_parse_secure_bits(
740 const char *filename,
748 ExecContext *c = data;
758 FOREACH_WORD(w, l, rvalue, state) {
759 if (first_word(w, "keep-caps"))
760 c->secure_bits |= SECURE_KEEP_CAPS;
761 else if (first_word(w, "keep-caps-locked"))
762 c->secure_bits |= SECURE_KEEP_CAPS_LOCKED;
763 else if (first_word(w, "no-setuid-fixup"))
764 c->secure_bits |= SECURE_NO_SETUID_FIXUP;
765 else if (first_word(w, "no-setuid-fixup-locked"))
766 c->secure_bits |= SECURE_NO_SETUID_FIXUP_LOCKED;
767 else if (first_word(w, "noroot"))
768 c->secure_bits |= SECURE_NOROOT;
769 else if (first_word(w, "noroot-locked"))
770 c->secure_bits |= SECURE_NOROOT_LOCKED;
772 log_error("[%s:%u] Failed to parse secure bits: %s", filename, line, rvalue);
780 static int config_parse_bounding_set(
781 const char *filename,
789 ExecContext *c = data;
799 FOREACH_WORD(w, l, rvalue, state) {
804 if (!(t = strndup(w, l)))
807 r = cap_from_name(t, &cap);
811 log_error("[%s:%u] Failed to parse capability bounding set: %s", filename, line, rvalue);
815 c->capability_bounding_set_drop |= 1 << cap;
821 static int config_parse_timer_slack_ns(
822 const char *filename,
830 ExecContext *c = data;
839 if ((r = safe_atolu(rvalue, &u)) < 0) {
840 log_error("[%s:%u] Failed to parse time slack value: %s", filename, line, rvalue);
844 c->timer_slack_ns = u;
849 static int config_parse_limit(
850 const char *filename,
858 struct rlimit **rl = data;
859 unsigned long long u;
867 if ((r = safe_atollu(rvalue, &u)) < 0) {
868 log_error("[%s:%u] Failed to parse resource value: %s", filename, line, rvalue);
873 if (!(*rl = new(struct rlimit, 1)))
876 (*rl)->rlim_cur = (*rl)->rlim_max = (rlim_t) u;
880 static int config_parse_cgroup(
881 const char *filename,
894 FOREACH_WORD(w, l, rvalue, state) {
898 if (!(t = strndup(w, l)))
901 r = unit_add_cgroup_from_text(u, t);
911 static int config_parse_sysv_priority(
912 const char *filename,
920 int *priority = data;
928 if ((r = safe_atoi(rvalue, &i)) < 0 || i < 0) {
929 log_error("[%s:%u] Failed to parse SysV start priority: %s", filename, line, rvalue);
937 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode");
939 static int config_parse_mount_flags(
940 const char *filename,
948 ExecContext *c = data;
952 unsigned long flags = 0;
959 FOREACH_WORD(w, l, rvalue, state) {
960 if (strncmp(w, "shared", l) == 0)
962 else if (strncmp(w, "slave", l) == 0)
964 else if (strncmp(w, "private", l) == 0)
967 log_error("[%s:%u] Failed to parse mount flags: %s", filename, line, rvalue);
972 c->mount_flags = flags;
978 static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
989 /* This will update the filename pointer if the loaded file is
990 * reached by a symlink. The old string will be freed. */
993 char *target, *k, *name;
995 if (c++ >= FOLLOW_MAX)
998 path_kill_slashes(*filename);
1000 /* Add the file name we are currently looking at to
1001 * the names of this unit */
1002 name = file_name_from_path(*filename);
1003 if (!(id = set_get(names, name))) {
1005 if (!(id = strdup(name)))
1008 if ((r = set_put(names, id)) < 0) {
1014 /* Try to open the file name, but don't if its a symlink */
1015 if ((fd = open(*filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW)) >= 0)
1021 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
1022 if ((r = readlink_malloc(*filename, &target)) < 0)
1025 k = file_in_same_dir(*filename, target);
1035 if (!(f = fdopen(fd, "r"))) {
1037 close_nointr_nofail(fd);
1046 static int merge_by_names(Unit **u, Set *names, const char *id) {
1054 /* Let's try to add in all symlink names we found */
1055 while ((k = set_steal_first(names))) {
1057 /* First try to merge in the other name into our
1059 if ((r = unit_merge_by_name(*u, k)) < 0) {
1062 /* Hmm, we couldn't merge the other unit into
1063 * ours? Then let's try it the other way
1066 other = manager_get_unit((*u)->meta.manager, k);
1070 if ((r = unit_merge(other, *u)) >= 0) {
1072 return merge_by_names(u, names, NULL);
1079 unit_choose_id(*u, id);
1087 static void dump_items(FILE *f, const ConfigItem *items) {
1088 const ConfigItem *i;
1089 const char *prev_section = NULL;
1090 bool not_first = false;
1093 ConfigParserCallback callback;
1096 { config_parse_int, "INTEGER" },
1097 { config_parse_unsigned, "UNSIGNED" },
1098 { config_parse_size, "SIZE" },
1099 { config_parse_bool, "BOOLEAN" },
1100 { config_parse_string, "STRING" },
1101 { config_parse_path, "PATH" },
1102 { config_parse_strv, "STRING [...]" },
1103 { config_parse_nice, "NICE" },
1104 { config_parse_oom_adjust, "OOMADJUST" },
1105 { config_parse_io_class, "IOCLASS" },
1106 { config_parse_io_priority, "IOPRIORITY" },
1107 { config_parse_cpu_sched_policy, "CPUSCHEDPOLICY" },
1108 { config_parse_cpu_sched_prio, "CPUSCHEDPRIO" },
1109 { config_parse_cpu_affinity, "CPUAFFINITY" },
1110 { config_parse_mode, "MODE" },
1111 { config_parse_output, "OUTPUT" },
1112 { config_parse_input, "INPUT" },
1113 { config_parse_facility, "FACILITY" },
1114 { config_parse_level, "LEVEL" },
1115 { config_parse_capabilities, "CAPABILITIES" },
1116 { config_parse_secure_bits, "SECUREBITS" },
1117 { config_parse_bounding_set, "BOUNDINGSET" },
1118 { config_parse_timer_slack_ns, "TIMERSLACK" },
1119 { config_parse_limit, "LIMIT" },
1120 { config_parse_cgroup, "CGROUP [...]" },
1121 { config_parse_deps, "UNIT [...]" },
1122 { config_parse_names, "UNIT [...]" },
1123 { config_parse_exec, "PATH [ARGUMENT [...]]" },
1124 { config_parse_service_type, "SERVICETYPE" },
1125 { config_parse_service_restart, "SERVICERESTART" },
1126 { config_parse_sysv_priority, "SYSVPRIORITY" },
1127 { config_parse_kill_mode, "KILLMODE" },
1128 { config_parse_listen, "SOCKET [...]" },
1129 { config_parse_socket_bind, "SOCKETBIND" },
1130 { config_parse_bindtodevice, "NETWORKINTERFACE" },
1131 { config_parse_usec, "SECONDS" },
1132 { config_parse_path_strv, "PATH [...]" },
1133 { config_parse_mount_flags, "MOUNTFLAG [...]" },
1134 { config_parse_description, "DESCRIPTION" },
1140 for (i = items; i->lvalue; i++) {
1142 const char *rvalue = "OTHER";
1144 if (!streq_ptr(i->section, prev_section)) {
1150 fprintf(f, "[%s]\n", i->section);
1151 prev_section = i->section;
1154 for (j = 0; j < ELEMENTSOF(table); j++)
1155 if (i->parse == table[j].callback) {
1156 rvalue = table[j].rvalue;
1160 fprintf(f, "%s=%s\n", i->lvalue, rvalue);
1164 static int load_from_path(Unit *u, const char *path) {
1166 static const char* const section_table[_UNIT_TYPE_MAX] = {
1167 [UNIT_SERVICE] = "Service",
1168 [UNIT_TIMER] = "Timer",
1169 [UNIT_SOCKET] = "Socket",
1170 [UNIT_TARGET] = "Target",
1171 [UNIT_DEVICE] = "Device",
1172 [UNIT_MOUNT] = "Mount",
1173 [UNIT_AUTOMOUNT] = "Automount",
1174 [UNIT_SNAPSHOT] = "Snapshot",
1175 [UNIT_SWAP] = "Swap"
1178 #define EXEC_CONTEXT_CONFIG_ITEMS(context, section) \
1179 { "WorkingDirectory", config_parse_path, &(context).working_directory, section }, \
1180 { "RootDirectory", config_parse_path, &(context).root_directory, section }, \
1181 { "User", config_parse_string, &(context).user, section }, \
1182 { "Group", config_parse_string, &(context).group, section }, \
1183 { "SupplementaryGroups", config_parse_strv, &(context).supplementary_groups, section }, \
1184 { "Nice", config_parse_nice, &(context), section }, \
1185 { "OOMAdjust", config_parse_oom_adjust, &(context), section }, \
1186 { "IOSchedulingClass", config_parse_io_class, &(context), section }, \
1187 { "IOSchedulingPriority", config_parse_io_priority, &(context), section }, \
1188 { "CPUSchedulingPolicy", config_parse_cpu_sched_policy,&(context), section }, \
1189 { "CPUSchedulingPriority", config_parse_cpu_sched_prio, &(context), section }, \
1190 { "CPUSchedulingResetOnFork", config_parse_bool, &(context).cpu_sched_reset_on_fork, section }, \
1191 { "CPUAffinity", config_parse_cpu_affinity, &(context), section }, \
1192 { "UMask", config_parse_mode, &(context).umask, section }, \
1193 { "Environment", config_parse_strv, &(context).environment, section }, \
1194 { "StandardInput", config_parse_input, &(context).std_input, section }, \
1195 { "StandardOutput", config_parse_output, &(context).std_output, section }, \
1196 { "StandardError", config_parse_output, &(context).std_output, section }, \
1197 { "TTYPath", config_parse_path, &(context).tty_path, section }, \
1198 { "SyslogIdentifier", config_parse_string, &(context).syslog_identifier, section }, \
1199 { "SyslogFacility", config_parse_facility, &(context).syslog_priority, section }, \
1200 { "SyslogLevel", config_parse_level, &(context).syslog_priority, section }, \
1201 { "SyslogNoPrefix", config_parse_bool, &(context).syslog_no_prefix, section }, \
1202 { "Capabilities", config_parse_capabilities, &(context), section }, \
1203 { "SecureBits", config_parse_secure_bits, &(context), section }, \
1204 { "CapabilityBoundingSetDrop", config_parse_bounding_set, &(context), section }, \
1205 { "TimerSlackNS", config_parse_timer_slack_ns, &(context), section }, \
1206 { "LimitCPU", config_parse_limit, &(context).rlimit[RLIMIT_CPU], section }, \
1207 { "LimitFSIZE", config_parse_limit, &(context).rlimit[RLIMIT_FSIZE], section }, \
1208 { "LimitDATA", config_parse_limit, &(context).rlimit[RLIMIT_DATA], section }, \
1209 { "LimitSTACK", config_parse_limit, &(context).rlimit[RLIMIT_STACK], section }, \
1210 { "LimitCORE", config_parse_limit, &(context).rlimit[RLIMIT_CORE], section }, \
1211 { "LimitRSS", config_parse_limit, &(context).rlimit[RLIMIT_RSS], section }, \
1212 { "LimitNOFILE", config_parse_limit, &(context).rlimit[RLIMIT_NOFILE], section }, \
1213 { "LimitAS", config_parse_limit, &(context).rlimit[RLIMIT_AS], section }, \
1214 { "LimitNPROC", config_parse_limit, &(context).rlimit[RLIMIT_NPROC], section }, \
1215 { "LimitMEMLOCK", config_parse_limit, &(context).rlimit[RLIMIT_MEMLOCK], section }, \
1216 { "LimitLOCKS", config_parse_limit, &(context).rlimit[RLIMIT_LOCKS], section }, \
1217 { "LimitSIGPENDING", config_parse_limit, &(context).rlimit[RLIMIT_SIGPENDING], section }, \
1218 { "LimitMSGQUEUE", config_parse_limit, &(context).rlimit[RLIMIT_MSGQUEUE], section }, \
1219 { "LimitNICE", config_parse_limit, &(context).rlimit[RLIMIT_NICE], section }, \
1220 { "LimitRTPRIO", config_parse_limit, &(context).rlimit[RLIMIT_RTPRIO], section }, \
1221 { "LimitRTTIME", config_parse_limit, &(context).rlimit[RLIMIT_RTTIME], section }, \
1222 { "ControlGroup", config_parse_cgroup, u, section }, \
1223 { "ReadWriteDirectories", config_parse_path_strv, &(context).read_write_dirs, section }, \
1224 { "ReadOnlyDirectories", config_parse_path_strv, &(context).read_only_dirs, section }, \
1225 { "InaccessibleDirectories",config_parse_path_strv, &(context).inaccessible_dirs, section }, \
1226 { "PrivateTmp", config_parse_bool, &(context).private_tmp, section }, \
1227 { "MountFlags", config_parse_mount_flags, &(context), section }
1229 const ConfigItem items[] = {
1230 { "Names", config_parse_names, u, "Unit" },
1231 { "Description", config_parse_description, u, "Unit" },
1232 { "Requires", config_parse_deps, UINT_TO_PTR(UNIT_REQUIRES), "Unit" },
1233 { "RequiresOverridable", config_parse_deps, UINT_TO_PTR(UNIT_REQUIRES_OVERRIDABLE), "Unit" },
1234 { "Requisite", config_parse_deps, UINT_TO_PTR(UNIT_REQUISITE), "Unit" },
1235 { "RequisiteOverridable", config_parse_deps, UINT_TO_PTR(UNIT_REQUISITE_OVERRIDABLE), "Unit" },
1236 { "Wants", config_parse_deps, UINT_TO_PTR(UNIT_WANTS), "Unit" },
1237 { "Conflicts", config_parse_deps, UINT_TO_PTR(UNIT_CONFLICTS), "Unit" },
1238 { "Before", config_parse_deps, UINT_TO_PTR(UNIT_BEFORE), "Unit" },
1239 { "After", config_parse_deps, UINT_TO_PTR(UNIT_AFTER), "Unit" },
1240 { "RecursiveStop", config_parse_bool, &u->meta.recursive_stop, "Unit" },
1241 { "StopWhenUnneeded", config_parse_bool, &u->meta.stop_when_unneeded, "Unit" },
1243 { "PIDFile", config_parse_path, &u->service.pid_file, "Service" },
1244 { "ExecStartPre", config_parse_exec, u->service.exec_command+SERVICE_EXEC_START_PRE, "Service" },
1245 { "ExecStart", config_parse_exec, u->service.exec_command+SERVICE_EXEC_START, "Service" },
1246 { "ExecStartPost", config_parse_exec, u->service.exec_command+SERVICE_EXEC_START_POST, "Service" },
1247 { "ExecReload", config_parse_exec, u->service.exec_command+SERVICE_EXEC_RELOAD, "Service" },
1248 { "ExecStop", config_parse_exec, u->service.exec_command+SERVICE_EXEC_STOP, "Service" },
1249 { "ExecStopPost", config_parse_exec, u->service.exec_command+SERVICE_EXEC_STOP_POST, "Service" },
1250 { "RestartSec", config_parse_usec, &u->service.restart_usec, "Service" },
1251 { "TimeoutSec", config_parse_usec, &u->service.timeout_usec, "Service" },
1252 { "Type", config_parse_service_type, &u->service.type, "Service" },
1253 { "Restart", config_parse_service_restart, &u->service.restart, "Service" },
1254 { "PermissionsStartOnly", config_parse_bool, &u->service.permissions_start_only, "Service" },
1255 { "RootDirectoryStartOnly", config_parse_bool, &u->service.root_directory_start_only, "Service" },
1256 { "ValidNoProcess", config_parse_bool, &u->service.valid_no_process, "Service" },
1257 { "SysVStartPriority", config_parse_sysv_priority, &u->service.sysv_start_priority, "Service" },
1258 { "KillMode", config_parse_kill_mode, &u->service.kill_mode, "Service" },
1259 { "NonBlocking", config_parse_bool, &u->service.exec_context.non_blocking, "Service" },
1260 { "BusName", config_parse_string, &u->service.bus_name, "Service" },
1261 EXEC_CONTEXT_CONFIG_ITEMS(u->service.exec_context, "Service"),
1263 { "ListenStream", config_parse_listen, &u->socket, "Socket" },
1264 { "ListenDatagram", config_parse_listen, &u->socket, "Socket" },
1265 { "ListenSequentialPacket", config_parse_listen, &u->socket, "Socket" },
1266 { "ListenFIFO", config_parse_listen, &u->socket, "Socket" },
1267 { "BindIPv6Only", config_parse_socket_bind, &u->socket, "Socket" },
1268 { "Backlog", config_parse_unsigned, &u->socket.backlog, "Socket" },
1269 { "BindToDevice", config_parse_bindtodevice, &u->socket, "Socket" },
1270 { "ExecStartPre", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_START_PRE, "Socket" },
1271 { "ExecStartPost", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_START_POST, "Socket" },
1272 { "ExecStopPre", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_STOP_PRE, "Socket" },
1273 { "ExecStopPost", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_STOP_POST, "Socket" },
1274 { "TimeoutSec", config_parse_usec, &u->socket.timeout_usec, "Socket" },
1275 { "DirectoryMode", config_parse_mode, &u->socket.directory_mode, "Socket" },
1276 { "SocketMode", config_parse_mode, &u->socket.socket_mode, "Socket" },
1277 { "KillMode", config_parse_kill_mode, &u->socket.kill_mode, "Socket" },
1278 { "Accept", config_parse_bool, &u->socket.accept, "Socket" },
1279 EXEC_CONTEXT_CONFIG_ITEMS(u->socket.exec_context, "Socket"),
1281 { "What", config_parse_string, &u->mount.parameters_fragment.what, "Mount" },
1282 { "Where", config_parse_path, &u->mount.where, "Mount" },
1283 { "Options", config_parse_string, &u->mount.parameters_fragment.options, "Mount" },
1284 { "Type", config_parse_string, &u->mount.parameters_fragment.fstype, "Mount" },
1285 { "TimeoutSec", config_parse_usec, &u->mount.timeout_usec, "Mount" },
1286 { "KillMode", config_parse_kill_mode, &u->mount.kill_mode, "Mount" },
1287 EXEC_CONTEXT_CONFIG_ITEMS(u->mount.exec_context, "Mount"),
1289 { "Where", config_parse_path, &u->automount.where, "Automount" },
1291 { "What", config_parse_path, &u->swap.parameters_fragment.what, "Swap" },
1292 { "Priority", config_parse_int, &u->swap.parameters_fragment.priority, "Swap" },
1294 { NULL, NULL, NULL, NULL }
1297 #undef EXEC_CONTEXT_CONFIG_ITEMS
1299 const char *sections[3];
1304 char *filename = NULL, *id = NULL;
1308 /* Dirty dirty hack. */
1309 dump_items((FILE*) path, items);
1316 sections[0] = "Unit";
1317 sections[1] = section_table[u->meta.type];
1320 if (!(symlink_names = set_new(string_hash_func, string_compare_func)))
1323 if (path_is_absolute(path)) {
1325 if (!(filename = strdup(path))) {
1330 if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) {
1341 STRV_FOREACH(p, u->meta.manager->unit_path) {
1343 /* Instead of opening the path right away, we manually
1344 * follow all symlinks and add their name to our unit
1345 * name set while doing so */
1346 if (!(filename = path_make_absolute(path, *p))) {
1351 if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) {
1360 /* Empty the symlink names for the next run */
1361 while ((sn = set_steal_first(symlink_names)))
1377 if ((r = merge_by_names(&merged, symlink_names, id)) < 0)
1381 u->meta.load_state = UNIT_MERGED;
1386 /* Now, parse the file contents */
1387 if ((r = config_parse(filename, f, sections, items, u)) < 0)
1390 free(u->meta.fragment_path);
1391 u->meta.fragment_path = filename;
1394 u->meta.load_state = UNIT_LOADED;
1398 while ((k = set_steal_first(symlink_names)))
1401 set_free(symlink_names);
1410 int unit_load_fragment(Unit *u) {
1415 if (u->meta.fragment_path) {
1417 if ((r = load_from_path(u, u->meta.fragment_path)) < 0)
1424 /* Try to find the unit under its id */
1425 if ((r = load_from_path(u, u->meta.id)) < 0)
1428 /* Try to find an alias we can load this with */
1429 if (u->meta.load_state == UNIT_STUB)
1430 SET_FOREACH(t, u->meta.names, i) {
1432 if (t == u->meta.id)
1435 if ((r = load_from_path(u, t)) < 0)
1438 if (u->meta.load_state != UNIT_STUB)
1442 /* Now, follow the same logic, but look for a template */
1443 if (u->meta.load_state == UNIT_STUB && u->meta.instance) {
1446 if (!(k = unit_name_template(u->meta.id)))
1449 r = load_from_path(u, k);
1455 if (u->meta.load_state == UNIT_STUB)
1456 SET_FOREACH(t, u->meta.names, i) {
1458 if (t == u->meta.id)
1461 if (!(k = unit_name_template(t)))
1464 r = load_from_path(u, k);
1470 if (u->meta.load_state != UNIT_STUB)
1479 void unit_dump_config_items(FILE *f) {
1480 /* OK, this wins a prize for extreme ugliness. */
1482 load_from_path(NULL, (const void*) f);