summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/conf-parser.c25
-rw-r--r--src/shared/conf-parser.h1
-rw-r--r--src/shared/install.c5
-rw-r--r--src/shared/sleep-config.c16
4 files changed, 28 insertions, 19 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;
diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h
index 3e2c784805..ea7b710dec 100644
--- a/src/shared/conf-parser.h
+++ b/src/shared/conf-parser.h
@@ -89,6 +89,7 @@ int config_parse(const char *unit,
const void *table,
bool relaxed,
bool allow_include,
+ bool warn,
void *userdata);
/* Generic parsers */
diff --git a/src/shared/install.c b/src/shared/install.c
index a080d8f328..bc2a377971 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1076,7 +1076,10 @@ static int unit_file_load(
return -ENOMEM;
}
- r = config_parse(NULL, path, f, NULL, config_item_table_lookup, items, true, true, info);
+ r = config_parse(NULL, path, f,
+ NULL,
+ config_item_table_lookup, items,
+ true, true, false, info);
if (r < 0)
return r;
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
index 4b2b0fe100..16a488d56b 100644
--- a/src/shared/sleep-config.c
+++ b/src/shared/sleep-config.c
@@ -48,19 +48,9 @@ int parse_sleep_config(const char *verb, char ***_modes, char ***_states) {
{}
};
- int r;
- _cleanup_fclose_ FILE *f;
-
- f = fopen(PKGSYSCONFDIR "/sleep.conf", "re");
- if (!f)
- log_full(errno == ENOENT ? LOG_DEBUG: LOG_WARNING,
- "Failed to open configuration file " PKGSYSCONFDIR "/sleep.conf: %m");
- else {
- r = config_parse(NULL, PKGSYSCONFDIR "/sleep.conf", f, "Sleep\0",
- config_item_table_lookup, items, false, false, NULL);
- if (r < 0)
- log_warning("Failed to parse configuration file: %s", strerror(-r));
- }
+ config_parse(NULL, PKGSYSCONFDIR "/sleep.conf", NULL,
+ "Sleep\0",
+ config_item_table_lookup, items, false, false, true, NULL);
if (streq(verb, "suspend")) {
/* empty by default */