chiark / gitweb /
udev: make set_usec_initialized() internal to libudev
authorTom Gundersen <teg@jklm.no>
Fri, 13 Mar 2015 17:43:00 +0000 (18:43 +0100)
committerTom Gundersen <teg@jklm.no>
Fri, 13 Mar 2015 17:47:07 +0000 (18:47 +0100)
Instead introduce ensure_usec_initialized(), which copies the timestamp if possible otherwise
sets it to now(CLOCK_MONOTONIC).

src/libudev/libudev-device.c
src/libudev/libudev-private.h
src/udev/udev-event.c
src/udev/udevd.c

index c0a061a..b518a2f 100644 (file)
@@ -445,6 +445,23 @@ static int udev_device_set_syspath(struct udev_device *udev_device, const char *
         return 0;
 }
 
+static void udev_device_set_usec_initialized(struct udev_device *udev_device, usec_t usec_initialized)
+{
+        char num[DECIMAL_STR_MAX(usec_t)];
+
+        udev_device->usec_initialized = usec_initialized;
+        snprintf(num, sizeof(num), USEC_FMT, usec_initialized);
+        udev_device_add_property_internal(udev_device, "USEC_INITIALIZED", num);
+}
+
+void udev_device_ensure_usec_initialized(struct udev_device *udev_device, struct udev_device *old_device)
+{
+        if (old_device && old_device->usec_initialized != 0)
+                udev_device_set_usec_initialized(udev_device, old_device->usec_initialized);
+        else
+                udev_device_set_usec_initialized(udev_device, now(CLOCK_MONOTONIC));
+}
+
 /*
  * parse property string, and if needed, update internal values accordingly
  *
@@ -1418,15 +1435,6 @@ usec_t 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, usec_t usec_initialized)
-{
-        char num[32];
-
-        udev_device->usec_initialized = usec_initialized;
-        snprintf(num, sizeof(num), USEC_FMT, usec_initialized);
-        udev_device_add_property_internal(udev_device, "USEC_INITIALIZED", num);
-}
-
 /**
  * udev_device_get_sysattr_value:
  * @udev_device: udev device
index a34c0f7..403ae59 100644 (file)
@@ -60,7 +60,7 @@ int udev_device_add_tag(struct udev_device *udev_device, const char *tag);
 void udev_device_remove_tag(struct udev_device *udev_device, const char *tag);
 void udev_device_cleanup_tags_list(struct udev_device *udev_device);
 usec_t udev_device_get_usec_initialized(struct udev_device *udev_device);
-void udev_device_set_usec_initialized(struct udev_device *udev_device, usec_t usec_initialized);
+void udev_device_ensure_usec_initialized(struct udev_device *udev_device, struct udev_device *old_device);
 int udev_device_get_devlink_priority(struct udev_device *udev_device);
 int udev_device_set_devlink_priority(struct udev_device *udev_device, int prio);
 int udev_device_get_watch_handle(struct udev_device *udev_device);
index f62c1ea..3a165b0 100644 (file)
@@ -873,10 +873,7 @@ void udev_event_execute_rules(struct udev_event *event,
                 }
 
                 /* preserve old, or get new initialization timestamp */
-                if (event->dev_db != NULL && udev_device_get_usec_initialized(event->dev_db) > 0)
-                        udev_device_set_usec_initialized(event->dev, udev_device_get_usec_initialized(event->dev_db));
-                else if (udev_device_get_usec_initialized(event->dev) == 0)
-                        udev_device_set_usec_initialized(event->dev, now(CLOCK_MONOTONIC));
+                udev_device_ensure_usec_initialized(event->dev, event->dev_db);
 
                 /* (re)write database file */
                 udev_device_update_db(dev);
index f7d6191..8eaf2cd 100644 (file)
@@ -1474,8 +1474,8 @@ int main(int argc, char *argv[]) {
                         struct udev_device *dev;
 
                         dev = udev_monitor_receive_device(monitor);
-                        if (dev != NULL) {
-                                udev_device_set_usec_initialized(dev, now(CLOCK_MONOTONIC));
+                        if (dev) {
+                                udev_device_ensure_usec_initialized(dev, NULL);
                                 if (event_queue_insert(dev) < 0)
                                         udev_device_unref(dev);
                         }