[BACK]Return to patch-dbeacon__posix.cpp CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / mbone / dbeacon / patches

File: [cvs.NetBSD.org] / pkgsrc / mbone / dbeacon / patches / patch-dbeacon__posix.cpp (download)

Revision 1.1, Tue Dec 9 10:45:51 2014 UTC (9 years, 4 months ago) by he
Branch: MAIN
CVS Tags: pkgsrc-2014Q4-base, pkgsrc-2014Q4

It can happen that times() returns ((uint32_t)-1).  If that happens,
retry a limited number of times, and log the events.  Export log() from
the main program for use in dbeacon_posix.cpp.

Fix the matrix.pl script since qw() no longer acts as parenteses, so add
some of our own where called for.

Bump PKGREVISION.

$NetBSD: patch-dbeacon__posix.cpp,v 1.1 2014/12/09 10:45:51 he Exp $

Retry if times() returns with an error.
It has been known to return ((uint32_t)-1).

--- dbeacon_posix.cpp.orig	2007-06-09 11:35:57.000000000 +0000
+++ dbeacon_posix.cpp
@@ -25,6 +25,7 @@
 #include <sys/time.h>
 #include <netdb.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <sys/uio.h>
 #include <sys/times.h>
 
@@ -516,10 +517,19 @@ void address::set(const sockaddr *sa) {
 
 uint64_t get_timestamp() {
 	struct tms tmp;
+	clock_t clk;
+	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 (++n < 5)
+			goto retry;
+		else
+			log(LOG_ERR, "times() failed after 5 retries: %m");
+	}
+	return (clk * 1000) / sysconf(_SC_CLK_TCK);
 }
 
 uint64_t get_time_of_day() {