Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Apr 2016 20:29:21 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r297529 - head/sbin/devd
Message-ID:  <201604032029.u33KTL8M062590@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201604032029.u33KTL8M062590>