summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2020-09-14 08:37:10 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2020-09-14 08:37:10 +0000
commit39e22bb2ce4e6987cefa3f3dcc8c75ba31f46b16 (patch)
treedd13766fde03284f4b8071ea9767102196c3948e /usr.bin
parent204db39cdcb1bebe870ea4f628e76f88eb186734 (diff)
Rewrite isc_time_microdiff() as uelapsed() and put it directly
into dig sources, lets us get rid of unix/time.{c,h} OK deraadt
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/dig/dig.c46
-rw-r--r--usr.bin/dig/dig.h3
-rw-r--r--usr.bin/dig/dighost.c18
-rw-r--r--usr.bin/dig/host.c7
-rw-r--r--usr.bin/dig/lib/isc/unix/Makefile.inc4
-rw-r--r--usr.bin/dig/lib/isc/unix/app.c14
-rw-r--r--usr.bin/dig/lib/isc/unix/include/isc/time.h43
-rw-r--r--usr.bin/dig/lib/isc/unix/time.c41
8 files changed, 54 insertions, 122 deletions
diff --git a/usr.bin/dig/dig.c b/usr.bin/dig/dig.c
index a9df70f46ea..d849e4ad27b 100644
--- a/usr.bin/dig/dig.c
+++ b/usr.bin/dig/dig.c
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: dig.c,v 1.13 2020/09/13 09:33:39 florian Exp $ */
+/* $Id: dig.c,v 1.14 2020/09/14 08:37:08 florian Exp $ */
/*! \file */
#include <sys/cdefs.h>
@@ -28,7 +28,6 @@
#include <string.h>
#include <isc/util.h>
-#include <isc/time.h>
#include <dns/fixedname.h>
#include <dns/masterdump.h>
@@ -171,7 +170,6 @@ help(void) {
*/
static void
received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query) {
- uint64_t diff;
time_t tnow;
struct tm tmnow;
char time_str[100];
@@ -180,11 +178,13 @@ received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query) {
isc_sockaddr_format(from, fromtext, sizeof(fromtext));
if (query->lookup->stats && !short_form) {
- diff = isc_time_microdiff(&query->time_recv, &query->time_sent);
if (use_usec)
- printf(";; Query time: %ld usec\n", (long) diff);
+ printf(";; Query time: %lld usec\n",
+ uelapsed(&query->time_recv, &query->time_sent));
else
- printf(";; Query time: %ld msec\n", (long) diff / 1000);
+ printf(";; Query time: %lld msec\n",
+ uelapsed(&query->time_recv, &query->time_sent) /
+ 1000);
printf(";; SERVER: %s(%s)\n", fromtext, query->servname);
time(&tnow);
tmnow = *localtime(&tnow);
@@ -210,21 +210,23 @@ received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query) {
}
puts("");
} else if (query->lookup->identify && !short_form) {
- diff = isc_time_microdiff(&query->time_recv, &query->time_sent);
if (use_usec)
printf(";; Received %llu bytes "
- "from %s(%s) in %ld us\n\n",
- query->lookup->doing_xfr
- ? query->byte_count
- : (uint64_t)bytes,
- fromtext, query->userarg, (long) diff);
+ "from %s(%s) in %lld us\n\n",
+ query->lookup->doing_xfr
+ ? query->byte_count
+ : (uint64_t)bytes,
+ fromtext, query->userarg,
+ uelapsed(&query->time_recv, &query->time_sent));
else
printf(";; Received %llu bytes "
- "from %s(%s) in %ld ms\n\n",
- query->lookup->doing_xfr
- ? query->byte_count
- : (uint64_t)bytes,
- fromtext, query->userarg, (long) diff / 1000);
+ "from %s(%s) in %lld ms\n\n",
+ query->lookup->doing_xfr
+ ? query->byte_count
+ : (uint64_t)bytes,
+ fromtext, query->userarg,
+ uelapsed(&query->time_recv, &query->time_sent) /
+ 1000);
}
}
@@ -245,7 +247,6 @@ trying(char *frm, dig_lookup_t *lookup) {
static isc_result_t
say_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
isc_result_t result;
- uint64_t diff;
char store[sizeof(" in 18446744073709551616 us.")];
unsigned int styleflags = 0;
@@ -267,14 +268,15 @@ say_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
return (result);
check_result(result, "dns_rdata_totext");
if (query->lookup->identify) {
-
- diff = isc_time_microdiff(&query->time_recv, &query->time_sent);
ADD_STRING(buf, " from server ");
ADD_STRING(buf, query->servname);
if (use_usec)
- snprintf(store, sizeof(store), " in %llu us.", diff);
+ snprintf(store, sizeof(store), " in %lld us.",
+ uelapsed(&query->time_recv, &query->time_sent));
else
- snprintf(store, sizeof(store), " in %llu ms.", diff / 1000);
+ snprintf(store, sizeof(store), " in %lld ms.",
+ uelapsed(&query->time_recv, &query->time_sent) /
+ 1000);
ADD_STRING(buf, store);
}
ADD_STRING(buf, "\n");
diff --git a/usr.bin/dig/dig.h b/usr.bin/dig/dig.h
index 6e19df3853f..34a85fb27f3 100644
--- a/usr.bin/dig/dig.h
+++ b/usr.bin/dig/dig.h
@@ -337,6 +337,9 @@ set_search_domain(char *domain);
char *
next_token(char **stringp, const char *delim);
+int64_t
+uelapsed(const struct timespec *t1, const struct timespec *t2);
+
/*
* Routines to be defined in dig.c, host.c, and nslookup.c. and
* then assigned to the appropriate function pointer
diff --git a/usr.bin/dig/dighost.c b/usr.bin/dig/dighost.c
index 4bffe54aebd..5ee7a61403d 100644
--- a/usr.bin/dig/dighost.c
+++ b/usr.bin/dig/dighost.c
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: dighost.c,v 1.26 2020/09/13 09:33:39 florian Exp $ */
+/* $Id: dighost.c,v 1.27 2020/09/14 08:37:08 florian Exp $ */
/*! \file
* \note
@@ -27,6 +27,7 @@
*/
#include <sys/socket.h>
+#include <sys/time.h>
#include <limits.h>
#include <locale.h>
#include <netdb.h>
@@ -3902,3 +3903,18 @@ destroy_libs(void) {
}
+int64_t
+uelapsed(const struct timespec *t1, const struct timespec *t2)
+{
+ struct timespec diff, zero = {0, 0};
+ struct timeval tv;
+
+ timespecsub(t1, t2, &diff);
+
+ if (timespeccmp(&diff, &zero, <=))
+ return 0;
+
+ TIMESPEC_TO_TIMEVAL(&tv, &diff);
+
+ return (tv.tv_sec * 1000000 + tv.tv_usec);
+}
diff --git a/usr.bin/dig/host.c b/usr.bin/dig/host.c
index e4c0e197f27..374ed4607a3 100644
--- a/usr.bin/dig/host.c
+++ b/usr.bin/dig/host.c
@@ -28,7 +28,6 @@
#include <isc/app.h>
#include <isc/util.h>
-#include <isc/time.h>
#include <dns/fixedname.h>
#include <dns/message.h>
@@ -146,15 +145,13 @@ host_shutdown(void) {
static void
received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query) {
struct timespec now;
- int diff;
if (!short_form) {
char fromtext[ISC_SOCKADDR_FORMATSIZE];
isc_sockaddr_format(from, fromtext, sizeof(fromtext));
clock_gettime(CLOCK_MONOTONIC, &now);
- diff = (int) isc_time_microdiff(&now, &query->time_sent);
- printf("Received %u bytes from %s in %d ms\n",
- bytes, fromtext, diff/1000);
+ printf("Received %u bytes from %s in %lld ms\n",
+ bytes, fromtext, uelapsed(&now, &query->time_sent)/1000);
}
}
diff --git a/usr.bin/dig/lib/isc/unix/Makefile.inc b/usr.bin/dig/lib/isc/unix/Makefile.inc
index 4ef52df973a..69c3c7f18bc 100644
--- a/usr.bin/dig/lib/isc/unix/Makefile.inc
+++ b/usr.bin/dig/lib/isc/unix/Makefile.inc
@@ -1,5 +1,5 @@
-# $OpenBSD: Makefile.inc,v 1.5 2020/02/17 19:45:00 jung Exp $
+# $OpenBSD: Makefile.inc,v 1.6 2020/09/14 08:37:09 florian Exp $
.PATH: ${.CURDIR}/lib/isc/unix
-SRCS+= app.c errno2result.c socket.c net.c time.c
+SRCS+= app.c errno2result.c socket.c net.c
diff --git a/usr.bin/dig/lib/isc/unix/app.c b/usr.bin/dig/lib/isc/unix/app.c
index f6705f3bb9c..62535523261 100644
--- a/usr.bin/dig/lib/isc/unix/app.c
+++ b/usr.bin/dig/lib/isc/unix/app.c
@@ -28,7 +28,6 @@
#include <string.h>
#include <isc/task.h>
-#include <isc/time.h>
#include <isc/util.h>
/*%
@@ -145,7 +144,7 @@ evloop(isc_appctx_t *ctx) {
while (!ctx->want_shutdown) {
int n;
- struct timespec when, now;
+ struct timespec when, now, diff, zero ={0, 0};
struct timeval tv, *tvp;
isc_socketwait_t *swait;
isc_boolean_t readytasks;
@@ -162,14 +161,13 @@ evloop(isc_appctx_t *ctx) {
if (result != ISC_R_SUCCESS)
tvp = NULL;
else {
- uint64_t us;
-
clock_gettime(CLOCK_MONOTONIC, &now);
- us = isc_time_microdiff(&when, &now);
- if (us == 0)
+ timespecsub(&when, &now, &diff);
+ if (timespeccmp(&diff, &zero, <=)) {
call_timer_dispatch = ISC_TRUE;
- tv.tv_sec = us / 1000000;
- tv.tv_usec = us % 1000000;
+ memset(&tv, 0, sizeof(tv));
+ } else
+ TIMESPEC_TO_TIMEVAL(&tv, &diff);
tvp = &tv;
}
}
diff --git a/usr.bin/dig/lib/isc/unix/include/isc/time.h b/usr.bin/dig/lib/isc/unix/include/isc/time.h
deleted file mode 100644
index 5d294edfe60..00000000000
--- a/usr.bin/dig/lib/isc/unix/include/isc/time.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-/* $Id: time.h,v 1.15 2020/02/16 21:11:31 florian Exp $ */
-
-#ifndef ISC_TIME_H
-#define ISC_TIME_H 1
-
-/*! \file */
-
-#include <sys/time.h>
-
-#include <inttypes.h>
-#include <time.h>
-
-uint64_t
-isc_time_microdiff(const struct timespec *t1, const struct timespec *t2);
-/*%<
- * Find the difference in microseconds between time t1 and time t2.
- * t2 is the subtrahend of t1; ie, difference = t1 - t2.
- *
- * Requires:
- *
- *\li 't1' and 't2' are valid pointers.
- *
- * Returns:
- *\li The difference of t1 - t2, or 0 if t1 <= t2.
- */
-
-#endif /* ISC_TIME_H */
diff --git a/usr.bin/dig/lib/isc/unix/time.c b/usr.bin/dig/lib/isc/unix/time.c
deleted file mode 100644
index d073515bfbd..00000000000
--- a/usr.bin/dig/lib/isc/unix/time.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-/* $Id: time.c,v 1.18 2020/02/16 21:11:31 florian Exp $ */
-
-/*! \file */
-
-#include <sys/time.h>
-#include <time.h>
-
-#include <isc/time.h>
-#include <isc/util.h>
-
-#define NS_PER_S 1000000000 /*%< Nanoseconds per second. */
-#define NS_PER_US 1000 /*%< Nanoseconds per microsecond. */
-
-uint64_t
-isc_time_microdiff(const struct timespec *t1, const struct timespec *t2) {
- struct timespec res;
-
- REQUIRE(t1 != NULL && t2 != NULL);
-
- timespecsub(t1, t2, &res);
- if (res.tv_sec < 0)
- return 0;
-
- return ((res.tv_sec * NS_PER_S + res.tv_nsec) / NS_PER_US);
-}