}
int config_item_table_lookup(
- void *table,
+ const void *table,
const char *section,
const char *lvalue,
ConfigParserCallback *func,
void **data,
void *userdata) {
- ConfigTableItem *t;
+ const ConfigTableItem *t;
assert(table);
assert(lvalue);
}
int config_item_perf_lookup(
- void *table,
+ const void *table,
const char *section,
const char *lvalue,
ConfigParserCallback *func,
const char *filename,
unsigned line,
ConfigItemLookup lookup,
- void *table,
+ const void *table,
const char *section,
unsigned section_line,
const char *lvalue,
unsigned line,
const char *sections,
ConfigItemLookup lookup,
- void *table,
+ const void *table,
bool relaxed,
bool allow_include,
char **section,
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 == '[') {
FILE *f,
const char *sections,
ConfigItemLookup lookup,
- void *table,
+ const void *table,
bool relaxed,
bool allow_include,
+ bool warn,
void *userdata) {
_cleanup_free_ char *section = NULL, *continuation = NULL;
if (!f) {
f = ours = fopen(filename, "re");
if (!f) {
- log_error("Failed to open configuration file '%s': %m", filename);
- return -errno;
+ /* 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;
}
}
if (continuation) {
c = strappend(continuation, l);
- if (!c)
+ if (!c) {
+ if (warn)
+ log_oom();
return -ENOMEM;
+ }
free(continuation);
continuation = NULL;
continuation = c;
else {
continuation = strdup(l);
- if (!continuation)
+ if (!continuation) {
+ if (warn)
+ log_oom();
return -ENOMEM;
+ }
}
continue;
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;
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
char *n;
- n = cunescape_length(w, l);
+ n = strndup(w, l);
if (!n)
return log_oom();