Module Name:    src
Committed By:   ozaki-r
Date:           Fri Jun 16 04:40:16 UTC 2017

Modified Files:
        src/sbin/route: route.8 route.c

Log Message:
Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sbin/route/route.8
cvs rdiff -u -r1.155 -r1.156 src/sbin/route/route.c

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

Modified files:

Index: src/sbin/route/route.8
diff -u src/sbin/route/route.8:1.56 src/sbin/route/route.8:1.57
--- src/sbin/route/route.8:1.56	Mon Apr  4 07:37:07 2016
+++ src/sbin/route/route.8	Fri Jun 16 04:40:16 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: route.8,v 1.56 2016/04/04 07:37:07 ozaki-r Exp $
+.\"	$NetBSD: route.8,v 1.57 2017/06/16 04:40:16 ozaki-r Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)route.8	8.4 (Berkeley) 6/1/94
 .\"
-.Dd March 30, 2016
+.Dd June 16, 2017
 .Dt ROUTE 8
 .Os
 .Sh NAME
@@ -139,8 +139,17 @@ The monitor command has the syntax
 .Nm
 .Op Fl n
 .Cm monitor
+.Op Fl c Ar count
 .Ed
 .Pp
+If
+.Ar count
+is specified,
+.Nm
+exits after receiving
+.Ar count
+routing messages.
+.Pp
 The flush command has the syntax
 .Pp
 .Bd -filled -offset indent -compact

Index: src/sbin/route/route.c
diff -u src/sbin/route/route.c:1.155 src/sbin/route/route.c:1.156
--- src/sbin/route/route.c:1.155	Fri Mar 17 16:13:44 2017
+++ src/sbin/route/route.c	Fri Jun 16 04:40:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.155 2017/03/17 16:13:44 roy Exp $	*/
+/*	$NetBSD: route.c,v 1.156 2017/06/16 04:40:16 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1983, 1989, 1991, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "@(#)route.c	8.6 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: route.c,v 1.155 2017/03/17 16:13:44 roy Exp $");
+__RCSID("$NetBSD: route.c,v 1.156 2017/06/16 04:40:16 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -108,7 +108,7 @@ static char *netmask_string(const struct
 static int prefixlen(const char *, struct sou *);
 #ifndef SMALL
 static void interfaces(void);
-__dead static void monitor(void);
+static void monitor(int, char * const *);
 static int print_getmsg(struct rt_msghdr *, int, struct sou *);
 static const char *linkstate(struct if_msghdr *);
 static sup readtag(sup, const char *);
@@ -236,7 +236,7 @@ main(int argc, char * const *argv)
 
 #ifndef SMALL
 	case K_MONITOR:
-		monitor();
+		monitor(argc, argv);
 		return 0;
 
 #endif /* SMALL */
@@ -1105,20 +1105,37 @@ interfaces(void)
 }
 
 static void
-monitor(void)
+monitor(int argc, char * const *argv)
 {
-	int n;
+	int i, n;
 	union {
 		char msg[2048];
 		struct rt_msghdr hdr;
 	} u;
+	int count = 0;
+
+	/* usage: route monitor [-c <count>] */
+
+	/* eat "monitor" */
+	argc -= 1;
+	argv += 1;
+
+	/* parse [-c <count>] */
+	if (argc > 0) {
+		if (argc != 2)
+			usage(argv[0]);
+		if (strcmp(argv[0], "-c") != 0)
+			usage(argv[0]);
+
+		count = atoi(argv[1]);
+	}
 
 	verbose = 1;
 	if (debugonly) {
 		interfaces();
 		exit(0);
 	}
-	for(;;) {
+	for(i = 0; count == 0 || i < count; i++) {
 		time_t now;
 		n = prog_read(sock, &u, sizeof(u));
 		now = time(NULL);

Reply via email to