chiark / gitweb /
libudev: introduce udev_device_properties_copy()
authorTom Gundersen <teg@jklm.no>
Fri, 6 Mar 2015 17:30:09 +0000 (18:30 +0100)
committerTom Gundersen <teg@jklm.no>
Thu, 12 Mar 2015 10:59:04 +0000 (11:59 +0100)
To copy properties from one device to another. Drop the equivalent functionality from udevd.

src/libudev/libudev-device.c
src/libudev/libudev-private.h
src/udev/udev-event.c

index 242a0d8..2604ad7 100644 (file)
@@ -2030,3 +2030,18 @@ struct udev_device *udev_device_new_from_nulstr(struct udev *udev, char *nulstr,
 
         return device;
 }
+
+int udev_device_copy_properties(struct udev_device *dst, struct udev_device *src) {
+        struct udev_list_entry *entry;
+
+        for ((entry = udev_device_get_properties_list_entry(src)); entry; entry = udev_list_entry_get_next(entry)) {
+                const char *key, *value;
+
+                key = udev_list_entry_get_name(entry);
+                value = udev_list_entry_get_value(entry);
+
+                udev_device_add_property(dst, key, value);
+        }
+
+        return 0;
+}
index 9153e67..c0f9fbe 100644 (file)
@@ -39,6 +39,7 @@ int udev_get_rules_path(struct udev *udev, char **path[], usec_t *ts_usec[]);
 /* libudev-device.c */
 struct udev_device *udev_device_new_from_nulstr(struct udev *udev, char *nulstr, ssize_t buflen);
 struct udev_device *udev_device_shallow_clone(struct udev_device *old_device);
+int udev_device_copy_properties(struct udev_device *dst, struct udev_device *src);
 mode_t udev_device_get_devnode_mode(struct udev_device *udev_device);
 uid_t udev_device_get_devnode_uid(struct udev_device *udev_device);
 gid_t udev_device_get_devnode_gid(struct udev_device *udev_device);
index 67fb1f7..b96cf73 100644 (file)
@@ -819,18 +819,8 @@ void udev_event_execute_rules(struct udev_event *event,
                 }
 
                 if (major(udev_device_get_devnum(dev)) == 0 &&
-                    streq(udev_device_get_action(dev), "move")) {
-                        struct udev_list_entry *entry;
-
-                        for ((entry = udev_device_get_properties_list_entry(event->dev_db)); entry; entry = udev_list_entry_get_next(entry)) {
-                                const char *key, *value;
-
-                                key = udev_list_entry_get_name(entry);
-                                value = udev_list_entry_get_value(entry);
-
-                                udev_device_add_property(dev, key, value);
-                        }
-                }
+                    streq(udev_device_get_action(dev), "move"))
+                        udev_device_copy_properties(dev, event->dev_db);
 
                 udev_rules_apply_to_event(rules, event,
                                           timeout_usec, timeout_warn_usec,