From 3447a66db8ac9f43c11d14926fd5dc90fe22b4fa Mon Sep 17 00:00:00 2001 From: Neel Natu Date: Fri, 14 Mar 2014 22:07:08 +0000 Subject: [PATCH] Don't dump entries that were modified during the time the KTR buffer was being copied to userspace. Failing to do this would result in entries at the bottom of the ktrdump output to be more recent than entries at the top. With this change the timestamps are monotonically decreasing going from the top to the bottom of the ktrdump output. --- usr.bin/ktrdump/ktrdump.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/usr.bin/ktrdump/ktrdump.c b/usr.bin/ktrdump/ktrdump.c index d55aa72dc771..11e78e92bf8b 100644 --- a/usr.bin/ktrdump/ktrdump.c +++ b/usr.bin/ktrdump/ktrdump.c @@ -93,7 +93,7 @@ main(int ac, char **av) char *p; int version; int entries; - int index; + int index, index2; int parm; int in; int c; @@ -182,7 +182,8 @@ main(int ac, char **av) if (kvm_read(kd, nl[2].n_value, &index, sizeof(index)) == -1 || kvm_read(kd, nl[3].n_value, &bufptr, sizeof(bufptr)) == -1 || - kvm_read(kd, bufptr, buf, sizeof(*buf) * entries) == -1) + kvm_read(kd, bufptr, buf, sizeof(*buf) * entries) == -1 || + kvm_read(kd, nl[2].n_value, &index2, sizeof(index2)) == -1) errx(1, "%s", kvm_geterr(kd)); } @@ -289,7 +290,14 @@ next: if ((c = *p++) == '\0') parms[4], parms[5]); fprintf(out, "\n"); if (!iflag) { - if (i == index) + /* + * 'index' and 'index2' are the values of 'ktr_idx' + * before and after the KTR buffer was copied into + * 'buf'. Since the KTR entries between 'index' and + * 'index2' were in flux while the KTR buffer was + * being copied to userspace we don't dump them. + */ + if (i == index2) break; if (--i < 0) i = entries - 1;