bool allow_include,
char **section,
unsigned *section_line,
+ bool *section_ignored,
char *l,
void *userdata) {
if (sections && !nulstr_contains(sections, n)) {
- if (!relaxed)
+ if (!relaxed && !startswith(n, "X-"))
log_syntax(unit, LOG_WARNING, filename, line, EINVAL,
"Unknown section '%s'. Ignoring.", n);
free(*section);
*section = NULL;
*section_line = 0;
+ *section_ignored = true;
} else {
free(*section);
*section = n;
*section_line = line;
+ *section_ignored = false;
}
return 0;
if (sections && !*section) {
- if (!relaxed)
+ if (!relaxed && !*section_ignored)
log_syntax(unit, LOG_WARNING, filename, line, EINVAL,
"Assignment outside of section. Ignoring.");
_cleanup_free_ char *section = NULL, *continuation = NULL;
_cleanup_fclose_ FILE *ours = NULL;
unsigned line = 0, section_line = 0;
+ bool section_ignored = false;
int r;
assert(filename);
allow_include,
§ion,
§ion_line,
+ §ion_ignored,
p,
userdata);
free(c);
return 0;
}
-int config_parse_string(const char *unit,
- const char *filename,
- unsigned line,
- const char *section,
- unsigned section_line,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) {
+int config_parse_string(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
- char **s = data;
- char *n;
+ char **s = data, *n;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
- n = strdup(rvalue);
- if (!n)
- return log_oom();
-
- if (!utf8_is_valid(n)) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "String is not UTF-8 clean, ignoring assignment: %s", rvalue);
- free(n);
+ if (!utf8_is_valid(rvalue)) {
+ log_invalid_utf8(unit, LOG_ERR, filename, line, EINVAL, rvalue);
return 0;
}
- free(*s);
- if (*n)
- *s = n;
+ if (isempty(rvalue))
+ n = NULL;
else {
- free(n);
- *s = NULL;
+ n = strdup(rvalue);
+ if (!n)
+ return log_oom();
}
+ free(*s);
+ *s = n;
+
return 0;
}
-int config_parse_path(const char *unit,
- const char *filename,
- unsigned line,
- const char *section,
- unsigned section_line,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) {
+int config_parse_path(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
- char **s = data;
- char *n;
- int offset;
+ char **s = data, *n;
assert(filename);
assert(lvalue);
assert(data);
if (!utf8_is_valid(rvalue)) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Path is not UTF-8 clean, ignoring assignment: %s", rvalue);
+ log_invalid_utf8(unit, LOG_ERR, filename, line, EINVAL, rvalue);
return 0;
}
- offset = rvalue[0] == '-' && (streq(lvalue, "InaccessibleDirectories") ||
- streq(lvalue, "ReadOnlyDirectories"));
- if (!path_is_absolute(rvalue + offset)) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Not an absolute path, ignoring: %s", rvalue);
+ if (!path_is_absolute(rvalue)) {
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Not an absolute path, ignoring: %s", rvalue);
return 0;
}
}
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
- _cleanup_free_ char *n;
+ char *n;
n = cunescape_length(w, l);
if (!n)
return log_oom();
if (!utf8_is_valid(n)) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "String is not UTF-8 clean, ignoring: %s", rvalue);
- continue;
- }
-
- r = strv_extend(sv, n);
- if (r < 0)
- return log_oom();
- }
-
- return 0;
-}
-
-int config_parse_path_strv(const char *unit,
- const char *filename,
- unsigned line,
- const char *section,
- unsigned section_line,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) {
-
- char*** sv = data, *w, *state;
- size_t l;
- int r;
-
- assert(filename);
- assert(lvalue);
- assert(rvalue);
- assert(data);
-
- if (isempty(rvalue)) {
- /* Empty assignment resets the list */
- strv_free(*sv);
- *sv = NULL;
- return 0;
- }
-
- FOREACH_WORD_QUOTED(w, l, rvalue, state) {
- _cleanup_free_ char *n;
- int offset;
-
- n = strndup(w, l);
- if (!n)
- return log_oom();
-
- if (!utf8_is_valid(n)) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Path is not UTF-8 clean, ignoring assignment: %s", rvalue);
- continue;
- }
-
- offset = n[0] == '-' && (streq(lvalue, "InaccessibleDirectories") ||
- streq(lvalue, "ReadOnlyDirectories"));
- if (!path_is_absolute(n + offset)) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Not an absolute path, ignoring: %s", rvalue);
+ log_invalid_utf8(unit, LOG_ERR, filename, line, EINVAL, rvalue);
continue;
}
- path_kill_slashes(n);
- r = strv_extend(sv, n);
+ r = strv_consume(sv, n);
if (r < 0)
return log_oom();
}