From 3b336ac34ffde831093cad2f4ae4ad42e9284dc5 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Sun, 3 Apr 2016 20:29:21 +0000 Subject: [PATCH] Add a timestamp variable to the environment. This is when the event was read from the kernel by devd. --- sbin/devd/devd.cc | 12 +++++++++++- sbin/devd/devd.conf.5 | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sbin/devd/devd.cc b/sbin/devd/devd.cc index 367783f8729..b2aea194973 100644 --- a/sbin/devd/devd.cc +++ b/sbin/devd/devd.cc @@ -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(×tr, "%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: diff --git a/sbin/devd/devd.conf.5 b/sbin/devd/devd.conf.5 index 21779ed61ae..83c4c767400 100644 --- a/sbin/devd/devd.conf.5 +++ b/sbin/devd/devd.conf.5 @@ -245,6 +245,8 @@ Variables for other classes of events are dependent on those events. 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