chiark / gitweb /
udevd: do not wrongly delay events for devices with swapped names
[elogind.git] / libudev / libudev-device.c
index 478fdcb92d7f80231662b10ccfceef6f1a2c7900..e5f8cc3e46b765d2af84ebcfed0123c33db689d5 100644 (file)
@@ -67,6 +67,7 @@ struct udev_device {
        int devlink_priority;
        int refcount;
        dev_t devnum;
+       int ifindex;
        int watch_handle;
        int maj, min;
        bool parent_set;
@@ -187,6 +188,8 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device,
                udev_device_set_seqnum(udev_device, strtoull(&property[7], NULL, 10));
        } else if (strncmp(property, "TIMEOUT=", 8) == 0) {
                udev_device_set_timeout(udev_device, strtoull(&property[8], NULL, 10));
+       } else if (strncmp(property, "IFINDEX=", 8) == 0) {
+               udev_device_set_ifindex(udev_device, strtoull(&property[8], NULL, 10));
        } else {
                udev_device_add_property_from_string(udev_device, property);
        }
@@ -279,11 +282,13 @@ int udev_device_read_db(struct udev_device *udev_device)
                return 0;
        }
 
-       f = fopen(filename, "r");
+       f = fopen(filename, "re");
        if (f == NULL) {
                dbg(udev_device->udev, "error reading db file %s: %m\n", filename);
                return -1;
        }
+       udev_device->db_loaded = true;
+
        while (fgets(line, sizeof(line), f)) {
                ssize_t len;
                const char *val;
@@ -322,7 +327,6 @@ int udev_device_read_db(struct udev_device *udev_device)
        fclose(f);
 
        info(udev_device->udev, "device %p filled with db file data\n", udev_device);
-       udev_device->db_loaded = true;
        return 0;
 }
 
@@ -338,9 +342,10 @@ int udev_device_read_uevent_file(struct udev_device *udev_device)
                return 0;
 
        util_strscpyl(filename, sizeof(filename), udev_device->syspath, "/uevent", NULL);
-       f = fopen(filename, "r");
+       f = fopen(filename, "re");
        if (f == NULL)
                return -1;
+       udev_device->uevent_loaded = true;
 
        while (fgets(line, sizeof(line), f)) {
                char *pos;
@@ -356,6 +361,8 @@ int udev_device_read_uevent_file(struct udev_device *udev_device)
                        maj = strtoull(&line[6], NULL, 10);
                else if (strncmp(line, "MINOR=", 6) == 0)
                        min = strtoull(&line[6], NULL, 10);
+               else if (strncmp(line, "IFINDEX=", 8) == 0)
+                       udev_device_set_ifindex(udev_device, strtoull(&line[8], NULL, 10));
                else if (strncmp(line, "DEVNAME=", 8) == 0)
                        udev_device_set_knodename(udev_device, &line[8]);
 
@@ -364,7 +371,6 @@ int udev_device_read_uevent_file(struct udev_device *udev_device)
 
        udev_device->devnum = makedev(maj, min);
        fclose(f);
-       udev_device->uevent_loaded = true;
        return 0;
 }
 
@@ -1163,7 +1169,7 @@ const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const
                goto out;
 
        /* read attribute value */
-       fd = open(path, O_RDONLY);
+       fd = open(path, O_RDONLY|O_CLOEXEC);
        if (fd < 0) {
                dbg(udev_device->udev, "attribute '%s' can not be opened\n", path);
                goto out;
@@ -1286,8 +1292,21 @@ void udev_device_cleanup_tags_list(struct udev_device *udev_device)
        udev_list_cleanup_entries(udev_device->udev, &udev_device->tags_list);
 }
 
+/**
+ * udev_device_get_tags_list_entry:
+ * @udev_device: udev device
+ *
+ * Retrieve the list of tags attached to the udev device. The next
+ * list entry can be retrieved with udev_list_entry_next(),
+ * which returns #NULL if no more entries exist. The tag string
+ * can be retrieved from the list entry by udev_list_get_name().
+ *
+ * Returns: the first entry of the tag list
+ **/
 struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device)
 {
+       if (udev_device == NULL)
+               return NULL;
        return udev_list_get_entry(&udev_device->tags_list);
 }
 
@@ -1522,3 +1541,14 @@ int udev_device_set_watch_handle(struct udev_device *udev_device, int handle)
        udev_device->watch_handle = handle;
        return 0;
 }
+
+int udev_device_get_ifindex(struct udev_device *udev_device)
+{
+       return udev_device->ifindex;
+}
+
+int udev_device_set_ifindex(struct udev_device *udev_device, int ifindex)
+{
+       udev_device->ifindex = ifindex;
+       return 0;
+}