shared/conf-parser: allow sections to be silently ignored with new -Section syntax
If we ignore any uknown section, we will not be able to show any warning if a typo in a section name is made. Let's reverse our approach, and explicitly list sections to ignore instead. I opted to make use the same section list for this, instead of adding a second list, because this list is passed through to many functions and adding yet another parameter to the long signature would be very noisy.
This commit is contained in:
@@ -221,8 +221,19 @@ static int parse_line(
|
||||
return -ENOMEM;
|
||||
|
||||
if (sections && !nulstr_contains(sections, n)) {
|
||||
bool ignore = flags & CONFIG_PARSE_RELAXED;
|
||||
const char *t;
|
||||
|
||||
if (!(flags & CONFIG_PARSE_RELAXED) && !startswith(n, "X-"))
|
||||
ignore = ignore || startswith(n, "X-");
|
||||
|
||||
if (!ignore)
|
||||
NULSTR_FOREACH(t, sections)
|
||||
if (streq_ptr(n, startswith(t, "-"))) {
|
||||
ignore = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ignore)
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown section '%s'. Ignoring.", n);
|
||||
|
||||
free(n);
|
||||
|
||||
Reference in New Issue
Block a user