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
d89b3004da due to an extra check before
calling parse_key_value_argument().)
This commit is contained in:
Frantisek Sumsal
2025-05-26 16:56:55 +02:00
parent a6b5e57274
commit 1420ffffc5
2 changed files with 5 additions and 4 deletions
+4 -3
View File
@@ -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);
+1 -1
View File
@@ -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);