chiark / gitweb /
udev: event - introduce and use internal udev_device_shallow_clone()
authorTom Gundersen <teg@jklm.no>
Mon, 26 Jan 2015 13:12:45 +0000 (14:12 +0100)
committerTom Gundersen <teg@jklm.no>
Mon, 26 Jan 2015 13:12:45 +0000 (14:12 +0100)
src/libudev/libudev-device.c
src/libudev/libudev-private.h
src/udev/udev-event.c

index 193c706..08331a2 100644 (file)
@@ -1944,3 +1944,24 @@ int udev_device_rename(struct udev_device *udev_device, const char *name)
 
         return 0;
 }
+
+struct udev_device *udev_device_shallow_clone(struct udev_device *old_device)
+{
+        struct udev_device *device;
+
+        if (old_device == NULL)
+                return NULL;
+
+        device = udev_device_new(old_device->udev);
+        if (!device) {
+                errno = ENOMEM;
+
+                return NULL;
+        }
+
+        udev_device_set_syspath(device, udev_device_get_syspath(old_device));
+        udev_device_set_subsystem(device, udev_device_get_subsystem(old_device));
+        udev_device_set_devnum(device, udev_device_get_devnum(old_device));
+
+        return device;
+}
index 017b6cc..31f150c 100644 (file)
@@ -38,6 +38,7 @@ int udev_get_rules_path(struct udev *udev, char **path[], usec_t *ts_usec[]);
 
 /* libudev-device.c */
 struct udev_device *udev_device_new(struct udev *udev);
+struct udev_device *udev_device_shallow_clone(struct udev_device *old_device);
 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 e5b2259..d6c9cfc 100644 (file)
@@ -809,11 +809,8 @@ void udev_event_execute_rules(struct udev_event *event,
                 if (major(udev_device_get_devnum(dev)) != 0)
                         udev_node_remove(dev);
         } else {
-                event->dev_db = udev_device_new(event->udev);
+                event->dev_db = udev_device_shallow_clone(dev);
                 if (event->dev_db != NULL) {
-                        udev_device_set_syspath(event->dev_db, udev_device_get_syspath(dev));
-                        udev_device_set_subsystem(event->dev_db, udev_device_get_subsystem(dev));
-                        udev_device_set_devnum(event->dev_db, udev_device_get_devnum(dev));
                         udev_device_read_db(event->dev_db, NULL);
                         udev_device_set_info_loaded(event->dev_db);