chiark / gitweb /
udevd: remove TIMEOUT= handling
[elogind.git] / libudev / libudev-device.c
index 76354dc7a7b7b178feb0575cc4f05202e56b1cb4..28df7a2a11e7c110d75d4c6bffc6ec66e365b8a3 100644 (file)
@@ -69,7 +69,6 @@ struct udev_device {
        struct udev_list tags_list;
        unsigned long long int seqnum;
        unsigned long long int usec_initialized;
-       int timeout;
        int devlink_priority;
        int refcount;
        dev_t devnum;
@@ -92,7 +91,7 @@ struct udev_device {
 };
 
 /**
- * udev_device_get_devnum:
+ * udev_device_get_seqnum:
  * @udev_device: udev device
  *
  * This is only valid if the device was received through a monitor. Devices read from
@@ -162,21 +161,6 @@ static int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum)
        return 0;
 }
 
-int udev_device_get_timeout(struct udev_device *udev_device)
-{
-       return udev_device->timeout;
-}
-
-static int udev_device_set_timeout(struct udev_device *udev_device, int timeout)
-{
-       char num[32];
-
-       udev_device->timeout = timeout;
-       snprintf(num, sizeof(num), "%u", timeout);
-       udev_device_add_property(udev_device, "TIMEOUT", num);
-       return 0;
-}
-
 const char *udev_device_get_knodename(struct udev_device *udev_device)
 {
        return udev_device->knodename;
@@ -229,7 +213,7 @@ UDEV_EXPORT const char *udev_device_get_driver(struct udev_device *udev_device)
                return NULL;
        if (!udev_device->driver_set) {
                udev_device->driver_set = true;
-               if (util_get_sys_driver(udev_device->udev, udev_device->syspath, driver, sizeof(driver)) > 0)
+               if (util_get_sys_core_link_value(udev_device->udev, "driver", udev_device->syspath, driver, sizeof(driver)) > 0)
                        udev_device->driver = strdup(driver);
        }
        return udev_device->driver;
@@ -305,7 +289,7 @@ UDEV_EXPORT const char *udev_device_get_subsystem(struct udev_device *udev_devic
        if (!udev_device->subsystem_set) {
                udev_device->subsystem_set = true;
                /* read "subsystem" link */
-               if (util_get_sys_subsystem(udev_device->udev, udev_device->syspath, subsystem, sizeof(subsystem)) > 0) {
+               if (util_get_sys_core_link_value(udev_device->udev, "subsystem", udev_device->syspath, subsystem, sizeof(subsystem)) > 0) {
                        udev_device_set_subsystem(udev_device, subsystem);
                        return udev_device->subsystem;
                }
@@ -437,6 +421,8 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device,
                                udev_device_add_tag(udev_device, tag);
                        }
                }
+       } else if (strncmp(property, "USEC_INITIALIZED=", 19) == 0) {
+               udev_device_set_usec_initialized(udev_device, strtoull(&property[19], NULL, 10));
        } else if (strncmp(property, "DRIVER=", 7) == 0) {
                udev_device_set_driver(udev_device, &property[7]);
        } else if (strncmp(property, "ACTION=", 7) == 0) {
@@ -449,8 +435,6 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device,
                udev_device_set_devpath_old(udev_device, &property[12]);
        } else if (strncmp(property, "SEQNUM=", 7) == 0) {
                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 if (strncmp(property, "DEVMODE=", 8) == 0) {
@@ -633,7 +617,6 @@ struct udev_device *udev_device_new(struct udev *udev)
        udev_list_init(udev, &udev_device->sysattr_value_list, true);
        udev_list_init(udev, &udev_device->sysattr_list, false);
        udev_list_init(udev, &udev_device->tags_list, true);
-       udev_device->timeout = -1;
        udev_device->watch_handle = -1;
        /* copy global properties */
        udev_list_entry_foreach(list_entry, udev_get_properties_list_entry(udev))
@@ -1322,7 +1305,11 @@ unsigned long long udev_device_get_usec_initialized(struct udev_device *udev_dev
 
 void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized)
 {
+       char num[32];
+
        udev_device->usec_initialized = usec_initialized;
+       snprintf(num, sizeof(num), "%llu", usec_initialized);
+       udev_device_add_property(udev_device, "USEC_INITIALIZED", num);
 }
 
 /**
@@ -1367,27 +1354,32 @@ UDEV_EXPORT const char *udev_device_get_sysattr_value(struct udev_device *udev_d
        }
 
        if (S_ISLNK(statbuf.st_mode)) {
-               char target[UTIL_NAME_SIZE];
-               int len;
-               char *pos;
-
-               /* some core links return the last element of the target path */
-               if (strcmp(sysattr, "driver") != 0 &&
-                   strcmp(sysattr, "subsystem") != 0 &&
-                   strcmp(sysattr, "module") != 0)
-                       goto out;
+               struct udev_device *dev;
 
-               len = readlink(path, target, sizeof(target));
-               if (len <= 0 || len == sizeof(target))
+               /*
+                * Some core links return only the last element of the target path,
+                * these are just values, the paths should not be exposed.
+                */
+               if (strcmp(sysattr, "driver") == 0 ||
+                   strcmp(sysattr, "subsystem") == 0 ||
+                   strcmp(sysattr, "module") == 0) {
+                       if (util_get_sys_core_link_value(udev_device->udev, sysattr,
+                                                        udev_device->syspath, value, sizeof(value)) < 0)
+                               return NULL;
+                       dbg(udev_device->udev, "cache '%s' with link value '%s'\n", sysattr, value);
+                       list_entry = udev_list_entry_add(&udev_device->sysattr_value_list, sysattr, value);
+                       val = udev_list_entry_get_value(list_entry);
                        goto out;
-               target[len] = '\0';
+               }
 
-               pos = strrchr(target, '/');
-               if (pos != NULL) {
-                       pos = &pos[1];
-                       dbg(udev_device->udev, "cache '%s' with link value '%s'\n", sysattr, pos);
-                       list_entry = udev_list_entry_add(&udev_device->sysattr_value_list, sysattr, pos);
+               /* resolve link to a device and return its syspath */
+               util_strscpyl(path, sizeof(path), udev_device->syspath, "/", sysattr, NULL);
+               dev = udev_device_new_from_syspath(udev_device->udev, path);
+               if (dev != NULL) {
+                       list_entry = udev_list_entry_add(&udev_device->sysattr_value_list, sysattr,
+                                                        udev_device_get_syspath(dev));
                        val = udev_list_entry_get_value(list_entry);
+                       udev_device_unref(dev);
                }
 
                goto out;