summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflorian <florian@openbsd.org>2020-02-16 21:11:02 +0000
committerflorian <florian@openbsd.org>2020-02-16 21:11:02 +0000
commita12dcefb48e200107d0d2d0ced8c8d9c25cb6d86 (patch)
tree9fb057b930c99b994191b88919f80cc550e5796c
parentMove isc_time_formathttptimestamp to the only place it is used. (diff)
downloadwireguard-openbsd-a12dcefb48e200107d0d2d0ced8c8d9c25cb6d86.tar.xz
wireguard-openbsd-a12dcefb48e200107d0d2d0ced8c8d9c25cb6d86.zip
clock_gettime cannot fail if called correctly; unravel TIME_NOW
indirections. (I'm not convinced that we always want to read CLOCK_REALTIME, in fact we probably want to almost always read CLOCK_MONOTONIC.) OK millert
-rw-r--r--usr.bin/dig/dighost.c10
-rw-r--r--usr.bin/dig/host.c2
-rw-r--r--usr.bin/dig/lib/isc/include/isc/util.h7
-rw-r--r--usr.bin/dig/lib/isc/log.c8
-rw-r--r--usr.bin/dig/lib/isc/timer.c10
-rw-r--r--usr.bin/dig/lib/isc/unix/app.c2
-rw-r--r--usr.bin/dig/lib/isc/unix/include/isc/time.h18
-rw-r--r--usr.bin/dig/lib/isc/unix/time.c13
8 files changed, 19 insertions, 51 deletions
diff --git a/usr.bin/dig/dighost.c b/usr.bin/dig/dighost.c
index 4f79c254398..afc2c749059 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.9 2020/02/16 21:06:15 florian Exp $ */
+/* $Id: dighost.c,v 1.10 2020/02/16 21:11:02 florian Exp $ */
/*! \file
* \note
@@ -380,7 +380,7 @@ debug(const char *format, ...) {
if (debugging) {
fflush(stdout);
if (debugtiming) {
- TIME_NOW(&t);
+ clock_gettime(CLOCK_REALTIME, &t);
fprintf(stderr, "%lld.%06ld: ", t.tv_sec, t.tv_nsec /
1000);
}
@@ -2749,7 +2749,7 @@ send_udp(dig_query_t *query) {
sendbuf = clone_buffer(&query->sendbuf);
ISC_LIST_ENQUEUE(query->sendlist, sendbuf, link);
debug("sending a request");
- TIME_NOW(&query->time_sent);
+ clock_gettime(CLOCK_REALTIME, &query->time_sent);
INSIST(query->sock != NULL);
query->waiting_senddone = ISC_TRUE;
result = isc_socket_sendtov2(query->sock, &query->sendlist,
@@ -2965,7 +2965,7 @@ launch_next_query(dig_query_t *query, isc_boolean_t include_question) {
debug("recvcount=%d", recvcount);
if (!query->first_soa_rcvd) {
debug("sending a request in launch_next_query");
- TIME_NOW(&query->time_sent);
+ clock_gettime(CLOCK_REALTIME, &query->time_sent);
query->waiting_senddone = ISC_TRUE;
result = isc_socket_sendv(query->sock, &query->sendlist,
global_task, send_done, query);
@@ -3335,7 +3335,7 @@ recv_done(isc_task_t *task, isc_event_t *event) {
INSIST(recvcount >= 0);
query = event->ev_arg;
- TIME_NOW(&query->time_recv);
+ clock_gettime(CLOCK_REALTIME, &query->time_recv);
debug("lookup=%p, query=%p", query->lookup, query);
l = query->lookup;
diff --git a/usr.bin/dig/host.c b/usr.bin/dig/host.c
index dc66fbea3b3..fb3b6532d6f 100644
--- a/usr.bin/dig/host.c
+++ b/usr.bin/dig/host.c
@@ -149,7 +149,7 @@ received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query) {
if (!short_form) {
char fromtext[ISC_SOCKADDR_FORMATSIZE];
isc_sockaddr_format(from, fromtext, sizeof(fromtext));
- TIME_NOW(&now);
+ clock_gettime(CLOCK_REALTIME, &now);
diff = (int) isc_time_microdiff(&now, &query->time_sent);
printf("Received %u bytes from %s in %d ms\n",
bytes, fromtext, diff/1000);
diff --git a/usr.bin/dig/lib/isc/include/isc/util.h b/usr.bin/dig/lib/isc/include/isc/util.h
index 56390593db8..9a460785692 100644
--- a/usr.bin/dig/lib/isc/include/isc/util.h
+++ b/usr.bin/dig/lib/isc/include/isc/util.h
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: util.h,v 1.1 2020/02/07 09:58:54 florian Exp $ */
+/* $Id: util.h,v 1.2 2020/02/16 21:11:02 florian Exp $ */
#ifndef ISC_UTIL_H
#define ISC_UTIL_H 1
@@ -140,9 +140,4 @@
/*% Runtime Check */
#define RUNTIME_CHECK(cond) ISC_ERROR_RUNTIMECHECK(cond)
-/*%
- * Time
- */
-#define TIME_NOW(tp) RUNTIME_CHECK(isc_time_now((tp)) == ISC_R_SUCCESS)
-
#endif /* ISC_UTIL_H */
diff --git a/usr.bin/dig/lib/isc/log.c b/usr.bin/dig/lib/isc/log.c
index 0d47ea2bf22..76a01473640 100644
--- a/usr.bin/dig/lib/isc/log.c
+++ b/usr.bin/dig/lib/isc/log.c
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: log.c,v 1.12 2020/02/16 21:09:32 florian Exp $ */
+/* $Id: log.c,v 1.13 2020/02/16 21:11:02 florian Exp $ */
/*! \file
* \author Principal Authors: DCL */
@@ -945,7 +945,7 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
time_string[0] == '\0') {
struct timespec now;
- TIME_NOW(&now);
+ clock_gettime(CLOCK_REALTIME, &now);
strftime(time_string, sizeof(time_string),
"%d-%b-%Y %X", localtime(&now.tv_sec));
}
@@ -987,7 +987,7 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
* which fall within the duplicate_interval
* range.
*/
- TIME_NOW(&oldest);
+ clock_gettime(CLOCK_REALTIME, &oldest);
timespecsub(&oldest, &interval, &oldest);
message = ISC_LIST_HEAD(lctx->messages);
@@ -1050,7 +1050,7 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
strlcpy(message->text, lctx->buffer,
size);
- TIME_NOW(&message->time);
+ clock_gettime(CLOCK_REALTIME, &message->time);
ISC_LINK_INIT(message, link);
ISC_LIST_APPEND(lctx->messages,
diff --git a/usr.bin/dig/lib/isc/timer.c b/usr.bin/dig/lib/isc/timer.c
index 8c4bf3a04d4..20e472b99f9 100644
--- a/usr.bin/dig/lib/isc/timer.c
+++ b/usr.bin/dig/lib/isc/timer.c
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: timer.c,v 1.17 2020/02/16 21:08:59 florian Exp $ */
+/* $Id: timer.c,v 1.18 2020/02/16 21:11:02 florian Exp $ */
/*! \file */
@@ -218,7 +218,7 @@ isc__timer_create(isc_timermgr_t *manager0, const struct timespec *interval,
/*
* Get current time.
*/
- TIME_NOW(&now);
+ clock_gettime(CLOCK_REALTIME, &now);
timer = malloc(sizeof(*timer));
if (timer == NULL)
@@ -291,7 +291,7 @@ isc__timer_reset(isc_timer_t *timer0, const struct timespec *interval,
/*
* Get current time.
*/
- TIME_NOW(&now);
+ clock_gettime(CLOCK_REALTIME, &now);
if (purge)
(void)isc_task_purgerange(timer->task,
@@ -322,7 +322,7 @@ isc__timer_touch(isc_timer_t *timer0) {
REQUIRE(VALID_TIMER(timer));
- TIME_NOW(&now);
+ clock_gettime(CLOCK_REALTIME, &now);
timespecadd(&now, &timer->interval, &timer->idle);
}
@@ -565,7 +565,7 @@ isc__timermgr_dispatch(isc_timermgr_t *manager0) {
manager = timermgr;
if (manager == NULL)
return;
- TIME_NOW(&now);
+ clock_gettime(CLOCK_REALTIME, &now);
dispatch(manager, &now);
}
diff --git a/usr.bin/dig/lib/isc/unix/app.c b/usr.bin/dig/lib/isc/unix/app.c
index eebe9a39936..6c6d5daf236 100644
--- a/usr.bin/dig/lib/isc/unix/app.c
+++ b/usr.bin/dig/lib/isc/unix/app.c
@@ -331,7 +331,7 @@ evloop(isc__appctx_t *ctx) {
else {
uint64_t us;
- TIME_NOW(&now);
+ clock_gettime(CLOCK_REALTIME, &now);
us = isc_time_microdiff(&when, &now);
if (us == 0)
call_timer_dispatch = ISC_TRUE;
diff --git a/usr.bin/dig/lib/isc/unix/include/isc/time.h b/usr.bin/dig/lib/isc/unix/include/isc/time.h
index 9215c8cc972..e225b7292c4 100644
--- a/usr.bin/dig/lib/isc/unix/include/isc/time.h
+++ b/usr.bin/dig/lib/isc/unix/include/isc/time.h
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: time.h,v 1.13 2020/02/16 21:10:07 florian Exp $ */
+/* $Id: time.h,v 1.14 2020/02/16 21:11:02 florian Exp $ */
#ifndef ISC_TIME_H
#define ISC_TIME_H 1
@@ -30,22 +30,6 @@
*** Absolute Times
***/
-isc_result_t
-isc_time_now(struct timespec *t);
-/*%<
- * Set 't' to the current absolute time.
- *
- * Requires:
- *
- *\li 't' is a valid pointer.
- *
- * Returns:
- *
- *\li Success
- *\li Unexpected error
- * Getting the time from the system failed.
- */
-
uint64_t
isc_time_microdiff(const struct timespec *t1, const struct timespec *t2);
/*%<
diff --git a/usr.bin/dig/lib/isc/unix/time.c b/usr.bin/dig/lib/isc/unix/time.c
index 34b3115a9dc..ed4e821cd73 100644
--- a/usr.bin/dig/lib/isc/unix/time.c
+++ b/usr.bin/dig/lib/isc/unix/time.c
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: time.c,v 1.16 2020/02/16 21:10:07 florian Exp $ */
+/* $Id: time.c,v 1.17 2020/02/16 21:11:02 florian Exp $ */
/*! \file */
@@ -43,17 +43,6 @@
*** Absolute Times
***/
-isc_result_t
-isc_time_now(struct timespec *t) {
- REQUIRE(t != NULL);
-
- if (clock_gettime(CLOCK_REALTIME, t) == -1) {
- UNEXPECTED_ERROR(__FILE__, __LINE__, "%s", strerror(errno));
- return (ISC_R_UNEXPECTED);
- }
- return (ISC_R_SUCCESS);
-}
-
uint64_t
isc_time_microdiff(const struct timespec *t1, const struct timespec *t2) {
struct timespec res;