1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
7 Copyright 2012 Holger Hans Peter Freyther
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 #include <linux/oom.h>
30 #include <sys/prctl.h>
31 #include <sys/mount.h>
35 #include <sys/resource.h>
37 #include "sd-messages.h"
40 #include "conf-parser.h"
41 #include "load-fragment.h"
44 #include "securebits.h"
46 #include "unit-name.h"
47 #include "unit-printf.h"
49 #include "path-util.h"
50 #include "syscall-list.h"
54 #include "bus-error.h"
56 #ifndef HAVE_SYSV_COMPAT
57 int config_parse_warn_compat(const char *unit,
61 unsigned section_line,
68 log_syntax(unit, LOG_DEBUG, filename, line, EINVAL,
69 "Support for option %s= has been disabled at compile time and is ignored",
75 int config_parse_unit_deps(const char* unit,
79 unsigned section_line,
86 UnitDependency d = ltype;
96 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
97 _cleanup_free_ char *t = NULL, *k = NULL;
104 r = unit_name_printf(u, t, &k);
106 log_syntax(unit, LOG_ERR, filename, line, -r,
107 "Failed to resolve specifiers, ignoring: %s", strerror(-r));
111 r = unit_add_dependency_by_name(u, d, k, NULL, true);
113 log_syntax(unit, LOG_ERR, filename, line, -r,
114 "Failed to add dependency on %s, ignoring: %s", k, strerror(-r));
120 int config_parse_unit_string_printf(const char *unit,
121 const char *filename,
124 unsigned section_line,
132 _cleanup_free_ char *k = NULL;
140 r = unit_full_printf(u, rvalue, &k);
142 log_syntax(unit, LOG_ERR, filename, line, -r,
143 "Failed to resolve unit specifiers on %s, ignoring: %s", rvalue, strerror(-r));
145 return config_parse_string(unit, filename, line, section, section_line, lvalue, ltype,
146 k ? k : rvalue, data, userdata);
149 int config_parse_unit_strv_printf(const char *unit,
150 const char *filename,
153 unsigned section_line,
161 _cleanup_free_ char *k = NULL;
169 r = unit_full_printf(u, rvalue, &k);
171 log_syntax(unit, LOG_ERR, filename, line, -r,
172 "Failed to resolve unit specifiers on %s, ignoring: %s", rvalue, strerror(-r));
174 return config_parse_strv(unit, filename, line, section, section_line, lvalue, ltype,
175 k ? k : rvalue, data, userdata);
178 int config_parse_unit_path_printf(const char *unit,
179 const char *filename,
182 unsigned section_line,
190 _cleanup_free_ char *k = NULL;
198 r = unit_full_printf(u, rvalue, &k);
200 log_syntax(unit, LOG_ERR, filename, line, -r,
201 "Failed to resolve unit specifiers on %s, ignoring: %s", rvalue, strerror(-r));
203 return config_parse_path(unit, filename, line, section, section_line, lvalue, ltype,
204 k ? k : rvalue, data, userdata);
207 int config_parse_socket_listen(const char *unit,
208 const char *filename,
211 unsigned section_line,
218 SocketPort *p, *tail;
229 if (isempty(rvalue)) {
230 /* An empty assignment removes all ports */
231 socket_free_ports(s);
235 p = new0(SocketPort, 1);
239 if (ltype != SOCKET_SOCKET) {
242 r = unit_full_printf(UNIT(s), rvalue, &p->path);
244 p->path = strdup(rvalue);
249 log_syntax(unit, LOG_ERR, filename, line, -r,
250 "Failed to resolve unit specifiers on %s, ignoring: %s", rvalue, strerror(-r));
253 path_kill_slashes(p->path);
255 } else if (streq(lvalue, "ListenNetlink")) {
256 _cleanup_free_ char *k = NULL;
258 p->type = SOCKET_SOCKET;
259 r = unit_full_printf(UNIT(s), rvalue, &k);
261 log_syntax(unit, LOG_ERR, filename, line, -r,
262 "Failed to resolve unit specifiers on %s, ignoring: %s", rvalue, strerror(-r));
264 r = socket_address_parse_netlink(&p->address, k ? k : rvalue);
266 log_syntax(unit, LOG_ERR, filename, line, -r,
267 "Failed to parse address value, ignoring: %s", rvalue);
273 _cleanup_free_ char *k = NULL;
275 p->type = SOCKET_SOCKET;
276 r = unit_full_printf(UNIT(s), rvalue, &k);
278 log_syntax(unit, LOG_ERR, filename, line, -r,
279 "Failed to resolve unit specifiers on %s, ignoring: %s", rvalue, strerror(-r));
281 r = socket_address_parse(&p->address, k ? k : rvalue);
283 log_syntax(unit, LOG_ERR, filename, line, -r,
284 "Failed to parse address value, ignoring: %s", rvalue);
289 if (streq(lvalue, "ListenStream"))
290 p->address.type = SOCK_STREAM;
291 else if (streq(lvalue, "ListenDatagram"))
292 p->address.type = SOCK_DGRAM;
294 assert(streq(lvalue, "ListenSequentialPacket"));
295 p->address.type = SOCK_SEQPACKET;
298 if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) {
299 log_syntax(unit, LOG_ERR, filename, line, ENOTSUP,
300 "Address family not supported, ignoring: %s", rvalue);
310 LIST_FIND_TAIL(port, s->ports, tail);
311 LIST_INSERT_AFTER(port, s->ports, tail, p);
313 LIST_PREPEND(port, s->ports, p);
318 int config_parse_socket_bind(const char *unit,
319 const char *filename,
322 unsigned section_line,
330 SocketAddressBindIPv6Only b;
339 b = socket_address_bind_ipv6_only_from_string(rvalue);
343 r = parse_boolean(rvalue);
345 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
346 "Failed to parse bind IPv6 only value, ignoring: %s", rvalue);
350 s->bind_ipv6_only = r ? SOCKET_ADDRESS_IPV6_ONLY : SOCKET_ADDRESS_BOTH;
352 s->bind_ipv6_only = b;
357 int config_parse_exec_nice(const char *unit,
358 const char *filename,
361 unsigned section_line,
368 ExecContext *c = data;
376 r = safe_atoi(rvalue, &priority);
378 log_syntax(unit, LOG_ERR, filename, line, -r,
379 "Failed to parse nice priority, ignoring: %s. ", rvalue);
383 if (priority < PRIO_MIN || priority >= PRIO_MAX) {
384 log_syntax(unit, LOG_ERR, filename, line, ERANGE,
385 "Nice priority out of range, ignoring: %s", rvalue);
395 int config_parse_exec_oom_score_adjust(const char* unit,
396 const char *filename,
399 unsigned section_line,
406 ExecContext *c = data;
414 r = safe_atoi(rvalue, &oa);
416 log_syntax(unit, LOG_ERR, filename, line, -r,
417 "Failed to parse the OOM score adjust value, ignoring: %s", rvalue);
421 if (oa < OOM_SCORE_ADJ_MIN || oa > OOM_SCORE_ADJ_MAX) {
422 log_syntax(unit, LOG_ERR, filename, line, ERANGE,
423 "OOM score adjust value out of range, ignoring: %s", rvalue);
427 c->oom_score_adjust = oa;
428 c->oom_score_adjust_set = true;
433 int config_parse_exec(const char *unit,
434 const char *filename,
437 unsigned section_line,
444 ExecCommand **e = data, *nce;
456 if (isempty(rvalue)) {
457 /* An empty assignment resets the list */
458 exec_command_free_list(*e);
463 /* We accept an absolute path as first argument, or
464 * alternatively an absolute prefixed with @ to allow
465 * overriding of argv[0]. */
471 bool honour_argv0 = false, ignore = false;
477 rvalue += strspn(rvalue, WHITESPACE);
482 for (i = 0; i < 2; i++) {
483 if (rvalue[0] == '-' && !ignore) {
488 if (rvalue[0] == '@' && !honour_argv0) {
494 if (*rvalue != '/') {
495 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
496 "Executable path is not absolute, ignoring: %s", rvalue);
501 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
502 if (strneq(w, ";", MAX(l, 1U)))
508 n = new(char*, k + !honour_argv0);
513 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
514 if (strneq(w, ";", MAX(l, 1U)))
516 else if (strneq(w, "\\;", MAX(l, 1U)))
519 if (honour_argv0 && w == rvalue) {
522 path = strndup(w, l);
528 if (!utf8_is_valid(path)) {
529 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
530 "Path is not UTF-8 clean, ignoring assignment: %s",
539 c = n[k++] = cunescape_length(w, l);
545 if (!utf8_is_valid(c)) {
546 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
547 "Path is not UTF-8 clean, ignoring assignment: %s",
558 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
559 "Invalid command line, ignoring: %s", rvalue);
572 assert(path_is_absolute(path));
574 nce = new0(ExecCommand, 1);
582 nce->ignore = ignore;
584 path_kill_slashes(nce->path);
586 exec_command_append_list(e, nce);
602 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type");
603 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier");
605 int config_parse_socket_bindtodevice(const char* unit,
606 const char *filename,
609 unsigned section_line,
624 if (rvalue[0] && !streq(rvalue, "*")) {
631 free(s->bind_to_device);
632 s->bind_to_device = n;
637 DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output specifier");
638 DEFINE_CONFIG_PARSE_ENUM(config_parse_input, exec_input, ExecInput, "Failed to parse input specifier");
640 int config_parse_exec_io_class(const char *unit,
641 const char *filename,
644 unsigned section_line,
651 ExecContext *c = data;
659 x = ioprio_class_from_string(rvalue);
661 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
662 "Failed to parse IO scheduling class, ignoring: %s", rvalue);
666 c->ioprio = IOPRIO_PRIO_VALUE(x, IOPRIO_PRIO_DATA(c->ioprio));
667 c->ioprio_set = true;
672 int config_parse_exec_io_priority(const char *unit,
673 const char *filename,
676 unsigned section_line,
683 ExecContext *c = data;
691 r = safe_atoi(rvalue, &i);
692 if (r < 0 || i < 0 || i >= IOPRIO_BE_NR) {
693 log_syntax(unit, LOG_ERR, filename, line, -r,
694 "Failed to parse IO priority, ignoring: %s", rvalue);
698 c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), i);
699 c->ioprio_set = true;
704 int config_parse_exec_cpu_sched_policy(const char *unit,
705 const char *filename,
708 unsigned section_line,
716 ExecContext *c = data;
724 x = sched_policy_from_string(rvalue);
726 log_syntax(unit, LOG_ERR, filename, line, -x,
727 "Failed to parse CPU scheduling policy, ignoring: %s", rvalue);
731 c->cpu_sched_policy = x;
732 /* Moving to or from real-time policy? We need to adjust the priority */
733 c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(x), sched_get_priority_max(x));
734 c->cpu_sched_set = true;
739 int config_parse_exec_cpu_sched_prio(const char *unit,
740 const char *filename,
743 unsigned section_line,
750 ExecContext *c = data;
758 r = safe_atoi(rvalue, &i);
760 log_syntax(unit, LOG_ERR, filename, line, -r,
761 "Failed to parse CPU scheduling policy, ignoring: %s", rvalue);
765 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
766 min = sched_get_priority_min(c->cpu_sched_policy);
767 max = sched_get_priority_max(c->cpu_sched_policy);
769 if (i < min || i > max) {
770 log_syntax(unit, LOG_ERR, filename, line, ERANGE,
771 "CPU scheduling priority is out of range, ignoring: %s", rvalue);
775 c->cpu_sched_priority = i;
776 c->cpu_sched_set = true;
781 int config_parse_exec_cpu_affinity(const char *unit,
782 const char *filename,
785 unsigned section_line,
792 ExecContext *c = data;
802 if (isempty(rvalue)) {
803 /* An empty assignment resets the CPU list */
810 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
811 _cleanup_free_ char *t = NULL;
819 r = safe_atou(t, &cpu);
822 c->cpuset = cpu_set_malloc(&c->cpuset_ncpus);
827 if (r < 0 || cpu >= c->cpuset_ncpus) {
828 log_syntax(unit, LOG_ERR, filename, line, ERANGE,
829 "Failed to parse CPU affinity '%s', ignoring: %s", t, rvalue);
833 CPU_SET_S(cpu, CPU_ALLOC_SIZE(c->cpuset_ncpus), c->cpuset);
839 int config_parse_exec_capabilities(const char *unit,
840 const char *filename,
843 unsigned section_line,
850 ExecContext *c = data;
858 cap = cap_from_text(rvalue);
860 log_syntax(unit, LOG_ERR, filename, line, errno,
861 "Failed to parse capabilities, ignoring: %s", rvalue);
866 cap_free(c->capabilities);
867 c->capabilities = cap;
872 int config_parse_exec_secure_bits(const char *unit,
873 const char *filename,
876 unsigned section_line,
883 ExecContext *c = data;
893 if (isempty(rvalue)) {
894 /* An empty assignment resets the field */
899 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
900 if (first_word(w, "keep-caps"))
901 c->secure_bits |= 1<<SECURE_KEEP_CAPS;
902 else if (first_word(w, "keep-caps-locked"))
903 c->secure_bits |= 1<<SECURE_KEEP_CAPS_LOCKED;
904 else if (first_word(w, "no-setuid-fixup"))
905 c->secure_bits |= 1<<SECURE_NO_SETUID_FIXUP;
906 else if (first_word(w, "no-setuid-fixup-locked"))
907 c->secure_bits |= 1<<SECURE_NO_SETUID_FIXUP_LOCKED;
908 else if (first_word(w, "noroot"))
909 c->secure_bits |= 1<<SECURE_NOROOT;
910 else if (first_word(w, "noroot-locked"))
911 c->secure_bits |= 1<<SECURE_NOROOT_LOCKED;
913 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
914 "Failed to parse secure bits, ignoring: %s", rvalue);
922 int config_parse_bounding_set(const char *unit,
923 const char *filename,
926 unsigned section_line,
933 uint64_t *capability_bounding_set_drop = data;
945 if (rvalue[0] == '~') {
950 /* Note that we store this inverted internally, since the
951 * kernel wants it like this. But we actually expose it
952 * non-inverted everywhere to have a fully normalized
955 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
956 _cleanup_free_ char *t = NULL;
964 r = cap_from_name(t, &cap);
966 log_syntax(unit, LOG_ERR, filename, line, errno,
967 "Failed to parse capability in bounding set, ignoring: %s", t);
971 sum |= ((uint64_t) 1ULL) << (uint64_t) cap;
975 *capability_bounding_set_drop |= sum;
977 *capability_bounding_set_drop |= ~sum;
982 int config_parse_limit(const char *unit,
983 const char *filename,
986 unsigned section_line,
993 struct rlimit **rl = data;
994 unsigned long long u;
1003 if (streq(rvalue, "infinity"))
1004 u = (unsigned long long) RLIM_INFINITY;
1008 r = safe_atollu(rvalue, &u);
1010 log_syntax(unit, LOG_ERR, filename, line, -r,
1011 "Failed to parse resource value, ignoring: %s", rvalue);
1017 *rl = new(struct rlimit, 1);
1022 (*rl)->rlim_cur = (*rl)->rlim_max = (rlim_t) u;
1026 #ifdef HAVE_SYSV_COMPAT
1027 int config_parse_sysv_priority(const char *unit,
1028 const char *filename,
1030 const char *section,
1031 unsigned section_line,
1038 int *priority = data;
1046 r = safe_atoi(rvalue, &i);
1047 if (r < 0 || i < 0) {
1048 log_syntax(unit, LOG_ERR, filename, line, -r,
1049 "Failed to parse SysV start priority, ignoring: %s", rvalue);
1053 *priority = (int) i;
1058 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode");
1060 int config_parse_kill_signal(const char *unit,
1061 const char *filename,
1063 const char *section,
1064 unsigned section_line,
1079 r = signal_from_string_try_harder(rvalue);
1081 log_syntax(unit, LOG_ERR, filename, line, -r,
1082 "Failed to parse kill signal, ignoring: %s", rvalue);
1090 int config_parse_exec_mount_flags(const char *unit,
1091 const char *filename,
1093 const char *section,
1094 unsigned section_line,
1101 ExecContext *c = data;
1105 unsigned long flags = 0;
1112 FOREACH_WORD_SEPARATOR(w, l, rvalue, ", ", state) {
1113 _cleanup_free_ char *t;
1119 if (streq(t, "shared"))
1121 else if (streq(t, "slave"))
1123 else if (streq(w, "private"))
1124 flags |= MS_PRIVATE;
1126 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1127 "Failed to parse mount flag %s, ignoring: %s",
1133 c->mount_flags = flags;
1137 int config_parse_timer(const char *unit,
1138 const char *filename,
1140 const char *section,
1141 unsigned section_line,
1152 CalendarSpec *c = NULL;
1160 if (isempty(rvalue)) {
1161 /* Empty assignment resets list */
1162 timer_free_values(t);
1166 b = timer_base_from_string(lvalue);
1168 log_syntax(unit, LOG_ERR, filename, line, -b,
1169 "Failed to parse timer base, ignoring: %s", lvalue);
1173 if (b == TIMER_CALENDAR) {
1174 if (calendar_spec_from_string(rvalue, &c) < 0) {
1175 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1176 "Failed to parse calendar specification, ignoring: %s",
1181 id = CLOCK_REALTIME;
1183 if (parse_sec(rvalue, &u) < 0) {
1184 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1185 "Failed to parse timer value, ignoring: %s",
1190 id = CLOCK_MONOTONIC;
1193 v = new0(TimerValue, 1);
1200 v->calendar_spec = c;
1202 LIST_PREPEND(value, t->values, v);
1207 int config_parse_trigger_unit(
1209 const char *filename,
1211 const char *section,
1212 unsigned section_line,
1219 _cleanup_free_ char *p = NULL;
1229 if (!set_isempty(u->dependencies[UNIT_TRIGGERS])) {
1230 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1231 "Multiple units to trigger specified, ignoring: %s", rvalue);
1235 r = unit_name_printf(u, rvalue, &p);
1237 log_syntax(unit, LOG_ERR, filename, line, -r,
1238 "Failed to resolve specifiers, ignoring: %s", strerror(-r));
1240 type = unit_name_to_type(p ?: rvalue);
1242 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1243 "Unit type not valid, ignoring: %s", rvalue);
1247 if (type == u->type) {
1248 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1249 "Trigger cannot be of same type, ignoring: %s", rvalue);
1253 r = unit_add_two_dependencies_by_name(u, UNIT_BEFORE, UNIT_TRIGGERS, p ?: rvalue, NULL, true);
1255 log_syntax(unit, LOG_ERR, filename, line, -r,
1256 "Failed to add trigger on %s, ignoring: %s", p ?: rvalue, strerror(-r));
1263 int config_parse_path_spec(const char *unit,
1264 const char *filename,
1266 const char *section,
1267 unsigned section_line,
1277 _cleanup_free_ char *k = NULL;
1285 if (isempty(rvalue)) {
1286 /* Empty assignment clears list */
1291 b = path_type_from_string(lvalue);
1293 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1294 "Failed to parse path type, ignoring: %s", lvalue);
1298 r = unit_full_printf(UNIT(p), rvalue, &k);
1304 log_syntax(unit, LOG_ERR, filename, line, -r,
1305 "Failed to resolve unit specifiers on %s. Ignoring.",
1309 if (!path_is_absolute(k)) {
1310 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1311 "Path is not absolute, ignoring: %s", k);
1315 s = new0(PathSpec, 1);
1320 s->path = path_kill_slashes(k);
1325 LIST_PREPEND(spec, p->specs, s);
1330 int config_parse_socket_service(const char *unit,
1331 const char *filename,
1333 const char *section,
1334 unsigned section_line,
1341 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
1345 _cleanup_free_ char *p = NULL;
1352 r = unit_name_printf(UNIT(s), rvalue, &p);
1354 log_syntax(unit, LOG_ERR, filename, line, -r, "Failed to resolve specifiers, ignoring: %s", rvalue);
1356 if (!endswith(p ?: rvalue, ".service")) {
1357 log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Unit must be of type service, ignoring: %s", rvalue);
1361 r = manager_load_unit(UNIT(s)->manager, p ?: rvalue, NULL, &error, &x);
1363 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to load unit %s, ignoring: %s", rvalue, bus_error_message(&error, r));
1367 unit_ref_set(&s->service, x);
1372 int config_parse_service_sockets(const char *unit,
1373 const char *filename,
1375 const char *section,
1376 unsigned section_line,
1393 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1394 _cleanup_free_ char *t = NULL, *k = NULL;
1400 r = unit_name_printf(UNIT(s), t, &k);
1402 log_syntax(unit, LOG_ERR, filename, line, -r,
1403 "Failed to resolve specifiers, ignoring: %s", strerror(-r));
1405 if (!endswith(k ?: t, ".socket")) {
1406 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1407 "Unit must be of type socket, ignoring: %s", k ?: t);
1411 r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_WANTS, UNIT_AFTER, k ?: t, NULL, true);
1413 log_syntax(unit, LOG_ERR, filename, line, -r,
1414 "Failed to add dependency on %s, ignoring: %s",
1415 k ?: t, strerror(-r));
1417 r = unit_add_dependency_by_name(UNIT(s), UNIT_TRIGGERED_BY, k ?: t, NULL, true);
1425 int config_parse_service_timeout(const char *unit,
1426 const char *filename,
1428 const char *section,
1429 unsigned section_line,
1436 Service *s = userdata;
1444 r = config_parse_sec(unit, filename, line, section, section_line, lvalue, ltype,
1445 rvalue, data, userdata);
1449 if (streq(lvalue, "TimeoutSec")) {
1450 s->start_timeout_defined = true;
1451 s->timeout_stop_usec = s->timeout_start_usec;
1452 } else if (streq(lvalue, "TimeoutStartSec"))
1453 s->start_timeout_defined = true;
1458 int config_parse_unit_env_file(const char *unit,
1459 const char *filename,
1461 const char *section,
1462 unsigned section_line,
1471 _cleanup_free_ char *n = NULL;
1480 if (isempty(rvalue)) {
1481 /* Empty assignment frees the list */
1487 r = unit_full_printf(u, rvalue, &n);
1489 log_syntax(unit, LOG_ERR, filename, line, r,
1490 "Failed to resolve specifiers, ignoring: %s", rvalue);
1493 if (!path_is_absolute(s[0] == '-' ? s + 1 : s)) {
1494 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1495 "Path '%s' is not absolute, ignoring.", s);
1499 r = strv_extend(env, s);
1506 int config_parse_environ(const char *unit,
1507 const char *filename,
1509 const char *section,
1510 unsigned section_line,
1518 char*** env = data, *w, *state;
1520 _cleanup_free_ char *k = NULL;
1528 if (isempty(rvalue)) {
1529 /* Empty assignment resets the list */
1536 r = unit_full_printf(u, rvalue, &k);
1538 log_syntax(unit, LOG_ERR, filename, line, -r,
1539 "Failed to resolve specifiers, ignoring: %s", rvalue);
1547 FOREACH_WORD_QUOTED(w, l, k, state) {
1548 _cleanup_free_ char *n;
1551 n = cunescape_length(w, l);
1555 if (!env_assignment_is_valid(n)) {
1556 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1557 "Invalid environment assignment, ignoring: %s", rvalue);
1561 x = strv_env_set(*env, n);
1572 int config_parse_ip_tos(const char *unit,
1573 const char *filename,
1575 const char *section,
1576 unsigned section_line,
1583 int *ip_tos = data, x;
1590 x = ip_tos_from_string(rvalue);
1592 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1593 "Failed to parse IP TOS value, ignoring: %s", rvalue);
1601 int config_parse_unit_condition_path(const char *unit,
1602 const char *filename,
1604 const char *section,
1605 unsigned section_line,
1612 ConditionType cond = ltype;
1614 bool trigger, negate;
1616 _cleanup_free_ char *p = NULL;
1624 if (isempty(rvalue)) {
1625 /* Empty assignment resets the list */
1626 condition_free_list(u->conditions);
1627 u->conditions = NULL;
1631 trigger = rvalue[0] == '|';
1635 negate = rvalue[0] == '!';
1639 r = unit_full_printf(u, rvalue, &p);
1641 log_syntax(unit, LOG_ERR, filename, line, -r,
1642 "Failed to resolve specifiers, ignoring: %s", rvalue);
1649 if (!path_is_absolute(p)) {
1650 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1651 "Path in condition not absolute, ignoring: %s", p);
1655 c = condition_new(cond, p, trigger, negate);
1659 LIST_PREPEND(conditions, u->conditions, c);
1663 int config_parse_unit_condition_string(const char *unit,
1664 const char *filename,
1666 const char *section,
1667 unsigned section_line,
1674 ConditionType cond = ltype;
1676 bool trigger, negate;
1678 _cleanup_free_ char *s = NULL;
1686 if (isempty(rvalue)) {
1687 /* Empty assignment resets the list */
1688 condition_free_list(u->conditions);
1689 u->conditions = NULL;
1693 trigger = rvalue[0] == '|';
1697 negate = rvalue[0] == '!';
1701 r = unit_full_printf(u, rvalue, &s);
1703 log_syntax(unit, LOG_ERR, filename, line, -r,
1704 "Failed to resolve specifiers, ignoring: %s", rvalue);
1711 c = condition_new(cond, s, trigger, negate);
1715 LIST_PREPEND(conditions, u->conditions, c);
1719 int config_parse_unit_condition_null(const char *unit,
1720 const char *filename,
1722 const char *section,
1723 unsigned section_line,
1732 bool trigger, negate;
1740 if (isempty(rvalue)) {
1741 /* Empty assignment resets the list */
1742 condition_free_list(u->conditions);
1743 u->conditions = NULL;
1747 trigger = rvalue[0] == '|';
1751 negate = rvalue[0] == '!';
1755 b = parse_boolean(rvalue);
1757 log_syntax(unit, LOG_ERR, filename, line, -b,
1758 "Failed to parse boolean value in condition, ignoring: %s",
1766 c = condition_new(CONDITION_NULL, NULL, trigger, negate);
1770 LIST_PREPEND(conditions, u->conditions, c);
1774 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier");
1775 DEFINE_CONFIG_PARSE_ENUM(config_parse_start_limit_action, start_limit_action, StartLimitAction, "Failed to parse start limit action specifier");
1777 int config_parse_unit_requires_mounts_for(
1779 const char *filename,
1781 const char *section,
1782 unsigned section_line,
1799 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1801 _cleanup_free_ char *n;
1807 if (!utf8_is_valid(n)) {
1808 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1809 "Path is not UTF-8 clean, ignoring assignment: %s", rvalue);
1813 r = unit_require_mounts_for(u, n);
1815 log_syntax(unit, LOG_ERR, filename, line, r,
1816 "Failed to add required mount for, ignoring: %s", rvalue);
1824 int config_parse_documentation(const char *unit,
1825 const char *filename,
1827 const char *section,
1828 unsigned section_line,
1844 if (isempty(rvalue)) {
1845 /* Empty assignment resets the list */
1846 strv_free(u->documentation);
1847 u->documentation = NULL;
1851 r = config_parse_unit_strv_printf(unit, filename, line, section, section_line, lvalue, ltype,
1852 rvalue, data, userdata);
1856 for (a = b = u->documentation; a && *a; a++) {
1858 if (is_valid_documentation_url(*a))
1861 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1862 "Invalid URL, ignoring: %s", *a);
1872 static void syscall_set(uint32_t *p, int nr) {
1873 nr = SYSCALL_TO_INDEX(nr);
1874 p[nr >> 4] |= 1 << (nr & 31);
1877 static void syscall_unset(uint32_t *p, int nr) {
1878 nr = SYSCALL_TO_INDEX(nr);
1879 p[nr >> 4] &= ~(1 << (nr & 31));
1882 int config_parse_syscall_filter(const char *unit,
1883 const char *filename,
1885 const char *section,
1886 unsigned section_line,
1893 ExecContext *c = data;
1895 bool invert = false;
1905 if (isempty(rvalue)) {
1906 /* Empty assignment resets the list */
1907 free(c->syscall_filter);
1908 c->syscall_filter = NULL;
1912 if (rvalue[0] == '~') {
1917 if (!c->syscall_filter) {
1920 n = (syscall_max() + 31) >> 4;
1921 c->syscall_filter = new(uint32_t, n);
1922 if (!c->syscall_filter)
1925 memset(c->syscall_filter, invert ? 0xFF : 0, n * sizeof(uint32_t));
1927 /* Add these by default */
1928 syscall_set(c->syscall_filter, __NR_execve);
1929 syscall_set(c->syscall_filter, __NR_rt_sigreturn);
1930 #ifdef __NR_sigreturn
1931 syscall_set(c->syscall_filter, __NR_sigreturn);
1933 syscall_set(c->syscall_filter, __NR_exit_group);
1934 syscall_set(c->syscall_filter, __NR_exit);
1937 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1939 _cleanup_free_ char *t = NULL;
1945 id = syscall_from_name(t);
1947 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
1948 "Failed to parse syscall, ignoring: %s", t);
1953 syscall_unset(c->syscall_filter, id);
1955 syscall_set(c->syscall_filter, id);
1958 c->no_new_privileges = true;
1963 int config_parse_unit_slice(
1965 const char *filename,
1967 const char *section,
1968 unsigned section_line,
1975 _cleanup_free_ char *k = NULL;
1976 Unit *u = userdata, *slice;
1984 r = unit_name_printf(u, rvalue, &k);
1986 log_syntax(unit, LOG_ERR, filename, line, -r,
1987 "Failed to resolve unit specifiers on %s. Ignoring.", rvalue);
1994 r = manager_load_unit(u->manager, k, NULL, NULL, &slice);
1996 log_syntax(unit, LOG_ERR, filename, line, -r,
1997 "Failed to load slice unit %s. Ignoring.", k);
2001 if (slice->type != UNIT_SLICE) {
2002 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2003 "Slice unit %s is not a slice. Ignoring.", k);
2007 unit_ref_set(&u->slice, slice);
2011 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy, cgroup_device_policy, CGroupDevicePolicy, "Failed to parse device policy");
2013 int config_parse_cpu_shares(
2015 const char *filename,
2017 const char *section,
2018 unsigned section_line,
2025 CGroupContext *c = data;
2033 if (isempty(rvalue)) {
2034 c->cpu_shares = 1024;
2038 r = safe_atolu(rvalue, &lu);
2039 if (r < 0 || lu <= 0) {
2040 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2041 "CPU shares '%s' invalid. Ignoring.", rvalue);
2049 int config_parse_memory_limit(
2051 const char *filename,
2053 const char *section,
2054 unsigned section_line,
2061 CGroupContext *c = data;
2065 if (isempty(rvalue)) {
2066 c->memory_limit = (uint64_t) -1;
2070 assert_cc(sizeof(uint64_t) == sizeof(off_t));
2072 r = parse_bytes(rvalue, &bytes);
2074 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2075 "Memory limit '%s' invalid. Ignoring.", rvalue);
2079 c->memory_limit = (uint64_t) bytes;
2083 int config_parse_device_allow(
2085 const char *filename,
2087 const char *section,
2088 unsigned section_line,
2095 _cleanup_free_ char *path = NULL;
2096 CGroupContext *c = data;
2097 CGroupDeviceAllow *a;
2101 if (isempty(rvalue)) {
2102 while (c->device_allow)
2103 cgroup_context_free_device_allow(c, c->device_allow);
2108 n = strcspn(rvalue, WHITESPACE);
2109 path = strndup(rvalue, n);
2113 if (!path_startswith(path, "/dev")) {
2114 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2115 "Invalid device node path '%s'. Ignoring.", path);
2119 m = rvalue + n + strspn(rvalue + n, WHITESPACE);
2123 if (!in_charset(m, "rwm")) {
2124 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2125 "Invalid device rights '%s'. Ignoring.", m);
2129 a = new0(CGroupDeviceAllow, 1);
2135 a->r = !!strchr(m, 'r');
2136 a->w = !!strchr(m, 'w');
2137 a->m = !!strchr(m, 'm');
2139 LIST_PREPEND(device_allow, c->device_allow, a);
2143 int config_parse_blockio_weight(
2145 const char *filename,
2147 const char *section,
2148 unsigned section_line,
2155 CGroupContext *c = data;
2163 if (isempty(rvalue)) {
2164 c->blockio_weight = 1000;
2168 r = safe_atolu(rvalue, &lu);
2169 if (r < 0 || lu < 10 || lu > 1000) {
2170 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2171 "Block IO weight '%s' invalid. Ignoring.", rvalue);
2175 c->blockio_weight = lu;
2180 int config_parse_blockio_device_weight(
2182 const char *filename,
2184 const char *section,
2185 unsigned section_line,
2192 _cleanup_free_ char *path = NULL;
2193 CGroupBlockIODeviceWeight *w;
2194 CGroupContext *c = data;
2204 if (isempty(rvalue)) {
2205 while (c->blockio_device_weights)
2206 cgroup_context_free_blockio_device_weight(c, c->blockio_device_weights);
2211 n = strcspn(rvalue, WHITESPACE);
2212 weight = rvalue + n;
2214 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2215 "Expected block device and device weight. Ignoring.");
2219 path = strndup(rvalue, n);
2223 if (!path_startswith(path, "/dev")) {
2224 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2225 "Invalid device node path '%s'. Ignoring.", path);
2229 weight += strspn(weight, WHITESPACE);
2230 r = safe_atolu(weight, &lu);
2231 if (r < 0 || lu < 10 || lu > 1000) {
2232 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2233 "Block IO weight '%s' invalid. Ignoring.", rvalue);
2238 w = new0(CGroupBlockIODeviceWeight, 1);
2247 LIST_PREPEND(device_weights, c->blockio_device_weights, w);
2251 int config_parse_blockio_bandwidth(
2253 const char *filename,
2255 const char *section,
2256 unsigned section_line,
2263 _cleanup_free_ char *path = NULL;
2264 CGroupBlockIODeviceBandwidth *b;
2265 CGroupContext *c = data;
2266 const char *bandwidth;
2276 read = streq("BlockIOReadBandwidth", lvalue);
2278 if (isempty(rvalue)) {
2279 CGroupBlockIODeviceBandwidth *next;
2281 LIST_FOREACH_SAFE (device_bandwidths, b, next, c->blockio_device_bandwidths)
2282 if (b->read == read)
2283 cgroup_context_free_blockio_device_bandwidth(c, b);
2288 n = strcspn(rvalue, WHITESPACE);
2289 bandwidth = rvalue + n;
2290 bandwidth += strspn(bandwidth, WHITESPACE);
2293 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2294 "Expected space separated pair of device node and bandwidth. Ignoring.");
2298 path = strndup(rvalue, n);
2302 if (!path_startswith(path, "/dev")) {
2303 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2304 "Invalid device node path '%s'. Ignoring.", path);
2308 r = parse_bytes(bandwidth, &bytes);
2309 if (r < 0 || bytes <= 0) {
2310 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2311 "Block IO Bandwidth '%s' invalid. Ignoring.", rvalue);
2315 b = new0(CGroupBlockIODeviceBandwidth, 1);
2321 b->bandwidth = (uint64_t) bytes;
2324 LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, b);
2329 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode, job_mode, JobMode, "Failed to parse job mode");
2331 int config_parse_job_mode_isolate(
2333 const char *filename,
2335 const char *section,
2336 unsigned section_line,
2350 r = parse_boolean(rvalue);
2352 log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Failed to parse boolean, ignoring: %s", rvalue);
2356 *m = r ? JOB_ISOLATE : JOB_REPLACE;
2360 #define FOLLOW_MAX 8
2362 static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
2373 /* This will update the filename pointer if the loaded file is
2374 * reached by a symlink. The old string will be freed. */
2377 char *target, *name;
2379 if (c++ >= FOLLOW_MAX)
2382 path_kill_slashes(*filename);
2384 /* Add the file name we are currently looking at to
2385 * the names of this unit, but only if it is a valid
2387 name = path_get_file_name(*filename);
2389 if (unit_name_is_valid(name, true)) {
2391 id = set_get(names, name);
2397 r = set_consume(names, id);
2403 /* Try to open the file name, but don't if its a symlink */
2404 fd = open(*filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
2411 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
2412 r = readlink_and_make_absolute(*filename, &target);
2420 f = fdopen(fd, "re");
2423 close_nointr_nofail(fd);
2432 static int merge_by_names(Unit **u, Set *names, const char *id) {
2440 /* Let's try to add in all symlink names we found */
2441 while ((k = set_steal_first(names))) {
2443 /* First try to merge in the other name into our
2445 r = unit_merge_by_name(*u, k);
2449 /* Hmm, we couldn't merge the other unit into
2450 * ours? Then let's try it the other way
2453 other = manager_get_unit((*u)->manager, k);
2457 r = unit_merge(other, *u);
2460 return merge_by_names(u, names, NULL);
2468 unit_choose_id(*u, id);
2476 static int load_from_path(Unit *u, const char *path) {
2478 _cleanup_set_free_free_ Set *symlink_names = NULL;
2479 _cleanup_fclose_ FILE *f = NULL;
2480 _cleanup_free_ char *filename = NULL;
2488 symlink_names = set_new(string_hash_func, string_compare_func);
2492 if (path_is_absolute(path)) {
2494 filename = strdup(path);
2498 r = open_follow(&filename, &f, symlink_names, &id);
2510 STRV_FOREACH(p, u->manager->lookup_paths.unit_path) {
2512 /* Instead of opening the path right away, we manually
2513 * follow all symlinks and add their name to our unit
2514 * name set while doing so */
2515 filename = path_make_absolute(path, *p);
2519 if (u->manager->unit_path_cache &&
2520 !set_get(u->manager->unit_path_cache, filename))
2523 r = open_follow(&filename, &f, symlink_names, &id);
2532 /* Empty the symlink names for the next run */
2533 set_clear_free(symlink_names);
2542 /* Hmm, no suitable file found? */
2546 r = merge_by_names(&merged, symlink_names, id);
2551 u->load_state = UNIT_MERGED;
2555 if (fstat(fileno(f), &st) < 0)
2558 if (null_or_empty(&st))
2559 u->load_state = UNIT_MASKED;
2561 u->load_state = UNIT_LOADED;
2563 /* Now, parse the file contents */
2564 r = config_parse(u->id, filename, f, UNIT_VTABLE(u)->sections,
2565 config_item_perf_lookup,
2566 (void*) load_fragment_gperf_lookup, false, true, u);
2571 free(u->fragment_path);
2572 u->fragment_path = filename;
2575 u->fragment_mtime = timespec_load(&st.st_mtim);
2577 if (u->source_path) {
2578 if (stat(u->source_path, &st) >= 0)
2579 u->source_mtime = timespec_load(&st.st_mtim);
2581 u->source_mtime = 0;
2587 int unit_load_fragment(Unit *u) {
2593 assert(u->load_state == UNIT_STUB);
2596 /* First, try to find the unit under its id. We always look
2597 * for unit files in the default directories, to make it easy
2598 * to override things by placing things in /etc/systemd/system */
2599 r = load_from_path(u, u->id);
2603 /* Try to find an alias we can load this with */
2604 if (u->load_state == UNIT_STUB)
2605 SET_FOREACH(t, u->names, i) {
2610 r = load_from_path(u, t);
2614 if (u->load_state != UNIT_STUB)
2618 /* And now, try looking for it under the suggested (originally linked) path */
2619 if (u->load_state == UNIT_STUB && u->fragment_path) {
2621 r = load_from_path(u, u->fragment_path);
2625 if (u->load_state == UNIT_STUB) {
2626 /* Hmm, this didn't work? Then let's get rid
2627 * of the fragment path stored for us, so that
2628 * we don't point to an invalid location. */
2629 free(u->fragment_path);
2630 u->fragment_path = NULL;
2634 /* Look for a template */
2635 if (u->load_state == UNIT_STUB && u->instance) {
2638 k = unit_name_template(u->id);
2642 r = load_from_path(u, k);
2648 if (u->load_state == UNIT_STUB)
2649 SET_FOREACH(t, u->names, i) {
2654 k = unit_name_template(t);
2658 r = load_from_path(u, k);
2664 if (u->load_state != UNIT_STUB)
2672 void unit_dump_config_items(FILE *f) {
2673 static const struct {
2674 const ConfigParserCallback callback;
2677 { config_parse_int, "INTEGER" },
2678 { config_parse_unsigned, "UNSIGNED" },
2679 { config_parse_bytes_size, "SIZE" },
2680 { config_parse_bool, "BOOLEAN" },
2681 { config_parse_string, "STRING" },
2682 { config_parse_path, "PATH" },
2683 { config_parse_unit_path_printf, "PATH" },
2684 { config_parse_strv, "STRING [...]" },
2685 { config_parse_exec_nice, "NICE" },
2686 { config_parse_exec_oom_score_adjust, "OOMSCOREADJUST" },
2687 { config_parse_exec_io_class, "IOCLASS" },
2688 { config_parse_exec_io_priority, "IOPRIORITY" },
2689 { config_parse_exec_cpu_sched_policy, "CPUSCHEDPOLICY" },
2690 { config_parse_exec_cpu_sched_prio, "CPUSCHEDPRIO" },
2691 { config_parse_exec_cpu_affinity, "CPUAFFINITY" },
2692 { config_parse_mode, "MODE" },
2693 { config_parse_unit_env_file, "FILE" },
2694 { config_parse_output, "OUTPUT" },
2695 { config_parse_input, "INPUT" },
2696 { config_parse_facility, "FACILITY" },
2697 { config_parse_level, "LEVEL" },
2698 { config_parse_exec_capabilities, "CAPABILITIES" },
2699 { config_parse_exec_secure_bits, "SECUREBITS" },
2700 { config_parse_bounding_set, "BOUNDINGSET" },
2701 { config_parse_limit, "LIMIT" },
2702 { config_parse_unit_deps, "UNIT [...]" },
2703 { config_parse_exec, "PATH [ARGUMENT [...]]" },
2704 { config_parse_service_type, "SERVICETYPE" },
2705 { config_parse_service_restart, "SERVICERESTART" },
2706 #ifdef HAVE_SYSV_COMPAT
2707 { config_parse_sysv_priority, "SYSVPRIORITY" },
2709 { config_parse_warn_compat, "NOTSUPPORTED" },
2711 { config_parse_kill_mode, "KILLMODE" },
2712 { config_parse_kill_signal, "SIGNAL" },
2713 { config_parse_socket_listen, "SOCKET [...]" },
2714 { config_parse_socket_bind, "SOCKETBIND" },
2715 { config_parse_socket_bindtodevice, "NETWORKINTERFACE" },
2716 { config_parse_sec, "SECONDS" },
2717 { config_parse_nsec, "NANOSECONDS" },
2718 { config_parse_path_strv, "PATH [...]" },
2719 { config_parse_unit_requires_mounts_for, "PATH [...]" },
2720 { config_parse_exec_mount_flags, "MOUNTFLAG [...]" },
2721 { config_parse_unit_string_printf, "STRING" },
2722 { config_parse_trigger_unit, "UNIT" },
2723 { config_parse_timer, "TIMER" },
2724 { config_parse_path_spec, "PATH" },
2725 { config_parse_notify_access, "ACCESS" },
2726 { config_parse_ip_tos, "TOS" },
2727 { config_parse_unit_condition_path, "CONDITION" },
2728 { config_parse_unit_condition_string, "CONDITION" },
2729 { config_parse_unit_condition_null, "CONDITION" },
2730 { config_parse_unit_slice, "SLICE" },
2731 { config_parse_documentation, "URL" },
2732 { config_parse_service_timeout, "SECONDS" },
2733 { config_parse_start_limit_action, "ACTION" },
2734 { config_parse_set_status, "STATUS" },
2735 { config_parse_service_sockets, "SOCKETS" },
2736 { config_parse_environ, "ENVIRON" },
2737 { config_parse_syscall_filter, "SYSCALL" },
2738 { config_parse_cpu_shares, "SHARES" },
2739 { config_parse_memory_limit, "LIMIT" },
2740 { config_parse_device_allow, "DEVICE" },
2741 { config_parse_device_policy, "POLICY" },
2742 { config_parse_blockio_bandwidth, "BANDWIDTH" },
2743 { config_parse_blockio_weight, "WEIGHT" },
2744 { config_parse_blockio_device_weight, "DEVICEWEIGHT" },
2745 { config_parse_long, "LONG" },
2746 { config_parse_socket_service, "SERVICE" },
2749 const char *prev = NULL;
2754 NULSTR_FOREACH(i, load_fragment_gperf_nulstr) {
2755 const char *rvalue = "OTHER", *lvalue;
2759 const ConfigPerfItem *p;
2761 assert_se(p = load_fragment_gperf_lookup(i, strlen(i)));
2763 dot = strchr(i, '.');
2764 lvalue = dot ? dot + 1 : i;
2768 if (!prev || !strneq(prev, i, prefix_len+1)) {
2772 fprintf(f, "[%.*s]\n", (int) prefix_len, i);
2775 for (j = 0; j < ELEMENTSOF(table); j++)
2776 if (p->parse == table[j].callback) {
2777 rvalue = table[j].rvalue;
2781 fprintf(f, "%s=%s\n", lvalue, rvalue);