File ntp-sntp-libevent.patch of Package ntp

--- sntp/main.c.orig
+++ sntp/main.c
@@ -118,7 +118,6 @@ void set_li_vn_mode(struct pkt *spkt, ch
 int  set_time(double offset);
 void dec_pending_ntp(const char *, sockaddr_u *);
 int  libevent_version_ok(void);
-int  gettimeofday_cached(struct event_base *b, struct timeval *tv);
 
 
 /*
@@ -271,7 +270,7 @@ sntp_main (
 	for (i = 0; i < argc; ++i)
 		handle_lookup(argv[i], CTX_UCST);
 
-	gettimeofday_cached(base, &start_tv);
+	gettimeofday(&start_tv, NULL);
 	event_base_dispatch(base);
 	event_base_free(base);
 
@@ -571,7 +570,7 @@ queue_xmt(
 	xctx = emalloc_zero(sizeof(*xctx));
 	xctx->sock = sock;
 	xctx->spkt = spkt;
-	gettimeofday_cached(base, &start_cb);
+	gettimeofday(&start_cb, NULL);
 	xctx->sched = start_cb.tv_sec + (2 * xmt_delay);
 
 	LINK_SORT_SLIST(xmt_q, xctx, (xctx->sched < L_S_S_CUR()->sched),
@@ -621,7 +620,7 @@ xmt_timer_cb(
 
 	if (NULL == xmt_q || shutting_down)
 		return;
-	gettimeofday_cached(base, &start_cb);
+	gettimeofday(&start_cb, NULL);
 	if (xmt_q->sched <= start_cb.tv_sec) {
 		UNLINK_HEAD_SLIST(x, xmt_q, link);
 		TRACE(2, ("xmt_timer_cb: at .%6.6u -> %s\n",
@@ -708,7 +707,7 @@ timeout_queries(void)
 	TRACE(3, ("timeout_queries: called to check %u items\n",
 		  (unsigned)COUNTOF(fam_listheads)));
 
-	gettimeofday_cached(base, &start_cb);
+	gettimeofday(&start_cb, NULL);
 	for (idx = 0; idx < COUNTOF(fam_listheads); idx++) {
 		head = fam_listheads[idx];
 		for (spkt = head; spkt != NULL; spkt = spkt_next) {
@@ -1224,7 +1223,7 @@ handle_pkt(
 		TRACE(3, ("handle_pkt: %d bytes from %s %s\n",
 			  rpktl, stoa(host), hostname));
 
-		gettimeofday_cached(base, &tv_dst);
+		gettimeofday(&tv_dst, NULL);
 
 		p_SNTP_PRETEND_TIME = getenv("SNTP_PRETEND_TIME");
 		if (p_SNTP_PRETEND_TIME) {
@@ -1513,101 +1512,6 @@ libevent_version_ok(void)
 	}
 	return 1;
 }
-
-/*
- * gettimeofday_cached()
- *
- * Clones the event_base_gettimeofday_cached() interface but ensures the
- * times are always on the gettimeofday() 1970 scale.  Older libevent 2
- * sometimes used gettimeofday(), sometimes the since-system-start
- * clock_gettime(CLOCK_MONOTONIC), depending on the platform.
- *
- * It is not cleanly possible to tell which timescale older libevent is
- * using.
- *
- * The strategy involves 1 hour thresholds chosen to be far longer than
- * the duration of a round of libevent callbacks, which share a cached
- * start-of-round time.  First compare the last cached time with the
- * current gettimeofday() time.  If they are within one hour, libevent
- * is using the proper timescale so leave the offset 0.  Otherwise,
- * compare libevent's cached time and the current time on the monotonic
- * scale.  If they are within an hour, libevent is using the monotonic
- * scale so calculate the offset to add to such times to bring them to
- * gettimeofday()'s scale.
- */
-int
-gettimeofday_cached(
-	struct event_base *	b,
-	struct timeval *	caller_tv
-	)
-{
-#if defined(_EVENT_HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
-	static struct event_base *	cached_b;
-	static struct timeval		cached;
-	static struct timeval		adj_cached;
-	static struct timeval		offset;
-	static int			offset_ready;
-	struct timeval			latest;
-	struct timeval			systemt;
-	struct timespec			ts;
-	struct timeval			mono;
-	struct timeval			diff;
-	int				cgt_rc;
-	int				gtod_rc;
-
-	event_base_gettimeofday_cached(b, &latest);
-	if (b == cached_b &&
-	    !memcmp(&latest, &cached, sizeof(latest))) {
-		*caller_tv = adj_cached;
-		return 0;
-	}
-	cached = latest;
-	cached_b = b;
-	if (!offset_ready) {
-		cgt_rc = clock_gettime(CLOCK_MONOTONIC, &ts);
-		gtod_rc = gettimeofday(&systemt, NULL);
-		if (0 != gtod_rc) {
-			msyslog(LOG_ERR,
-				"%s: gettimeofday() error %m",
-				progname);
-			exit(1);
-		}
-		diff = sub_tval(systemt, latest);
-		if (debug > 1)
-			printf("system minus cached %+ld.%06ld\n",
-			       (long)diff.tv_sec, (long)diff.tv_usec);
-		if (0 != cgt_rc || labs((long)diff.tv_sec) < 3600) {
-			/*
-			 * Either use_monotonic == 0, or this libevent
-			 * has been repaired.  Leave offset at zero.
-			 */
-		} else {
-			mono.tv_sec = ts.tv_sec;
-			mono.tv_usec = ts.tv_nsec / 1000;
-			diff = sub_tval(latest, mono);
-			if (debug > 1)
-				printf("cached minus monotonic %+ld.%06ld\n",
-				       (long)diff.tv_sec, (long)diff.tv_usec);
-			if (labs((long)diff.tv_sec) < 3600) {
-				/* older libevent2 using monotonic */
-				offset = sub_tval(systemt, mono);
-				TRACE(1, ("%s: Offsetting libevent CLOCK_MONOTONIC times  by %+ld.%06ld\n",
-					 "gettimeofday_cached",
-					 (long)offset.tv_sec,
-					 (long)offset.tv_usec));
-			}
-		}
-		offset_ready = TRUE;
-	}
-	adj_cached = add_tval(cached, offset);
-	*caller_tv = adj_cached;
-
-	return 0;
-#else
-	return event_base_gettimeofday_cached(b, caller_tv);
-#endif
-}
-
 /* Dummy function to satisfy libntp/work_fork.c */
 extern int set_user_group_ids(void);
 int set_user_group_ids(void)
openSUSE Build Service is sponsored by