summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-11-09 00:26:11 +0100
committerLennart Poettering <lennart@poettering.net>2017-11-13 10:24:03 +0100
commitbcde742e78ac3b8e8ea348cfb022c820c11800e2 (patch)
tree0d044ff32ade82bf671aae8a1ff120ddc69598d0 /src
parent92b5e6054254b1d6cf7fcb342720fe58a58d0d7e (diff)
downloadsystemd-bcde742e78ac3b8e8ea348cfb022c820c11800e2.tar.gz
conf-parser: turn three bool function params into a flags fields
This makes things more readable and fixes some issues with incorrect flag propagation between the various flavours of config_parse().
Diffstat (limited to 'src')
-rw-r--r--src/core/load-dropin.c11
-rw-r--r--src/core/load-fragment.c2
-rw-r--r--src/core/main.c2
-rw-r--r--src/coredump/coredump.c2
-rw-r--r--src/journal-remote/journal-remote.c2
-rw-r--r--src/journal-remote/journal-upload.c2
-rw-r--r--src/journal/journald-server.c2
-rw-r--r--src/login/logind.c2
-rw-r--r--src/network/netdev/netdev.c4
-rw-r--r--src/network/networkd-conf.c2
-rw-r--r--src/network/networkd-network.c2
-rw-r--r--src/nspawn/nspawn-settings.c4
-rw-r--r--src/resolve/resolved-conf.c2
-rw-r--r--src/shared/conf-parser.c104
-rw-r--r--src/shared/conf-parser.h18
-rw-r--r--src/shared/install.c2
-rw-r--r--src/shared/sleep-config.c8
-rw-r--r--src/test/test-conf-parser.c2
-rw-r--r--src/timesync/timesyncd-conf.c2
-rw-r--r--src/tty-ask-password-agent/tty-ask-password-agent.c2
-rw-r--r--src/udev/net/link-config.c2
21 files changed, 88 insertions, 91 deletions
diff --git a/src/core/load-dropin.c b/src/core/load-dropin.c
index 948d1bc248..c98ab4164f 100644
--- a/src/core/load-dropin.c
+++ b/src/core/load-dropin.c
@@ -154,12 +154,11 @@ int unit_load_dropin(Unit *u) {
return log_oom();
}
- STRV_FOREACH(f, u->dropin_paths) {
- config_parse(u->id, *f, NULL,
- UNIT_VTABLE(u)->sections,
- config_item_perf_lookup, load_fragment_gperf_lookup,
- false, false, false, u);
- }
+ STRV_FOREACH(f, u->dropin_paths)
+ (void) config_parse(u->id, *f, NULL,
+ UNIT_VTABLE(u)->sections,
+ config_item_perf_lookup, load_fragment_gperf_lookup,
+ 0, u);
u->dropin_mtime = now(CLOCK_REALTIME);
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 84f2931b63..53a95caeaf 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -4450,7 +4450,7 @@ static int load_from_path(Unit *u, const char *path) {
r = config_parse(u->id, filename, f,
UNIT_VTABLE(u)->sections,
config_item_perf_lookup, load_fragment_gperf_lookup,
- false, true, false, u);
+ CONFIG_PARSE_ALLOW_INCLUDE, u);
if (r < 0)
return r;
}
diff --git a/src/core/main.c b/src/core/main.c
index 3e766f0645..96cac1cd9e 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -768,7 +768,7 @@ static int parse_config_file(void) {
CONF_PATHS_NULSTR("systemd/system.conf.d") :
CONF_PATHS_NULSTR("systemd/user.conf.d");
- config_parse_many_nulstr(fn, conf_dirs_nulstr, "Manager\0", config_item_table_lookup, items, false, NULL);
+ (void) config_parse_many_nulstr(fn, conf_dirs_nulstr, "Manager\0", config_item_table_lookup, items, CONFIG_PARSE_WARN, NULL);
/* Traditionally "0" was used to turn off the default unit timeouts. Fix this up so that we used USEC_INFINITY
* like everywhere else. */
diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c
index 300d647903..ee258a1219 100644
--- a/src/coredump/coredump.c
+++ b/src/coredump/coredump.c
@@ -147,7 +147,7 @@ static int parse_config(void) {
CONF_PATHS_NULSTR("systemd/coredump.conf.d"),
"Coredump\0",
config_item_table_lookup, items,
- false, NULL);
+ CONFIG_PARSE_WARN, NULL);
}
static inline uint64_t storage_size_max(void) {
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
index e045e9a842..90cd4447d7 100644
--- a/src/journal-remote/journal-remote.c
+++ b/src/journal-remote/journal-remote.c
@@ -1254,7 +1254,7 @@ static int parse_config(void) {
return config_parse_many_nulstr(PKGSYSCONFDIR "/journal-remote.conf",
CONF_PATHS_NULSTR("systemd/journal-remote.conf.d"),
"Remote\0", config_item_table_lookup, items,
- false, NULL);
+ CONFIG_PARSE_WARN, NULL);
}
static void help(void) {
diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c
index ea264989ab..1e3e541998 100644
--- a/src/journal-remote/journal-upload.c
+++ b/src/journal-remote/journal-upload.c
@@ -543,7 +543,7 @@ static int parse_config(void) {
return config_parse_many_nulstr(PKGSYSCONFDIR "/journal-upload.conf",
CONF_PATHS_NULSTR("systemd/journal-upload.conf.d"),
"Upload\0", config_item_table_lookup, items,
- false, NULL);
+ CONFIG_PARSE_WARN, NULL);
}
static void help(void) {
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 00ad168286..e719fae007 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1398,7 +1398,7 @@ static int server_parse_config_file(Server *s) {
CONF_PATHS_NULSTR("systemd/journald.conf.d"),
"Journal\0",
config_item_perf_lookup, journald_gperf_lookup,
- false, s);
+ CONFIG_PARSE_WARN, s);
}
static int server_dispatch_sync(sd_event_source *es, usec_t t, void *userdata) {
diff --git a/src/login/logind.c b/src/login/logind.c
index 6046596684..cdd1710fd3 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -1072,7 +1072,7 @@ static int manager_parse_config_file(Manager *m) {
CONF_PATHS_NULSTR("systemd/logind.conf.d"),
"Login\0",
config_item_perf_lookup, logind_gperf_lookup,
- false, m);
+ CONFIG_PARSE_WARN, m);
}
static int manager_dispatch_reload_signal(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c
index 0e1a7d1335..2ec526e636 100644
--- a/src/network/netdev/netdev.c
+++ b/src/network/netdev/netdev.c
@@ -630,7 +630,7 @@ static int netdev_load_one(Manager *manager, const char *filename) {
r = config_parse_many(filename, network_dirs, dropin_dirname,
"Match\0NetDev\0",
config_item_perf_lookup, network_netdev_gperf_lookup,
- true, netdev_raw);
+ CONFIG_PARSE_WARN, netdev_raw);
if (r < 0)
return r;
@@ -671,7 +671,7 @@ static int netdev_load_one(Manager *manager, const char *filename) {
r = config_parse(NULL, filename, file,
NETDEV_VTABLE(netdev)->sections,
config_item_perf_lookup, network_netdev_gperf_lookup,
- false, false, false, netdev);
+ CONFIG_PARSE_WARN, netdev);
if (r < 0)
return r;
diff --git a/src/network/networkd-conf.c b/src/network/networkd-conf.c
index 025662437b..25ec160df8 100644
--- a/src/network/networkd-conf.c
+++ b/src/network/networkd-conf.c
@@ -35,7 +35,7 @@ int manager_parse_config_file(Manager *m) {
CONF_PATHS_NULSTR("systemd/networkd.conf.d"),
"DHCP\0",
config_item_perf_lookup, networkd_gperf_lookup,
- false, m);
+ CONFIG_PARSE_WARN, m);
}
static const char* const duid_type_table[_DUID_TYPE_MAX] = {
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 29f1586d13..3ed82ca3f9 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -280,7 +280,7 @@ static int network_load_one(Manager *manager, const char *filename) {
"IPv6PrefixDelegation\0"
"IPv6Prefix\0",
config_item_perf_lookup, network_network_gperf_lookup,
- false, network);
+ CONFIG_PARSE_WARN, network);
if (r < 0)
return r;
diff --git a/src/nspawn/nspawn-settings.c b/src/nspawn/nspawn-settings.c
index 285e22820f..5f9c1f5ea4 100644
--- a/src/nspawn/nspawn-settings.c
+++ b/src/nspawn/nspawn-settings.c
@@ -59,9 +59,7 @@ int settings_load(FILE *f, const char *path, Settings **ret) {
"Network\0"
"Files\0",
config_item_perf_lookup, nspawn_gperf_lookup,
- false,
- false,
- true,
+ CONFIG_PARSE_WARN,
s);
if (r < 0)
return r;
diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c
index 3cf4261ff0..39dc358a48 100644
--- a/src/resolve/resolved-conf.c
+++ b/src/resolve/resolved-conf.c
@@ -236,7 +236,7 @@ int manager_parse_config_file(Manager *m) {
CONF_PATHS_NULSTR("systemd/resolved.conf.d"),
"Resolve\0",
config_item_perf_lookup, resolved_gperf_lookup,
- false, m);
+ CONFIG_PARSE_WARN, m);
if (r < 0)
return r;
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index d1c73b6f2d..86cf71afac 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -121,17 +121,18 @@ int config_item_perf_lookup(
}
/* Run the user supplied parser for an assignment */
-static int next_assignment(const char *unit,
- const char *filename,
- unsigned line,
- ConfigItemLookup lookup,
- const void *table,
- const char *section,
- unsigned section_line,
- const char *lvalue,
- const char *rvalue,
- bool relaxed,
- void *userdata) {
+static int next_assignment(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ ConfigItemLookup lookup,
+ const void *table,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ const char *rvalue,
+ ConfigParseFlags flags,
+ void *userdata) {
ConfigParserCallback func = NULL;
int ltype = 0;
@@ -157,26 +158,26 @@ static int next_assignment(const char *unit,
}
/* Warn about unknown non-extension fields. */
- if (!relaxed && !startswith(lvalue, "X-"))
+ if (!(flags & CONFIG_PARSE_RELAXED) && !startswith(lvalue, "X-"))
log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown lvalue '%s' in section '%s'", lvalue, section);
return 0;
}
/* Parse a variable assignment line */
-static int parse_line(const char* unit,
- const char *filename,
- unsigned line,
- const char *sections,
- ConfigItemLookup lookup,
- const void *table,
- bool relaxed,
- bool allow_include,
- char **section,
- unsigned *section_line,
- bool *section_ignored,
- char *l,
- void *userdata) {
+static int parse_line(
+ const char* unit,
+ const char *filename,
+ unsigned line,
+ const char *sections,
+ ConfigItemLookup lookup,
+ const void *table,
+ ConfigParseFlags flags,
+ char **section,
+ unsigned *section_line,
+ bool *section_ignored,
+ char *l,
+ void *userdata) {
char *e;
@@ -204,7 +205,7 @@ static int parse_line(const char* unit,
*
* Support for them should be eventually removed. */
- if (!allow_include) {
+ if (!(flags & CONFIG_PARSE_ALLOW_INCLUDE)) {
log_syntax(unit, LOG_ERR, filename, line, 0, ".include not allowed here. Ignoring.");
return 0;
}
@@ -213,7 +214,7 @@ static int parse_line(const char* unit,
if (!fn)
return -ENOMEM;
- return config_parse(unit, fn, NULL, sections, lookup, table, relaxed, false, false, userdata);
+ return config_parse(unit, fn, NULL, sections, lookup, table, flags, userdata);
}
if (*l == '[') {
@@ -234,7 +235,7 @@ static int parse_line(const char* unit,
if (sections && !nulstr_contains(sections, n)) {
- if (!relaxed && !startswith(n, "X-"))
+ if (!(flags & CONFIG_PARSE_RELAXED) && !startswith(n, "X-"))
log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown section '%s'. Ignoring.", n);
free(n);
@@ -253,7 +254,7 @@ static int parse_line(const char* unit,
if (sections && !*section) {
- if (!relaxed && !*section_ignored)
+ if (!(flags & CONFIG_PARSE_RELAXED) && !*section_ignored)
log_syntax(unit, LOG_WARNING, filename, line, 0, "Assignment outside of section. Ignoring.");
return 0;
@@ -277,7 +278,7 @@ static int parse_line(const char* unit,
*section_line,
strstrip(l),
strstrip(e),
- relaxed,
+ flags,
userdata);
}
@@ -288,15 +289,13 @@ int config_parse(const char *unit,
const char *sections,
ConfigItemLookup lookup,
const void *table,
- bool relaxed,
- bool allow_include,
- bool warn,
+ ConfigParseFlags flags,
void *userdata) {
_cleanup_free_ char *section = NULL, *continuation = NULL;
_cleanup_fclose_ FILE *ours = NULL;
unsigned line = 0, section_line = 0;
- bool section_ignored = false, allow_bom = true;
+ bool section_ignored = false;
int r;
assert(filename);
@@ -307,7 +306,7 @@ int config_parse(const char *unit,
if (!f) {
/* Only log on request, except for ENOENT,
* since we return 0 to the caller. */
- if (warn || errno == ENOENT)
+ if ((flags & CONFIG_PARSE_WARN) || errno == ENOENT)
log_full(errno == ENOENT ? LOG_DEBUG : LOG_ERR,
"Failed to open configuration file '%s': %m", filename);
return errno == ENOENT ? 0 : -errno;
@@ -325,38 +324,38 @@ int config_parse(const char *unit,
if (r == 0)
break;
if (r == -ENOBUFS) {
- if (warn)
+ if (flags & CONFIG_PARSE_WARN)
log_error_errno(r, "%s:%u: Line too long", filename, line);
return r;
}
if (r < 0) {
- if (warn)
+ if (CONFIG_PARSE_WARN)
log_error_errno(r, "%s:%u: Error while reading configuration file: %m", filename, line);
return r;
}
l = buf;
- if (allow_bom) {
+ if (!(flags & CONFIG_PARSE_REFUSE_BOM)) {
char *q;
q = startswith(buf, UTF8_BYTE_ORDER_MARK);
if (q) {
l = q;
- allow_bom = false;
+ flags |= CONFIG_PARSE_REFUSE_BOM;
}
}
if (continuation) {
if (strlen(continuation) + strlen(l) > LONG_LINE_MAX) {
- if (warn)
+ if (flags & CONFIG_PARSE_WARN)
log_error("%s:%u: Continuation line too long", filename, line);
return -ENOBUFS;
}
if (!strextend(&continuation, l, NULL)) {
- if (warn)
+ if (flags & CONFIG_PARSE_WARN)
log_oom();
return -ENOMEM;
}
@@ -378,7 +377,7 @@ int config_parse(const char *unit,
if (!continuation) {
continuation = strdup(l);
if (!continuation) {
- if (warn)
+ if (flags & CONFIG_PARSE_WARN)
log_oom();
return -ENOMEM;
}
@@ -393,15 +392,14 @@ int config_parse(const char *unit,
sections,
lookup,
table,
- relaxed,
- allow_include,
+ flags,
&section,
&section_line,
&section_ignored,
p,
userdata);
if (r < 0) {
- if (warn)
+ if (flags & CONFIG_PARSE_WARN)
log_warning_errno(r, "%s:%u: Failed to parse file: %m", filename, line);
return r;
@@ -419,20 +417,20 @@ static int config_parse_many_files(
const char *sections,
ConfigItemLookup lookup,
const void *table,
- bool relaxed,
+ ConfigParseFlags flags,
void *userdata) {
char **fn;
int r;
if (conf_file) {
- r = config_parse(NULL, conf_file, NULL, sections, lookup, table, relaxed, false, true, userdata);
+ r = config_parse(NULL, conf_file, NULL, sections, lookup, table, flags, userdata);
if (r < 0)
return r;
}
STRV_FOREACH(fn, files) {
- r = config_parse(NULL, *fn, NULL, sections, lookup, table, relaxed, false, true, userdata);
+ r = config_parse(NULL, *fn, NULL, sections, lookup, table, flags, userdata);
if (r < 0)
return r;
}
@@ -447,7 +445,7 @@ int config_parse_many_nulstr(
const char *sections,
ConfigItemLookup lookup,
const void *table,
- bool relaxed,
+ ConfigParseFlags flags,
void *userdata) {
_cleanup_strv_free_ char **files = NULL;
@@ -457,8 +455,7 @@ int config_parse_many_nulstr(
if (r < 0)
return r;
- return config_parse_many_files(conf_file, files,
- sections, lookup, table, relaxed, userdata);
+ return config_parse_many_files(conf_file, files, sections, lookup, table, flags, userdata);
}
/* Parse each config file in the directories specified as strv. */
@@ -469,7 +466,7 @@ int config_parse_many(
const char *sections,
ConfigItemLookup lookup,
const void *table,
- bool relaxed,
+ ConfigParseFlags flags,
void *userdata) {
_cleanup_strv_free_ char **dropin_dirs = NULL;
@@ -486,8 +483,7 @@ int config_parse_many(
if (r < 0)
return r;
- return config_parse_many_files(conf_file, files,
- sections, lookup, table, relaxed, userdata);
+ return config_parse_many_files(conf_file, files, sections, lookup, table, flags, userdata);
}
#define DEFINE_PARSER(type, vartype, conv_func) \
diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h
index ce1113485d..a270488c23 100644
--- a/src/shared/conf-parser.h
+++ b/src/shared/conf-parser.h
@@ -29,8 +29,14 @@
#include "log.h"
#include "macro.h"
-/* An abstract parser for simple, line based, shallow configuration
- * files consisting of variable assignments only. */
+/* An abstract parser for simple, line based, shallow configuration files consisting of variable assignments only. */
+
+typedef enum ConfigParseFlags {
+ CONFIG_PARSE_RELAXED = 1U << 0,
+ CONFIG_PARSE_ALLOW_INCLUDE = 1U << 1,
+ CONFIG_PARSE_WARN = 1U << 2,
+ CONFIG_PARSE_REFUSE_BOM = 1U << 3,
+} ConfigParseFlags;
/* Prototype for a parser for a specific configuration setting */
typedef int (*ConfigParserCallback)(const char *unit,
@@ -91,9 +97,7 @@ int config_parse(
const char *sections, /* nulstr */
ConfigItemLookup lookup,
const void *table,
- bool relaxed,
- bool allow_include,
- bool warn,
+ ConfigParseFlags flags,
void *userdata);
int config_parse_many_nulstr(
@@ -102,7 +106,7 @@ int config_parse_many_nulstr(
const char *sections, /* nulstr */
ConfigItemLookup lookup,
const void *table,
- bool relaxed,
+ ConfigParseFlags flags,
void *userdata);
int config_parse_many(
@@ -112,7 +116,7 @@ int config_parse_many(
const char *sections, /* nulstr */
ConfigItemLookup lookup,
const void *table,
- bool relaxed,
+ ConfigParseFlags flags,
void *userdata);
/* Generic parsers */
diff --git a/src/shared/install.c b/src/shared/install.c
index ed0c4a5a11..d122aebc09 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1308,7 +1308,7 @@ static int unit_file_load(
r = config_parse(info->name, path, f,
NULL,
config_item_table_lookup, items,
- true, true, false, info);
+ CONFIG_PARSE_RELAXED|CONFIG_PARSE_ALLOW_INCLUDE, info);
if (r < 0)
return log_debug_errno(r, "Failed to parse %s: %m", info->name);
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
index 8c1624ff46..b4c3037f0c 100644
--- a/src/shared/sleep-config.c
+++ b/src/shared/sleep-config.c
@@ -58,10 +58,10 @@ int parse_sleep_config(const char *verb, char ***_modes, char ***_states) {
{}
};
- config_parse_many_nulstr(PKGSYSCONFDIR "/sleep.conf",
- CONF_PATHS_NULSTR("systemd/sleep.conf.d"),
- "Sleep\0", config_item_table_lookup, items,
- false, NULL);
+ (void) config_parse_many_nulstr(PKGSYSCONFDIR "/sleep.conf",
+ CONF_PATHS_NULSTR("systemd/sleep.conf.d"),
+ "Sleep\0", config_item_table_lookup, items,
+ CONFIG_PARSE_WARN, NULL);
if (streq(verb, "suspend")) {
/* empty by default */
diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c
index 7a7de98bec..2974d533c3 100644
--- a/src/test/test-conf-parser.c
+++ b/src/test/test-conf-parser.c
@@ -311,7 +311,7 @@ static void test_config_parse(unsigned i, const char *s) {
r = config_parse(NULL, name, f,
"Section\0",
config_item_table_lookup, items,
- false, false, true, NULL);
+ CONFIG_PARSE_WARN, NULL);
switch (i) {
case 0 ... 3:
diff --git a/src/timesync/timesyncd-conf.c b/src/timesync/timesyncd-conf.c
index b62e20c287..333f81a948 100644
--- a/src/timesync/timesyncd-conf.c
+++ b/src/timesync/timesyncd-conf.c
@@ -114,7 +114,7 @@ int manager_parse_config_file(Manager *m) {
CONF_PATHS_NULSTR("systemd/timesyncd.conf.d"),
"Time\0",
config_item_perf_lookup, timesyncd_gperf_lookup,
- false, m);
+ CONFIG_PARSE_WARN, m);
if (r < 0)
return r;
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c
index 495ae464b4..9dd7ea1811 100644
--- a/src/tty-ask-password-agent/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent/tty-ask-password-agent.c
@@ -310,7 +310,7 @@ static int parse_password(const char *filename, char **wall) {
r = config_parse(NULL, filename, NULL,
NULL,
config_item_table_lookup, items,
- true, false, true, NULL);
+ CONFIG_PARSE_RELAXED|CONFIG_PARSE_WARN, NULL);
if (r < 0)
return r;
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index a5f3b1a1b0..fcbadf3e79 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -175,7 +175,7 @@ static int load_link(link_config_ctx *ctx, const char *filename) {
r = config_parse(NULL, filename, file,
"Match\0Link\0Ethernet\0",
config_item_perf_lookup, link_config_gperf_lookup,
- false, false, true, link);
+ CONFIG_PARSE_WARN, link);
if (r < 0)
return r;
else