]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevadm-info: print the original input on error
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 26 May 2025 14:44:13 +0000 (16:44 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 26 May 2025 14:56:55 +0000 (16:56 +0200)
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().)

src/udev/udevadm-util.c
src/udev/udevadm-util.h

index 09fb24f6e5b829624f5b8d60b93e8b0ea8679353..73c39f696c4e25572889a05fa84df64d201a7286 100644 (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);
index 9b41109df86fc43af2cc170046a9056e3bdf266f..aca461897756677dfed685b3287f50c07c524f33 100644 (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);