Module Name:    src
Committed By:   roy
Date:           Fri Apr 20 13:27:45 UTC 2018

Modified Files:
        src/usr.sbin/rtadvd: timer.c timer.h

Log Message:
Allow timers to exist but be inactive.
This will be used in a future commit.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/rtadvd/timer.c
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/rtadvd/timer.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/rtadvd/timer.c
diff -u src/usr.sbin/rtadvd/timer.c:1.15 src/usr.sbin/rtadvd/timer.c:1.16
--- src/usr.sbin/rtadvd/timer.c:1.15	Fri Apr 20 10:39:37 2018
+++ src/usr.sbin/rtadvd/timer.c	Fri Apr 20 13:27:45 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: timer.c,v 1.15 2018/04/20 10:39:37 roy Exp $	*/
+/*	$NetBSD: timer.c,v 1.16 2018/04/20 13:27:45 roy Exp $	*/
 /*	$KAME: timer.c,v 1.11 2005/04/14 06:22:35 suz Exp $	*/
 
 /*
@@ -36,6 +36,7 @@
 #include <limits.h>
 #include <unistd.h>
 #include <syslog.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 #include <search.h>
@@ -110,6 +111,9 @@ rtadvd_set_timer(struct timespec *tm, st
 	/* upate the next expiration time */
 	if (timespeccmp(&timer->tm, &tm_max, <))
 		tm_max = timer->tm;
+
+	/* enable the timer */
+	timer->enabled = true;
 }
 
 /*
@@ -128,6 +132,8 @@ rtadvd_check_timer(void)
 	tm_max = tm_limit;
 
 	TAILQ_FOREACH_SAFE(tm, &ra_timer, next, tmn) {
+		if (!tm->enabled)
+			continue;
 		if (timespeccmp(&tm->tm, &now, <=)) {
 			if ((*tm->expire)(tm->expire_data) == NULL)
 				continue; /* the timer was removed */
@@ -157,9 +163,10 @@ rtadvd_timer_rest(struct rtadvd_timer *t
 
 	prog_clock_gettime(CLOCK_MONOTONIC, &now);
 	if (timespeccmp(&timer->tm, &now, <=)) {
-		logit(LOG_DEBUG,
-		       "<%s> a timer must be expired, but not yet",
-		       __func__);
+		if (timer->enabled)
+			logit(LOG_DEBUG,
+			       "<%s> a timer must be expired, but not yet",
+			       __func__);
 		returnval.tv_sec = 0;
 		returnval.tv_nsec = 0;
 	}

Index: src/usr.sbin/rtadvd/timer.h
diff -u src/usr.sbin/rtadvd/timer.h:1.9 src/usr.sbin/rtadvd/timer.h:1.10
--- src/usr.sbin/rtadvd/timer.h:1.9	Fri Apr 20 10:39:37 2018
+++ src/usr.sbin/rtadvd/timer.h	Fri Apr 20 13:27:45 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: timer.h,v 1.9 2018/04/20 10:39:37 roy Exp $	*/
+/*	$NetBSD: timer.h,v 1.10 2018/04/20 13:27:45 roy Exp $	*/
 /*	$KAME: timer.h,v 1.5 2002/05/31 13:30:38 jinmei Exp $	*/
 
 /*
@@ -35,6 +35,7 @@ struct rtadvd_timer {
 	TAILQ_ENTRY(rtadvd_timer) next;
 	struct rainfo *rai;
 	struct timespec tm;
+	bool enabled;
 
 	struct rtadvd_timer *(*expire) (void *); /* expiration function */
 	void *expire_data;

Reply via email to