summaryrefslogtreecommitdiff
path: root/src/basic/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-09-30 18:22:42 +0200
committerLennart Poettering <lennart@poettering.net>2015-09-30 22:26:16 +0200
commit12ca818ffddb77eb6a0fabe369a5bcbf6994ff8b (patch)
treec8ebcdb6cc00af0e97cf16a629bf10990f8ae4d2 /src/basic/util.c
parent234ae0090309b5bb049f6813798bd2b4615414bc (diff)
tree-wide: clean up log_syntax() usage
- Rely everywhere that we use abs() on the error code passed in anyway, thus don't need to explicitly negate what we pass in - Never attach synthetic error number information to log messages. Only log about errors we *receive* with the error number we got there, don't log any synthetic error, that don#t even propagate, but just eat up. - Be more careful with attaching exactly the error we get, instead of errno or unrelated errors randomly. - Fix one occasion where the error number and line number got swapped. - Make sure we never tape over OOM issues, or inability to resolve specifiers
Diffstat (limited to 'src/basic/util.c')
-rw-r--r--src/basic/util.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/basic/util.c b/src/basic/util.c
index 2bad33be1b..b76cb7aa97 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -2602,30 +2602,28 @@ int parse_cpu_set(
r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES);
if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, r,
- "Invalid value for %s: %s", lvalue, whole_rvalue);
+ log_syntax(unit, LOG_ERR, filename, line, r, "Invalid value for %s: %s", lvalue, whole_rvalue);
return r;
}
if (r == 0)
break;
- r = safe_atou(word, &cpu);
-
- if (!c)
- if (!(c = cpu_set_malloc(&ncpus)))
+ if (!c) {
+ c = cpu_set_malloc(&ncpus);
+ if (!c)
return log_oom();
+ }
+ r = safe_atou(word, &cpu);
if (r < 0 || cpu >= ncpus) {
- log_syntax(unit, LOG_ERR, filename, line, -r,
- "Failed to parse CPU affinity '%s'", rvalue);
- return -EBADMSG;
+ log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse CPU affinity '%s'", rvalue);
+ return -EINVAL;
}
CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c);
}
if (!isempty(rvalue))
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Trailing garbage, ignoring.");
+ log_syntax(unit, LOG_ERR, filename, line, 0, "Trailing garbage, ignoring.");
/* On success, sets *cpu_set and returns ncpus for the system. */
if (c) {
@@ -6070,6 +6068,7 @@ int extract_first_word_and_warn(
const char *filename,
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. */
@@ -6078,17 +6077,17 @@ int extract_first_word_and_warn(
save = *p;
r = extract_first_word(p, ret, separators, flags);
- if (r < 0 && !(flags&EXTRACT_CUNESCAPE_RELAX)) {
+ if (r < 0 && !(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, EINVAL,
- "Unbalanced quoting in command line, ignoring: \"%s\"", rvalue);
+ log_syntax(unit, LOG_ERR, filename, line, r, "Unbalanced quoting in command line, ignoring: \"%s\"", rvalue);
else
- log_syntax(unit, LOG_WARNING, filename, line, EINVAL,
- "Invalid escape sequences in command line: \"%s\"", rvalue);
+ log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid escape sequences in command line: \"%s\"", rvalue);
}
+
return r;
}