diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-04-06 20:11:41 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-04-07 15:42:25 +0200 |
commit | 527b7a421ff3927d4f3f170b1b143452e88ae1dc (patch) | |
tree | cfb13e123c6dfd547fb005db63a480ca709b46da /src/core/load-fragment.c | |
parent | 64f75d7a2898e0c0d2b66f93ddd34ffd345bb3c5 (diff) |
util: rework cunescape(), improve error handling
Change cunescape() to return a normal error code, so that we can
distuingish OOM errors from parse errors.
This also adds a flags parameter to control whether "relaxed" or normal
parsing shall be done. If set no parse failures are generated, and the
only reason why cunescape() can fail is OOM.
Diffstat (limited to 'src/core/load-fragment.c')
-rw-r--r-- | src/core/load-fragment.c | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 07384d3668..e61418db50 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -507,16 +507,17 @@ int config_parse_exec_oom_score_adjust(const char* unit, return 0; } -int config_parse_exec(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_exec( + 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) { ExecCommand **e = data, *nce; char *path, **n; @@ -568,15 +569,13 @@ int config_parse_exec(const char *unit, word ++; } } - } else - if (strneq(word, ";", MAX(l, 1U))) + } else if (strneq(word, ";", MAX(l, 1U))) goto found; k++; } if (!isempty(state)) { - log_syntax(unit, LOG_ERR, filename, line, EINVAL, - "Trailing garbage, ignoring."); + log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Trailing garbage, ignoring."); return 0; } @@ -605,9 +604,10 @@ int config_parse_exec(const char *unit, else skip = strneq(word, "\\;", MAX(l, 1U)); - c = cunescape_length(word + skip, l - skip); - if (!c) { - r = log_oom(); + r = cunescape_length(word + skip, l - skip, 0, &c); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, "Failed to unescape command line, ignoring: %s", rvalue); + r = 0; goto fail; } @@ -637,8 +637,7 @@ int config_parse_exec(const char *unit, else goto ok; - log_syntax(unit, LOG_ERR, filename, line, EINVAL, - "%s, ignoring: %s", reason, rvalue); + log_syntax(unit, LOG_ERR, filename, line, EINVAL, "%s, ignoring: %s", reason, rvalue); r = 0; goto fail; @@ -1976,8 +1975,7 @@ int config_parse_environ(const char *unit, if (u) { r = unit_full_printf(u, rvalue, &k); if (r < 0) - log_syntax(unit, LOG_ERR, filename, line, -r, - "Failed to resolve specifiers, ignoring: %s", rvalue); + log_syntax(unit, LOG_ERR, filename, line, -r, "Failed to resolve specifiers, ignoring: %s", rvalue); } if (!k) @@ -1989,13 +1987,14 @@ int config_parse_environ(const char *unit, _cleanup_free_ char *n; char **x; - n = cunescape_length(word, l); - if (!n) - return log_oom(); + r = cunescape_length(word, l, 0, &n); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, "Couldn't unescape assignment, ignoring: %s", rvalue); + continue; + } if (!env_assignment_is_valid(n)) { - log_syntax(unit, LOG_ERR, filename, line, EINVAL, - "Invalid environment assignment, ignoring: %s", rvalue); + log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Invalid environment assignment, ignoring: %s", rvalue); continue; } |