]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevadm-trigger: replace home-made key/value splitting function
authorDavid Tardon <dtardon@redhat.com>
Tue, 29 Apr 2025 11:57:10 +0000 (13:57 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 9 May 2025 00:54:25 +0000 (09:54 +0900)
src/udev/udevadm-trigger.c

index 5a45a93ac98c747883b667f542c91dac5bdfebc2..b7eed70e7047a5a5b1e6da397be09219a7dce853 100644 (file)
@@ -190,25 +190,6 @@ static int device_monitor_handler(sd_device_monitor *m, sd_device *dev, void *us
         return 0;
 }
 
-static char* keyval(const char *str, const char **key, const char **val) {
-        char *buf, *pos;
-
-        buf = strdup(str);
-        if (!buf)
-                return NULL;
-
-        pos = strchr(buf, '=');
-        if (pos) {
-                pos[0] = 0;
-                pos++;
-        }
-
-        *key = buf;
-        *val = pos;
-
-        return buf;
-}
-
 static int add_device_match(sd_device_enumerator *e, const char *s, const char *prefix) {
         _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
         int r;
@@ -263,12 +244,11 @@ static int setup_matches(sd_device_enumerator *e) {
         }
 
         STRV_FOREACH(a, arg_attr_match) {
-                _cleanup_free_ char *buf = NULL;
-                const char *k, *v;
+                _cleanup_free_ char *k = NULL, *v = NULL;
 
-                buf = keyval(*a, &k, &v);
-                if (!buf)
-                        return log_oom();
+                r = parse_key_value_argument(*a, /* require_value= */ false, &k, &v);
+                if (r < 0)
+                        return r;
 
                 r = sd_device_enumerator_add_match_sysattr(e, k, v, /* match= */ true);
                 if (r < 0)
@@ -276,12 +256,11 @@ static int setup_matches(sd_device_enumerator *e) {
         }
 
         STRV_FOREACH(a, arg_attr_nomatch) {
-                _cleanup_free_ char *buf = NULL;
-                const char *k, *v;
+                _cleanup_free_ char *k = NULL, *v = NULL;
 
-                buf = keyval(*a, &k, &v);
-                if (!buf)
-                        return log_oom();
+                r = parse_key_value_argument(*a, /* require_value= */ false, &k, &v);
+                if (r < 0)
+                        return r;
 
                 r = sd_device_enumerator_add_match_sysattr(e, k, v, /* match= */ false);
                 if (r < 0)
@@ -289,12 +268,11 @@ static int setup_matches(sd_device_enumerator *e) {
         }
 
         STRV_FOREACH(p, arg_property_match) {
-                _cleanup_free_ char *buf = NULL;
-                const char *k, *v;
+                _cleanup_free_ char *k = NULL, *v = NULL;
 
-                buf = keyval(*p, &k, &v);
-                if (!buf)
-                        return log_oom();
+                r = parse_key_value_argument(*p, /* require_value= */ true, &k, &v);
+                if (r < 0)
+                        return r;
 
                 r = sd_device_enumerator_add_match_property(e, k, v);
                 if (r < 0)