summaryrefslogtreecommitdiff
path: root/libudev/libudev-device.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2010-12-15 08:57:46 +0100
committerKay Sievers <kay.sievers@vrfy.org>2010-12-15 08:58:46 +0100
commit9c6a11b1c6c68dabfd28b72d361da0e1930c7321 (patch)
tree581eed5eeb14013c6ec4e9669ed14d6ed69d107e /libudev/libudev-device.c
parent93a724d3f8afc4b6fe5c7c9642c79df724324ed3 (diff)
libudev: record and export "age" of device record
Diffstat (limited to 'libudev/libudev-device.c')
-rw-r--r--libudev/libudev-device.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/libudev/libudev-device.c b/libudev/libudev-device.c
index 66f806316f..16bee19dff 100644
--- a/libudev/libudev-device.c
+++ b/libudev/libudev-device.c
@@ -63,6 +63,7 @@ struct udev_device {
struct udev_list_node sysattr_list;
struct udev_list_node tags_list;
unsigned long long int seqnum;
+ unsigned long long int usec_initialized;
int event_timeout;
int timeout;
int devlink_priority;
@@ -284,6 +285,9 @@ int udev_device_read_db(struct udev_device *udev_device)
case 'W':
udev_device_set_watch_handle(udev_device, atoi(val));
break;
+ case 'I':
+ udev_device_set_usec_initialized(udev_device, strtoull(val, NULL, 10));
+ break;
}
}
fclose(f);
@@ -1095,6 +1099,44 @@ unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device)
}
/**
+ * udev_device_get_usec_since_initialized:
+ * @udev_device: udev device
+ *
+ * Return the number of microseconds passed since udev set up the
+ * device for the first time.
+ *
+ * This is only implemented for devices with need to store properties
+ * in the udev database. All other devices return 0 here.
+ *
+ * Returns: the number of microseconds since the device was first seen.
+ **/
+unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device)
+{
+ unsigned long long now;
+
+ if (udev_device == NULL)
+ return 0;
+ if (!udev_device->info_loaded)
+ udev_device_read_db(udev_device);
+ if (udev_device->usec_initialized == 0)
+ return 0;
+ now = usec_monotonic();
+ if (now == 0)
+ return 0;
+ return now - udev_device->usec_initialized;
+}
+
+unsigned long long udev_device_get_usec_initialized(struct udev_device *udev_device)
+{
+ return udev_device->usec_initialized;
+}
+
+void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized)
+{
+ udev_device->usec_initialized = usec_initialized;
+}
+
+/**
* udev_device_get_sysattr_value:
* @udev_device: udev device
* @sysattr: attribute name
@@ -1318,7 +1360,7 @@ const char *udev_device_get_id_filename(struct udev_device *udev_device)
* device node permissions and context, or has renamed a network
* device.
*
- * For now, this is only implemented for devices with a device node
+ * This is only implemented for devices with a device node
* or network interfaces. All other devices return 1 here.
*
* Returns: 1 if the device is set up. 0 otherwise.