summaryrefslogtreecommitdiff
path: root/mbone/dbeacon/patches/patch-dbeacon__posix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mbone/dbeacon/patches/patch-dbeacon__posix.cpp')
-rw-r--r--mbone/dbeacon/patches/patch-dbeacon__posix.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/mbone/dbeacon/patches/patch-dbeacon__posix.cpp b/mbone/dbeacon/patches/patch-dbeacon__posix.cpp
index 85aeecd4080..3376d96d320 100644
--- a/mbone/dbeacon/patches/patch-dbeacon__posix.cpp
+++ b/mbone/dbeacon/patches/patch-dbeacon__posix.cpp
@@ -1,7 +1,12 @@
-$NetBSD: patch-dbeacon__posix.cpp,v 1.1 2014/12/09 10:45:51 he Exp $
+$NetBSD: patch-dbeacon__posix.cpp,v 1.2 2015/01/13 20:25:13 he Exp $
-Retry if times() returns with an error.
-It has been known to return ((uint32_t)-1).
+Replace use of times() with gettimeofday(), since all we use it
+for is to get a millisecond timestamp, and with a 32-bit unsigned
+clock_t and 100Hz tick, times() wraps around every 500 days or so,
+and the code then falls into an assert() in dbeacon.cpp.
+
+Still retry a few times if gettimeofday() for some reason should
+decide to fail.
--- dbeacon_posix.cpp.orig 2007-06-09 11:35:57.000000000 +0000
+++ dbeacon_posix.cpp
@@ -13,26 +18,31 @@ It has been known to return ((uint32_t)-1).
#include <sys/uio.h>
#include <sys/times.h>
-@@ -516,10 +517,19 @@ void address::set(const sockaddr *sa) {
+@@ -515,11 +516,24 @@ void address::set(const sockaddr *sa) {
+ }
uint64_t get_timestamp() {
- struct tms tmp;
-+ clock_t clk;
+- struct tms tmp;
++ struct timeval tv;
++ uint64_t timestamp;
+ int n = 0;
- uint64_t v = times(&tmp);
--
-- return (v * 1000) / sysconf(_SC_CLK_TCK);
+ retry:
-+ clk = times(&tmp);
-+ if (errno != 0) {
-+ log(LOG_WARNING, "times() failed: %m");
++ if (gettimeofday(&tv, 0) != 0) {
++ log(LOG_WARNING, "gettimeofday() failed: %m");
+ if (++n < 5)
+ goto retry;
+ else
-+ log(LOG_ERR, "times() failed after 5 retries: %m");
++ log(LOG_ERR,
++ "gettimeofday() failed after 5 retries: %m");
+ }
-+ return (clk * 1000) / sysconf(_SC_CLK_TCK);
++ timestamp = tv.tv_sec;
++ timestamp *= 1000;
++ timestamp += tv.tv_usec / 1000;
+
+- return (v * 1000) / sysconf(_SC_CLK_TCK);
++ return timestamp;
}
uint64_t get_time_of_day() {