]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-util: add wrapper for sd_device_get_property_value()
authorDavid Tardon <dtardon@redhat.com>
Mon, 13 Nov 2023 15:11:41 +0000 (16:11 +0100)
committerDavid Tardon <dtardon@redhat.com>
Mon, 13 Nov 2023 18:18:23 +0000 (19:18 +0100)
... that allows to pass additional properties to fall back to.

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

index 8d55fb58b37eccaaaa4f2608adb2410a8ab881c7..cf28ba864796d20704b9b70cd567e3851a73071d 100644 (file)
@@ -410,3 +410,30 @@ int device_get_model_string(sd_device *device, const char **ret) {
 
         return -ENOENT;
 }
+
+int device_get_property_value_with_fallback(
+                sd_device *device,
+                const char *prop,
+                Hashmap *extra_props,
+                const char **ret) {
+        const char *value;
+        int r;
+
+        assert(device);
+        assert(prop);
+        assert(ret);
+
+        r = sd_device_get_property_value(device, prop, &value);
+        if (r < 0) {
+                if (r != -ENOENT)
+                        return r;
+
+                value = hashmap_get(extra_props, prop);
+                if (!value)
+                        return -ENOENT;
+        }
+
+        *ret = value;
+
+        return 1;
+}
index 129b11fae3194bdf1a07f09984f835aaa34a58c2..651d335b9698611f31a3c696032d64dc3f1d8a4f 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "sd-device.h"
 
+#include "hashmap.h"
 #include "time-util.h"
 
 int udev_set_max_log_level(char *str);
@@ -25,3 +26,9 @@ bool udev_available(void);
 
 int device_get_vendor_string(sd_device *device, const char **ret);
 int device_get_model_string(sd_device *device, const char **ret);
+
+int device_get_property_value_with_fallback(
+                sd_device *device,
+                const char *prop,
+                Hashmap *extra_props,
+                const char **ret);