Author: imp
Date: Sun Apr  3 20:29:21 2016
New Revision: 297529
URL: https://svnweb.freebsd.org/changeset/base/297529

Log:
  Add a timestamp variable to the environment. This is when the event
  was read from the kernel by devd.

Modified:
  head/sbin/devd/devd.cc
  head/sbin/devd/devd.conf.5

Modified: head/sbin/devd/devd.cc
==============================================================================
--- head/sbin/devd/devd.cc      Sun Apr  3 20:29:14 2016        (r297528)
+++ head/sbin/devd/devd.cc      Sun Apr  3 20:29:21 2016        (r297529)
@@ -788,6 +788,8 @@ process_event(char *buffer)
 {
        char type;
        char *sp;
+       struct timeval tv;
+       char *timestr;
 
        sp = buffer + 1;
        devdlog(LOG_INFO, "Processing event '%s'\n", buffer);
@@ -797,7 +799,15 @@ process_event(char *buffer)
        cfg.set_variable("*", buffer - 1);
        // $_ is the entire line without the initial character
        cfg.set_variable("_", buffer);
-       // No match doesn't have a device, and the format is a little
+
+       // Save the time this happened (as approximated by when we got
+       // around to processing it).
+       gettimeofday(&tv, NULL);
+       asprintf(&timestr, "%jd.%06ld", (uintmax_t)tv.tv_sec, tv.tv_usec);
+       cfg.set_variable("timestamp", timestr);
+       free(timestr);
+
+       // Match doesn't have a device, and the format is a little
        // different, so handle it separately.
        switch (type) {
        case notify:

Modified: head/sbin/devd/devd.conf.5
==============================================================================
--- head/sbin/devd/devd.conf.5  Sun Apr  3 20:29:14 2016        (r297528)
+++ head/sbin/devd/devd.conf.5  Sun Apr  3 20:29:21 2016        (r297529)
@@ -245,6 +245,8 @@ Variables for other classes of events ar
 The entire message from the current event
 .It Li _
 The entire message from the current event, after the initial type character
+.It Li timestamp
+The time this event was processed, in seconds since 1970 dot fraction
 .It Li bus
 Device name of parent bus.
 .It Li cdev
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to