return 1;
}
+static int parse_log_error(int error, const char *field, const char *eq) {
+ if (error == -ENOMEM)
+ return log_oom();
+ if (error != 0) /* Allow SYNTHETIC_ERRNO to be used, i.e. positive values. */
+ return log_error_errno(error, "Failed to parse %s= value '%s': %m", field, eq);
+
+ /* We don't log the error value for cases where we have a general "syntax error". */
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid syntax for %s= value: '%s'", field, eq);
+}
+
#define DEFINE_BUS_APPEND_PARSE_PTR(bus_type, cast_type, type, parse_func) \
static int bus_append_##parse_func( \
sd_bus_message *m, \
\
r = parse_func(eq, &val); \
if (r < 0) \
- return log_error_errno(r, "Failed to parse %s=%s: %m", field, eq); \
+ return parse_log_error(r, field, eq); \
\
r = sd_bus_message_append(m, "(sv)", field, \
bus_type, (cast_type) val); \
\
r = parse_func(eq); \
if (r < 0) \
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to parse %s: %s", field, eq); \
+ return parse_log_error(r, field, eq); \
\
r = sd_bus_message_append(m, "(sv)", field, \
bus_type, (int32_t) r); \
_cleanup_free_ char *word = NULL;
r = extract_first_word(&p, &word, /* separators= */ NULL, flags);
- if (r == -ENOMEM)
- return log_oom();
if (r < 0)
- return log_error_errno(r, "Invalid syntax: %s", eq);
+ return parse_log_error(r, field, eq);
if (r == 0)
break;
r = parse_sec(eq, &t);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s=%s: %m", field, eq);
+ return parse_log_error(r, field, eq);
l = strlen(field);
n = newa(char, l + 2);
r = parse_size(eq, /* base= */ 1024, &v);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s=%s: %m", field, eq);
+ return parse_log_error(r, field, eq);
r = sd_bus_message_append(m, "(sv)", field, "t", v);
if (r < 0)
r = parse_permyriad(eq);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s=%s: %m", field, eq);
+ return parse_log_error(r, field, eq);
/* Pass around scaled to 2^32-1 == 100% */
r = sd_bus_message_append(m, "(sv)", field, "u", UINT32_SCALE_FROM_PERMYRIAD(r));
r = parse_cpu_set(eq, &cpuset);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s value: %s", field, eq);
+ return parse_log_error(r, field, eq);
r = cpu_set_to_dbus(&cpuset, &array, &allocated);
if (r < 0)
else {
r = parse_permyriad_unbounded(eq);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s=%s: %m", field, eq);
+ return parse_log_error(r, field, eq);
if (r == 0)
- return log_error_errno(SYNTHETIC_ERRNO(ERANGE), "%s value too small.", field);
+ return parse_log_error(SYNTHETIC_ERRNO(ERANGE), field, eq);
x = r * USEC_PER_SEC / 10000U;
}
else {
const char *e = strchr(eq, ' ');
if (!e)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "Failed to parse %s value %s.",
- field, eq);
+ return parse_log_error(0, field, eq);
const char *bandwidth = e + 1;
_cleanup_free_ char *path = strndup(eq, e - eq);
else {
r = parse_size(bandwidth, 1000, &bytes);
if (r < 0)
- return log_error_errno(r, "Failed to parse byte value %s: %m", bandwidth);
+ return parse_log_error(r, field, eq);
}
r = sd_bus_message_append(m, "(sv)", field, "a(st)", 1, path, bytes);
else {
const char *e = strchr(eq, ' ');
if (!e)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "Failed to parse %s value %s.",
- field, eq);
+ return parse_log_error(0, field, eq);
const char *weight = e + 1;
_cleanup_free_ char *path = strndup(eq, e - eq);
uint64_t u;
r = safe_atou64(weight, &u);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s value %s: %m", field, weight);
+ return parse_log_error(r, field, weight);
r = sd_bus_message_append(m, "(sv)", field, "a(st)", 1, path, u);
}
else {
const char *e = strchr(eq, ' ');
if (!e)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "Failed to parse %s value %s.",
- field, eq);
+ return parse_log_error(0, field, eq);
const char *target = e + 1;
_cleanup_free_ char *path = strndup(eq, e - eq);
usec_t usec;
r = parse_sec(target, &usec);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s value %s: %m", field, target);
+ return parse_log_error(r, field, target);
r = sd_bus_message_append(m, "(sv)", field_usec, "a(st)", 1, path, usec);
}
_cleanup_free_ char *word = NULL;
r = extract_first_word(&eq, &word, ":", 0);
- if (r == -ENOMEM)
- return log_oom();
if (r < 0)
- return log_error_errno(r, "Failed to parse %s: %m", field);
+ return parse_log_error(r, field, eq);
r = sd_bus_message_append(m, "(sv)", field, "a(ss)", 1, word, eq);
}
uint16_t nr_ports, port_min;
r = parse_socket_bind_item(eq, &family, &ip_protocol, &nr_ports, &port_min);
- if (r == -ENOMEM)
- return log_oom();
if (r < 0)
- return log_error_errno(r, "Failed to parse %s", field);
+ return parse_log_error(r, field, eq);
r = sd_bus_message_append(
m, "(sv)", field, "a(iiqq)", 1, family, ip_protocol, nr_ports, port_min);
if (is_ex_prop) {
r = exec_command_flags_to_strv(flags, &ex_opts);
if (r < 0)
- return log_error_errno(r, "Failed to convert ExecCommandFlags to strv: %m");
+ return log_error_errno(r, "Failed to serialize ExecCommand flags: %m");
}
const char *path = NULL;
else if (explicit_path) {
r = extract_first_word(&eq, &_path, NULL, EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE);
if (r < 0)
- return log_error_errno(r, "Failed to parse path: %m");
+ return parse_log_error(r, field, eq);
if (r == 0)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No executable path specified, refusing.");
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No executable path specified for %s=, refusing.", field);
if (isempty(eq))
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Got empty command line, refusing.");
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Got empty command line for %s=, refusing.", field);
path = _path;
}
r = strv_split_full(&cmdline, eq, NULL, EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE);
if (r < 0)
- return log_error_errno(r, "Failed to parse command line: %m");
+ return parse_log_error(r, field, eq);
if (FLAGS_SET(flags, EXEC_COMMAND_VIA_SHELL)) {
r = strv_prepend(&cmdline, explicit_path ? "-sh" : "sh");
r = open_file_parse(eq, &of);
if (r < 0)
- return log_error_errno(r, "Failed to parse OpenFile= setting: %m");
+ return parse_log_error(r, field, eq);
r = sd_bus_message_append(m, "(sv)", field, "a(sst)", (size_t) 1, of->path, of->fdname, of->flags);
if (r < 0)
_cleanup_free_ char *word = NULL;
r = extract_first_word(&eq, &word, NULL, 0);
- if (r == -ENOMEM)
- return log_oom();
if (r < 0)
- return log_error_errno(r, "Failed to parse %s: %s", field, eq);
+ return parse_log_error(r, field, eq);
if (r == 0)
break;
r = in_addr_prefix_from_string_auto(word, &family, &prefix, &prefixlen);
if (r < 0)
- return log_error_errno(r, "Failed to parse IP address prefix: %s", word);
+ return log_error_errno(r, "Failed to parse IP address prefix '%s': %m", word);
r = bus_append_ip_address_access(m, family, &prefix, prefixlen);
if (r < 0)
int source, nfproto;
r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
- if (r == -ENOMEM)
- return log_oom();
if (r < 0)
- return log_error_errno(r, "Failed to parse %s: %m", field);
+ return parse_log_error(r, field, eq);
if (r == 0)
break;
if (isempty(tuple))
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to parse %s.", field);
+ return parse_log_error(0, field, eq);
q = tuple;
r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE, &source_str, &nfproto_str, &table, &set);
- if (r == -ENOMEM)
- return log_oom();
if (r != 4 || !isempty(q))
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to parse %s.", field);
+ return parse_log_error(0, field, tuple);
assert(source_str);
assert(nfproto_str);
const char *p = eq;
r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
- if (r == -ENOMEM)
- return log_oom();
- if (r < 0)
- return log_error_errno(r, "Failed to parse %s= parameter: %s", field, eq);
- if (r == 0 || !p)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Missing argument to %s=.", field);
+ if (r <= 0 || !p)
+ return parse_log_error(r < 0 ? r : 0, field, eq);
r = sd_bus_message_open_container(m, 'a', "(say)");
if (r < 0)
if (r < 0)
return bus_log_create_error(r);
- if (streq(field, "SetCredentialEncrypted")) {
+ if (endswith(field, "Encrypted")) {
_cleanup_free_ void *decoded = NULL;
size_t decoded_size;
r = unbase64mem(p, &decoded, &decoded_size);
if (r < 0)
- return log_error_errno(r, "Failed to base64 decode encrypted credential: %m");
+ return log_error_errno(r, "Failed to decode base64 data for %s=: %m", field);
r = sd_bus_message_append_array(m, 'y', decoded, decoded_size);
} else {
l = cunescape(p, UNESCAPE_ACCEPT_NUL, &unescaped);
if (l < 0)
- return log_error_errno(l, "Failed to unescape %s= value: %s", field, p);
+ return log_error_errno(l, "Failed to unescape value for %s=: %s", field, p);
r = sd_bus_message_append_array(m, 'y', unescaped, l);
}
const char *p = eq;
r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
- if (r == -ENOMEM)
- return log_oom();
- if (r < 0)
- return log_error_errno(r, "Failed to parse %s= parameter: %s", field, eq);
- if (r == 0)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Missing argument to %s=.", field);
+ if (r <= 0)
+ return parse_log_error(r, field, eq);
if (isempty(p)) /* If only one field is specified, then this means "inherit from above" */
p = eq;
const char *p = eq;
r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
- if (r == -ENOMEM)
- return log_oom();
- if (r < 0)
- return log_error_errno(r, "Failed to parse %s= parameter: %s", field, eq);
- if (r == 0)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Missing argument to %s=.", field);
+ if (r <= 0)
+ return parse_log_error(r, field, eq);
if (!p)
r = sd_bus_message_append(m, "(sv)", "ImportCredential", "as", 1, eq);
l = cunescape(eq, 0, &unescaped);
if (l < 0)
- return log_error_errno(l, "Failed to unescape text '%s': %m", eq);
+ return log_error_errno(l, "Failed to unescape value for %s=: %s", field, eq);
if (!strextend(&unescaped, "\n"))
return log_oom();
r = unbase64mem(eq, &decoded, &sz);
if (r < 0)
- return log_error_errno(r, "Failed to decode base64 data '%s': %m", eq);
+ return log_error_errno(r, "Failed to decode base64 data for %s=: %m", field);
return bus_append_byte_array(m, field, decoded, sz);
}
int rl = rlimit_from_string(suffix);
if (rl < 0)
- return log_error_errno(rl, "Unknown setting '%s'.", field);
+ return 0; /* We let the generic error machinery handle this. */
struct rlimit l;
r = rlimit_parse(rl, eq, &l);
if (r < 0)
- return log_error_errno(r, "Failed to parse resource limit: %s", eq);
+ return parse_log_error(r, field, eq);
r = sd_bus_message_append(m, "(sv)", field, "t", (uint64_t) l.rlim_max);
if (r < 0)
r = capability_set_from_string(p, &sum);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s value %s: %m", field, eq);
+ return parse_log_error(r, field, eq);
sum = invert ? ~sum : sum;
} else {
r = parse_cpu_set(eq, &nodes);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s value: %s", field, eq);
+ return parse_log_error(r, field, eq);
}
r = cpu_set_to_dbus(&nodes, &array, &allocated);
_cleanup_free_ char *word = NULL;
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
- if (r == -ENOMEM)
- return log_oom();
if (r < 0)
- return log_error_errno(r, "Invalid syntax: %s", eq);
+ return parse_log_error(r, field, eq);
if (r == 0)
break;
r = namespace_flags_from_string(eq, &flags);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s value %s.", field, eq);
+ return parse_log_error(r, field, eq);
}
if (invert)
r = extract_first_word(&p, &source, ":" WHITESPACE, EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS);
if (r < 0)
- return log_error_errno(r, "Failed to parse argument: %m");
+ return parse_log_error(r, field, eq);
if (r == 0)
break;
if (p && p[-1] == ':') {
r = extract_first_word(&p, &destination, ":" WHITESPACE, EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS);
if (r < 0)
- return log_error_errno(r, "Failed to parse argument: %m");
+ return parse_log_error(r, field, p);
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Missing argument after ':': %s", eq);
r = extract_first_word(&p, &options, NULL, EXTRACT_UNQUOTE);
if (r < 0)
- return log_error_errno(r, "Failed to parse argument: %m");
+ return parse_log_error(r, field, p);
if (isempty(options) || streq(options, "rbind"))
flags = MS_REC;
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
if (r < 0)
- return log_error_errno(r, "Failed to parse argument: %m");
+ return parse_log_error(r, field, eq);
if (r == 0)
break;
w = word;
r = extract_first_word(&w, &path, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
- if (r < 0)
- return log_error_errno(r, "Failed to parse argument: %m");
- if (r == 0)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "Failed to parse argument: %s", p);
+ if (r <= 0)
+ return parse_log_error(r, field, eq);
r = sd_bus_message_append(m, "(ss)", path, w);
if (r < 0)
/* We have a roothash to decode, eg: RootHash=012345789abcdef */
r = unhexmem(eq, &roothash_decoded, &roothash_decoded_size);
if (r < 0)
- return log_error_errno(r, "Failed to decode RootHash= '%s': %m", eq);
+ return log_error_errno(r, "Failed to decode base64 data for %s=: %m", field);
if (roothash_decoded_size < sizeof(sd_id128_t))
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "RootHash= '%s' is too short.", eq);
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "%s value '%s' is too short.", field, eq);
return bus_append_byte_array(m, field, roothash_decoded, roothash_decoded_size);
}
if (!(value = startswith(eq, "base64:")))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "Failed to decode %s=%s: neither a path nor starts with 'base64:'.",
+ "Failed to decode %s value '%s': neither a path nor starts with 'base64:'.",
field, eq);
/* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
r = unbase64mem(value, &roothash_sig_decoded, &roothash_sig_decoded_size);
if (r < 0)
- return log_error_errno(r, "Failed to decode %s=%s: %m", field, eq);
+ return log_error_errno(r, "Failed to decode base64 data for %s=: %m", field);
return bus_append_byte_array(m, field, roothash_sig_decoded, roothash_sig_decoded_size);
}
r = strv_split_colon_pairs(&l, p);
if (r < 0)
- return log_error_errno(r, "Failed to parse argument: %m");
+ return parse_log_error(r, field, eq);
STRV_FOREACH_PAIR(first, second, l) {
r = sd_bus_message_append(m, "(ss)",
r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s property: %s", field, eq);
+ return parse_log_error(r, field, eq);
if (r == 0)
break;
q = tuple;
r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &first, &second);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s property: %s", field, eq);
+ return parse_log_error(r, field, eq);
if (r == 0)
continue;
if (isempty(second))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "Missing argument after ':' for %s: %s", field, eq);
+ "Missing argument after ':' for %s=: '%s'", field, eq);
r = sd_bus_message_open_container(m, 'r', "ssba(ss)");
if (r < 0)
r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s property: %s", field, eq);
+ return parse_log_error(r, field, eq);
if (r == 0)
break;
/* Single set of options, applying to the root partition/single filesystem */
r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s property: %s", field, eq);
+ return parse_log_error(r, field, eq);
if (r == 0)
break;
q = tuple;
r = extract_first_word(&q, &source, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s property: %s", field, eq);
+ return parse_log_error(r, field, eq);
if (r == 0)
continue;
r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s property: %s", field, eq);
+ return parse_log_error(r, field, eq);
if (r == 0)
break;
/* Single set of options, applying to the root partition/single filesystem */
r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE);
if (r < 0)
- return log_error_errno(r, "Failed to parse argument: %m");
+ return parse_log_error(r, field, eq);
if (r == 0)
break;
const char *t = tuple;
r = extract_many_words(&t, ":", EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS, &source, &dest, &flags);
if (r <= 0)
- return log_error_errno(r ?: SYNTHETIC_ERRNO(EINVAL), "Failed to parse argument: %m");
+ return parse_log_error(r, field, eq);
path_simplify(source);
} else {
ExecDirectoryFlags exec_directory_flags = exec_directory_flags_from_string(flags);
if (exec_directory_flags < 0 || (exec_directory_flags & ~_EXEC_DIRECTORY_FLAGS_PUBLIC) != 0)
- return log_error_errno(r, "Failed to parse flags: %s", flags);
+ return log_error_errno(r, "Failed to parse flags for %s=: '%s'", field, flags);
if (!isempty(dest)) {
path_simplify(dest);
const char *colon = strchr(eq, ':');
if (colon) {
if (isempty(colon + 1))
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to parse argument: %s=%s", field, eq);
+ return parse_log_error(0, field, eq);
_cleanup_free_ char *p = strndup(eq, colon - eq);
if (!p)
_cleanup_free_ char *word = NULL;
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
- if (r == -ENOMEM)
- return log_oom();
if (r < 0)
- return log_error_errno(r, "Invalid syntax in %s: %s", field, eq);
+ return parse_log_error(r, field, eq);
if (r == 0)
break;
} else
/* original r from exit_status_to_string() */
- return log_error_errno(r, "Invalid status or signal %s in %s: %m",
- word, field);
+ return parse_log_error(r, field, word);
}
r = sd_bus_message_open_container(m, SD_BUS_TYPE_STRUCT, "sv");
r = safe_atou8(eq, &u);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s=%s", field, eq);
+ return parse_log_error(r, field, eq);
r = sd_bus_message_append(m, "(sv)", field, "i", (int) u);
}
usec_t t;
r = parse_sec(eq, &t);
if (r < 0)
- return log_error_errno(r, "Failed to parse %s=%s: %m", field, eq);
+ return parse_log_error(r, field, eq);
r = sd_bus_message_append(m, "(sv)", "TimersMonotonic", "a(st)", 1, field, t);
}