Add a timestamp variable to the environment. This is when the event

was read from the kernel by devd.
This commit is contained in:
Warner Losh 2016-04-03 20:29:21 +00:00
parent 535595db8d
commit 3b336ac34f
2 changed files with 13 additions and 1 deletions

View File

@ -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:

View File

@ -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