svn commit: r311839 - stable/11/usr.bin/kdump
John Baldwin
jhb at FreeBSD.org
Mon Jan 9 23:43:43 UTC 2017
Author: jhb
Date: Mon Jan 9 23:43:42 2017
New Revision: 311839
URL: https://svnweb.freebsd.org/changeset/base/311839
Log:
MFC 306565,306566: Use timercmp() and timersub() in kdump.
306565:
Use timercmp() and timersub() in kdump.
Previously, kdump used the kernel-only timervalsub() macro which required
defining _KERNEL when including <sys/time.h>. Now, kdump uses the existing
userland API. The timercmp() usage to check for a backwards timestamp is
also clearer and simpler than the previous code which checked the result of
the subtraction for a negative value.
While here, take advantage of the 3-arg timersub() to store the subtraction
results in a tempory timeval instead of overwriting the timestamp in the
ktrace record and then having to restore it.
306566:
Don't declare the 'temp' timeval as static.
Modified:
stable/11/usr.bin/kdump/kdump.c
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/usr.bin/kdump/kdump.c
==============================================================================
--- stable/11/usr.bin/kdump/kdump.c Mon Jan 9 23:42:02 2017 (r311838)
+++ stable/11/usr.bin/kdump/kdump.c Mon Jan 9 23:43:42 2017 (r311839)
@@ -45,9 +45,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/capsicum.h>
#include <sys/errno.h>
-#define _KERNEL
#include <sys/time.h>
-#undef _KERNEL
#include <sys/uio.h>
#include <sys/ktrace.h>
#include <sys/ioctl.h>
@@ -564,7 +562,8 @@ void
dumpheader(struct ktr_header *kth)
{
static char unknown[64];
- static struct timeval prevtime, prevtime_e, temp;
+ static struct timeval prevtime, prevtime_e;
+ struct timeval temp;
const char *type;
const char *sign;
@@ -637,27 +636,23 @@ dumpheader(struct ktr_header *kth)
if (timestamp & TIMESTAMP_ELAPSED) {
if (prevtime_e.tv_sec == 0)
prevtime_e = kth->ktr_time;
- timevalsub(&kth->ktr_time, &prevtime_e);
- printf("%jd.%06ld ", (intmax_t)kth->ktr_time.tv_sec,
- kth->ktr_time.tv_usec);
- timevaladd(&kth->ktr_time, &prevtime_e);
+ timersub(&kth->ktr_time, &prevtime_e, &temp);
+ printf("%jd.%06ld ", (intmax_t)temp.tv_sec,
+ temp.tv_usec);
}
if (timestamp & TIMESTAMP_RELATIVE) {
if (prevtime.tv_sec == 0)
prevtime = kth->ktr_time;
- temp = kth->ktr_time;
- timevalsub(&kth->ktr_time, &prevtime);
- if ((intmax_t)kth->ktr_time.tv_sec < 0) {
- kth->ktr_time = prevtime;
- prevtime = temp;
- timevalsub(&kth->ktr_time, &prevtime);
+ if (timercmp(&kth->ktr_time, &prevtime, <)) {
+ timersub(&prevtime, &kth->ktr_time, &temp);
sign = "-";
} else {
- prevtime = temp;
+ timersub(&kth->ktr_time, &prevtime, &temp);
sign = "";
}
- printf("%s%jd.%06ld ", sign, (intmax_t)kth->ktr_time.tv_sec,
- kth->ktr_time.tv_usec);
+ prevtime = kth->ktr_time;
+ printf("%s%jd.%06ld ", sign, (intmax_t)temp.tv_sec,
+ temp.tv_usec);
}
}
printf("%s ", type);
More information about the svn-src-stable-11
mailing list