]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev/builtin: introduce udev_builtin_import_property() helper function
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 8 Jan 2024 16:12:20 +0000 (01:12 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 9 Jan 2024 19:11:08 +0000 (04:11 +0900)
This is not used in this commit, but will be used later commits.

src/udev/udev-builtin.c
src/udev/udev-builtin.h

index bcc2018c6fb7d01f43f6b5ab77f9f5cd0bbcc73d..6caea8eccee8cec4a60f80464d35ca686e901818 100644 (file)
@@ -154,3 +154,26 @@ int udev_builtin_add_propertyf(sd_device *dev, bool test, const char *key, const
 
         return udev_builtin_add_property(dev, test, key, val);
 }
+
+int udev_builtin_import_property(sd_device *dev, sd_device *src, bool test, const char *key) {
+        const char *val;
+        int r;
+
+        assert(dev);
+        assert(key);
+
+        if (!src)
+                return 0;
+
+        r = sd_device_get_property_value(src, key, &val);
+        if (r == -ENOENT)
+                return 0;
+        if (r < 0)
+                return log_device_debug_errno(src, r, "Failed to get property \"%s\", ignoring: %m", key);
+
+        r = udev_builtin_add_property(dev, test, key, val);
+        if (r < 0)
+                return r;
+
+        return 1;
+}
index fcd41d615de4d63c72658c1990b7f1480a0e2a3e..c7a48b0201cee858ad96230dfa198c9e08b71122 100644 (file)
@@ -84,5 +84,6 @@ void udev_builtin_list(void);
 bool udev_builtin_should_reload(void);
 int udev_builtin_add_property(sd_device *dev, bool test, const char *key, const char *val);
 int udev_builtin_add_propertyf(sd_device *dev, bool test, const char *key, const char *valf, ...) _printf_(4, 5);
+int udev_builtin_import_property(sd_device *dev, sd_device *src, bool test, const char *key);
 int udev_builtin_hwdb_lookup(sd_device *dev, const char *prefix, const char *modalias,
                              const char *filter, bool test);