]> err.no Git - systemd/commitdiff
libudev: device - copy global properties, unset empty properties
authorKay Sievers <kay.sievers@vrfy.org>
Thu, 16 Oct 2008 11:53:16 +0000 (13:53 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Thu, 16 Oct 2008 11:53:16 +0000 (13:53 +0200)
udev/lib/libudev-device.c

index acab263785a95fe4892989a765818e17b869936b..daf2217765ee373efc0b326696f77d7b27cd07f8 100644 (file)
@@ -231,6 +231,7 @@ void udev_device_set_info_loaded(struct udev_device *device)
 struct udev_device *device_new(struct udev *udev)
 {
        struct udev_device *udev_device;
+       struct udev_list_entry *list_entry;
 
        if (udev == NULL)
                return NULL;
@@ -245,6 +246,11 @@ struct udev_device *device_new(struct udev *udev)
        udev_list_init(&udev_device->properties_list);
        udev_list_init(&udev_device->attr_list);
        udev_device->event_timeout = -1;
+       /* copy global properties */
+       udev_list_entry_foreach(list_entry, udev_get_properties_list_entry(udev))
+               udev_device_add_property(udev_device,
+                                        udev_list_entry_get_name(list_entry),
+                                        udev_list_entry_get_value(list_entry));
        info(udev_device->udev, "udev_device: %p created\n", udev_device);
        return udev_device;
 }
@@ -969,6 +975,15 @@ int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink
 struct udev_list_entry *udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value)
 {
        udev_device->envp_uptodate = 0;
+       if (value == NULL) {
+               struct udev_list_entry *list_entry;
+
+               list_entry = udev_device_get_properties_list_entry(udev_device);
+               list_entry = udev_list_entry_get_by_name(list_entry, key);
+               if (list_entry != NULL)
+                       udev_list_entry_remove(list_entry);
+               return NULL;
+       }
        return udev_list_entry_add(udev_device->udev, &udev_device->properties_list, key, value, 1, 0);
 }