From: Frantisek Sumsal Date: Mon, 26 May 2025 14:44:13 +0000 (+0200) Subject: udevadm-info: print the original input on error X-Git-Tag: v258-rc1~485^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1420ffffc58a30bf85c4dc6ab9500401c156b8db;p=thirdparty%2Fsystemd.git udevadm-info: print the original input on error Print the original input value on error instead of the consumed string (which will be empty). Previously: $ udevadm info /dev/block/251:0 -e --attr-match='foo=\' Failed to parse key/value pair : Invalid argument $ udevadm info /dev/block/251:0 -e --attr-match='foo' Missing '=' in key/value pair (null). Now: $ build/udevadm info /dev/block/251:0 -e --attr-match='foo=\' Failed to parse key/value pair foo=\: Invalid argument (The second scenario can't be hit anymore since d89b3004da54228eb5ab2f3326a773a6e97924b9 due to an extra check before calling parse_key_value_argument().) --- diff --git a/src/udev/udevadm-util.c b/src/udev/udevadm-util.c index 09fb24f6e5b..73c39f696c4 100644 --- a/src/udev/udevadm-util.c +++ b/src/udev/udevadm-util.c @@ -152,8 +152,9 @@ int parse_resolve_name_timing(const char *str, ResolveNameTiming *ret) { return 1; } -int parse_key_value_argument(const char *s, bool require_value, char **key, char **value) { +int parse_key_value_argument(const char *str, bool require_value, char **key, char **value) { _cleanup_free_ char *k = NULL, *v = NULL; + const char *s = str; int r; assert(s); @@ -162,9 +163,9 @@ int parse_key_value_argument(const char *s, bool require_value, char **key, char r = extract_many_words(&s, "=", EXTRACT_DONT_COALESCE_SEPARATORS, &k, &v); if (r < 0) - return log_error_errno(r, "Failed to parse key/value pair %s: %m", s); + return log_error_errno(r, "Failed to parse key/value pair %s: %m", str); if (require_value && r < 2) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Missing '=' in key/value pair %s.", s); + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Missing '=' in key/value pair %s.", str); if (!filename_is_valid(k)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "%s is not a valid key name", k); diff --git a/src/udev/udevadm-util.h b/src/udev/udevadm-util.h index 9b41109df86..aca46189775 100644 --- a/src/udev/udevadm-util.h +++ b/src/udev/udevadm-util.h @@ -10,6 +10,6 @@ int find_device(const char *id, const char *prefix, sd_device **ret); int find_device_with_action(const char *id, sd_device_action_t action, sd_device **ret); int parse_device_action(const char *str, sd_device_action_t *ret); int parse_resolve_name_timing(const char *str, ResolveNameTiming *ret); -int parse_key_value_argument(const char *s, bool require_value, char **key, char **value); +int parse_key_value_argument(const char *str, bool require_value, char **key, char **value); int udev_ping(usec_t timeout, bool ignore_connection_failure); int search_rules_files(char * const *a, const char *root, char ***ret);