summaryrefslogtreecommitdiff
path: root/src/shared/conf-parser.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-16 18:27:12 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-16 18:47:20 -0400
commit36f822c4bd077f9121757e24b6516e5c7ada63b5 (patch)
tree9201ba3d895aa08a00c17ada422a3dd399e456f9 /src/shared/conf-parser.c
parente1bbf3d12f28b8e3d4394f2b257e1b7aea3d10fc (diff)
Let config_parse open file where applicable
Special care is needed so that we get an error message if the file failed to parse, but not when it is missing. To avoid duplicating the same error check in every caller, add an additional 'warn' boolean to tell config_parse whether a message should be issued. This makes things both shorter and more robust wrt. to error reporting.
Diffstat (limited to 'src/shared/conf-parser.c')
-rw-r--r--src/shared/conf-parser.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 1f40986649..0be7226871 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -245,7 +245,7 @@ static int parse_line(const char* unit,
if (!fn)
return -ENOMEM;
- return config_parse(unit, fn, NULL, sections, lookup, table, relaxed, false, userdata);
+ return config_parse(unit, fn, NULL, sections, lookup, table, relaxed, false, false, userdata);
}
if (*l == '[') {
@@ -326,6 +326,7 @@ int config_parse(const char *unit,
const void *table,
bool relaxed,
bool allow_include,
+ bool warn,
void *userdata) {
_cleanup_free_ char *section = NULL, *continuation = NULL;
@@ -340,7 +341,11 @@ int config_parse(const char *unit,
if (!f) {
f = ours = fopen(filename, "re");
if (!f) {
- log_full(errno == ENOENT ? LOG_DEBUG : LOG_ERR, "Failed to open configuration file '%s': %m", filename);
+ /* Only log on request, except for ENOENT,
+ * since we return 0 to the caller. */
+ if (warn || errno == ENOENT)
+ log_full(errno == ENOENT ? LOG_DEBUG : LOG_ERR,
+ "Failed to open configuration file '%s': %m", filename);
return errno == ENOENT ? 0 : -errno;
}
}
@@ -363,8 +368,11 @@ int config_parse(const char *unit,
if (continuation) {
c = strappend(continuation, l);
- if (!c)
+ if (!c) {
+ if (warn)
+ log_oom();
return -ENOMEM;
+ }
free(continuation);
continuation = NULL;
@@ -386,8 +394,11 @@ int config_parse(const char *unit,
continuation = c;
else {
continuation = strdup(l);
- if (!continuation)
+ if (!continuation) {
+ if (warn)
+ log_oom();
return -ENOMEM;
+ }
}
continue;
@@ -408,8 +419,12 @@ int config_parse(const char *unit,
userdata);
free(c);
- if (r < 0)
+ if (r < 0) {
+ if (warn)
+ log_warning("Failed to parse file '%s': %s",
+ filename, strerror(-r));
return r;
+ }
}
return 0;