Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/route Support -c <count> option for route monitor



details:   https://anonhg.NetBSD.org/src/rev/02eea8d1e18b
branches:  trunk
changeset: 354432:02eea8d1e18b
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Fri Jun 16 04:40:16 2017 +0000

description:
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.

diffstat:

 sbin/route/route.8 |  13 +++++++++++--
 sbin/route/route.c |  31 ++++++++++++++++++++++++-------
 2 files changed, 35 insertions(+), 9 deletions(-)

diffs (113 lines):

diff -r 2224d160eedd -r 02eea8d1e18b sbin/route/route.8
--- a/sbin/route/route.8        Fri Jun 16 04:16:18 2017 +0000
+++ b/sbin/route/route.8        Fri Jun 16 04:40:16 2017 +0000
@@ -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 @@
 .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
diff -r 2224d160eedd -r 02eea8d1e18b sbin/route/route.c
--- a/sbin/route/route.c        Fri Jun 16 04:16:18 2017 +0000
+++ b/sbin/route/route.c        Fri Jun 16 04:40:16 2017 +0000
@@ -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 @@
 #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 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 @@
 
 #ifndef SMALL
        case K_MONITOR:
-               monitor();
+               monitor(argc, argv);
                return 0;
 
 #endif /* SMALL */
@@ -1105,20 +1105,37 @@
 }
 
 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);



Home | Main Index | Thread Index | Old Index