diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-10-23 18:20:54 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-10-24 23:03:49 +0200 |
commit | dea7b6b043f0cd9e34ee719b9b612c3a4776387e (patch) | |
tree | 1e46775676ee8ac282bd912d52f0f6e55892227d /src/basic | |
parent | 84ac7bea360cd369df26910e9685a7eed2327088 (diff) |
util-lib: rework extract_first_word_and_warn() a bit
- Really warn in all error cases, not just some. We need to make sure
that all errors are logged to not confuse the user.
- Explicitly check for EINVAL error code before claiming anything about
invalid escapes, could be ENOMEM after all.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/extract-word.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/basic/extract-word.c b/src/basic/extract-word.c index 474e6fdd57..5e74f1832b 100644 --- a/src/basic/extract-word.c +++ b/src/basic/extract-word.c @@ -195,26 +195,36 @@ int extract_first_word_and_warn( unsigned line, const char *rvalue) { - /* Try to unquote it, if it fails, warn about it and try again but this - * time using EXTRACT_CUNESCAPE_RELAX to keep the backslashes verbatim - * in invalid escape sequences. */ + /* Try to unquote it, if it fails, warn about it and try again + * but this time using EXTRACT_CUNESCAPE_RELAX to keep the + * backslashes verbatim in invalid escape sequences. */ + const char *save; int r; save = *p; r = extract_first_word(p, ret, separators, flags); - if (r < 0 && !(flags & EXTRACT_CUNESCAPE_RELAX)) { + if (r >= 0) + return r; + + if (r == -EINVAL && !(flags & EXTRACT_CUNESCAPE_RELAX)) { /* Retry it with EXTRACT_CUNESCAPE_RELAX. */ *p = save; r = extract_first_word(p, ret, separators, flags|EXTRACT_CUNESCAPE_RELAX); - if (r < 0) - log_syntax(unit, LOG_ERR, filename, line, r, "Unbalanced quoting in command line, ignoring: \"%s\"", rvalue); - else - log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid escape sequences in command line: \"%s\"", rvalue); + if (r >= 0) { + /* It worked this time, hence it must have been an invalid escape sequence we could correct. */ + log_syntax(unit, LOG_WARNING, filename, line, EINVAL, "Invalid escape sequences in line, correcting: \"%s\"", rvalue); + return r; + } + + /* If it's still EINVAL; then it must be unbalanced quoting, report this. */ + if (r == -EINVAL) + return log_syntax(unit, LOG_ERR, filename, line, r, "Unbalanced quoting, ignoring: \"%s\"", rvalue); } - return r; + /* Can be any error, report it */ + return log_syntax(unit, LOG_ERR, filename, line, r, "Unable to decode word \"%s\", ignoring: %m", rvalue); } int extract_many_words(const char **p, const char *separators, ExtractFlags flags, ...) { |