From: Zbigniew Jędrzejewski-Szmek Date: Fri, 4 Jul 2025 15:18:16 +0000 (+0200) Subject: shared/bus-unit-util: rework error messages X-Git-Tag: v258-rc1~150^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=95a3cfcbf6bedb211be0c7f9a7f6047b8748c435;p=thirdparty%2Fsystemd.git shared/bus-unit-util: rework error messages We generally want to have error messages with a fixed structure that convey the important information, i.e. field name, error value, and the offending text for options that take short values. (The text is not printed for strings encoded with base64 and hexmem or for credentials.) Let's use a helper that prints the message in a fixed format in the majority of cases. In the few places where a custom message is useful, the helper is not used. The helper: - prints the field name, value, and error info, - quotes the value, - handles -ENOMEM, so we don't need to handle it separately everywhere. When this code was originally written, parse functions would return -1 as error. Nowadays day all return a good errno, so it is fine if we print the corresponding strerror. --- diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index d98550dd0b5..ebfabcdf360 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -76,6 +76,17 @@ static int warn_deprecated(_unused_ sd_bus_message *m, const char *field, const 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, \ @@ -86,7 +97,7 @@ static int warn_deprecated(_unused_ sd_bus_message *m, const char *field, const \ 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); \ @@ -105,7 +116,7 @@ static int warn_deprecated(_unused_ sd_bus_message *m, const char *field, const \ 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); \ @@ -175,10 +186,8 @@ static int bus_append_strv_full(sd_bus_message *m, const char *field, const char _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; @@ -248,7 +257,7 @@ static int bus_append_parse_sec_rename(sd_bus_message *m, const char *field, con 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); @@ -272,7 +281,7 @@ static int bus_append_parse_size(sd_bus_message *m, const char *field, const cha 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) @@ -286,7 +295,7 @@ static int bus_append_parse_permyriad(sd_bus_message *m, const char *field, cons 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)); @@ -304,7 +313,7 @@ static int bus_append_parse_cpu_set(sd_bus_message *m, const char *field, const 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) @@ -376,9 +385,9 @@ static int bus_append_parse_cpu_quota(sd_bus_message *m, const char *field, cons 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; } @@ -426,9 +435,7 @@ static int bus_try_append_parse_cgroup_io_limit(sd_bus_message *m, const char *f 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); @@ -441,7 +448,7 @@ static int bus_try_append_parse_cgroup_io_limit(sd_bus_message *m, const char *f 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); @@ -460,9 +467,7 @@ static int bus_append_parse_io_device_weight(sd_bus_message *m, const char *fiel 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); @@ -472,7 +477,7 @@ static int bus_append_parse_io_device_weight(sd_bus_message *m, const char *fiel 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); } @@ -491,9 +496,7 @@ static int bus_append_parse_io_device_latency(sd_bus_message *m, const char *fie 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); @@ -503,7 +506,7 @@ static int bus_append_parse_io_device_latency(sd_bus_message *m, const char *fie 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); } @@ -522,10 +525,8 @@ static int bus_append_bpf_program(sd_bus_message *m, const char *field, const ch _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); } @@ -545,10 +546,8 @@ static int bus_append_socket_filter(sd_bus_message *m, const char *field, const 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); @@ -652,7 +651,7 @@ static int bus_append_exec_command(sd_bus_message *m, const char *field, const c 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; @@ -661,17 +660,17 @@ static int bus_append_exec_command(sd_bus_message *m, const char *field, const c 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"); @@ -741,7 +740,7 @@ static int bus_append_open_file(sd_bus_message *m, const char *field, const char 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) @@ -863,16 +862,14 @@ static int bus_append_parse_ip_address_filter(sd_bus_message *m, const char *fie _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) @@ -947,21 +944,17 @@ static int bus_append_nft_set(sd_bus_message *m, const char *field, const char * 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); @@ -1024,12 +1017,8 @@ static int bus_append_set_credential(sd_bus_message *m, const char *field, const 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) @@ -1043,13 +1032,13 @@ static int bus_append_set_credential(sd_bus_message *m, const char *field, const 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 { @@ -1058,7 +1047,7 @@ static int bus_append_set_credential(sd_bus_message *m, const char *field, const 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); } @@ -1107,12 +1096,8 @@ static int bus_append_load_credential(sd_bus_message *m, const char *field, cons 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; @@ -1143,12 +1128,8 @@ static int bus_append_import_credential(sd_bus_message *m, const char *field, co 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); @@ -1258,7 +1239,7 @@ static int bus_append_standard_input_text(sd_bus_message *m, const char *field, 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(); @@ -1276,7 +1257,7 @@ static int bus_append_standard_input_data(sd_bus_message *m, const char *field, 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); } @@ -1290,12 +1271,12 @@ static int bus_try_append_resource_limit(sd_bus_message *m, const char *field, c 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) @@ -1343,7 +1324,7 @@ static int bus_append_capabilities(sd_bus_message *m, const char *field, const c 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; @@ -1380,7 +1361,7 @@ static int bus_append_numa_mask(sd_bus_message *m, const char *field, const char } 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); @@ -1428,10 +1409,8 @@ static int bus_append_filter_list(sd_bus_message *m, const char *field, const ch _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; @@ -1481,7 +1460,7 @@ static int bus_append_namespace_list(sd_bus_message *m, const char *field, const 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) @@ -1522,7 +1501,7 @@ static int bus_append_bind_paths(sd_bus_message *m, const char *field, const cha 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; @@ -1535,7 +1514,7 @@ static int bus_append_bind_paths(sd_bus_message *m, const char *field, const cha 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); @@ -1547,7 +1526,7 @@ static int bus_append_bind_paths(sd_bus_message *m, const char *field, const cha 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; @@ -1606,17 +1585,14 @@ static int bus_append_temporary_file_system(sd_bus_message *m, const char *field 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) @@ -1650,9 +1626,9 @@ static int bus_append_root_hash(sd_bus_message *m, const char *field, const char /* 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); } @@ -1669,13 +1645,13 @@ static int bus_append_root_hash_signature(sd_bus_message *m, const char *field, 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); } @@ -1703,7 +1679,7 @@ static int bus_append_root_image_options(sd_bus_message *m, const char *field, c 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)", @@ -1755,14 +1731,14 @@ static int bus_append_mount_images(sd_bus_message *m, const char *field, const c 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; @@ -1774,7 +1750,7 @@ static int bus_append_mount_images(sd_bus_message *m, const char *field, const c 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) @@ -1793,7 +1769,7 @@ static int bus_append_mount_images(sd_bus_message *m, const char *field, const c 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 */ @@ -1861,14 +1837,14 @@ static int bus_append_extension_images(sd_bus_message *m, const char *field, con 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; @@ -1895,7 +1871,7 @@ static int bus_append_extension_images(sd_bus_message *m, const char *field, con 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 */ @@ -1950,14 +1926,14 @@ static int bus_append_directory(sd_bus_message *m, const char *field, const char 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); @@ -1973,7 +1949,7 @@ static int bus_append_directory(sd_bus_message *m, const char *field, const char } 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); @@ -2091,7 +2067,7 @@ static int bus_append_protect_hostname(sd_bus_message *m, const char *field, con 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) @@ -2121,10 +2097,8 @@ static int bus_append_exit_status(sd_bus_message *m, const char *field, const ch _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; @@ -2148,8 +2122,7 @@ static int bus_append_exit_status(sd_bus_message *m, const char *field, const ch } 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"); @@ -2201,7 +2174,7 @@ static int bus_append_action_exit_status(sd_bus_message *m, const char *field, c 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); } @@ -2227,7 +2200,7 @@ static int bus_append_timers_monotonic(sd_bus_message *m, const char *field, con 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); } diff --git a/src/test/test-bus-unit-util.c b/src/test/test-bus-unit-util.c index a5207fa02d5..677615a2d3e 100644 --- a/src/test/test-bus-unit-util.c +++ b/src/test/test-bus-unit-util.c @@ -142,6 +142,7 @@ TEST(cgroup_properties) { "CPUQuota=200%", "CPUQuotaPeriodSec=100ms", "CPUQuotaPeriodSec=1s", + "-ERANGE CPUQuota=0%", "DeviceAllow=/dev/null rw", "DeviceAllow=/dev/zero r", @@ -382,6 +383,7 @@ TEST(execute_properties) { "CPUSchedulingPriority=50", "CPUSchedulingPriority=1", "CPUSchedulingPriority=99", + "-ERANGE CPUSchedulingPriority=2147483648", "OOMScoreAdjust=100", "OOMScoreAdjust=-100", @@ -579,8 +581,8 @@ TEST(kill_properties) { "KillSignal=1", "KillSignal=64", /* _NSIG == 64 */ - "-EINVAL KillSignal=0", - "-EINVAL KillSignal=65", + "-ERANGE KillSignal=0", + "-ERANGE KillSignal=65", "RestartKillSignal=TERM", "RestartKillSignal=SIGTERM", "FinalKillSignal=WINCH", @@ -591,7 +593,7 @@ TEST(kill_properties) { "ReloadSignal=RTMAX", "ReloadSignal=RTMAX-0", "ReloadSignal=RTMAX-5", - "-EINVAL ReloadSignal=RTMAX-100" + "-ERANGE ReloadSignal=RTMAX-100" ); test_transient_settings_one(UNIT_SCOPE, lines);