As before, with iostat fix and man page for netstat.

Index: usr.bin/netstat/if.c
===================================================================
RCS file: /home/tedu/cvs/src/usr.bin/netstat/if.c,v
retrieving revision 1.61
diff -u -r1.61 if.c
--- usr.bin/netstat/if.c        4 Aug 2009 03:45:47 -0000       1.61
+++ usr.bin/netstat/if.c        16 Nov 2009 01:21:18 -0000
@@ -56,7 +56,7 @@
 #include "netstat.h"
 
 static void print_addr(struct sockaddr *, struct sockaddr **, struct if_data 
*);
-static void sidewaysintpr(u_int);
+static void sidewaysintpr(u_int, int);
 static void catchalarm(int);
 static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
 static void fetchifs(void);
@@ -67,7 +67,7 @@
  * which is a TAILQ_HEAD.
  */
 void
-intpr(int interval)
+intpr(int interval, int repeatcount)
 {
        struct if_msghdr ifm;
        int mib[6] = { CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
@@ -82,7 +82,7 @@
        size_t len;
 
        if (interval) {
-               sidewaysintpr((unsigned)interval);
+               sidewaysintpr((unsigned)interval, repeatcount);
                return;
        }
 
@@ -350,7 +350,7 @@
  * First line printed at top of screen is always cumulative.
  */
 static void
-sidewaysintpr(unsigned int interval)
+sidewaysintpr(unsigned int interval, int repeatcount)
 {
        sigset_t emptyset;
        int line;
@@ -449,16 +449,17 @@
 
        putchar('\n');
        fflush(stdout);
+       if (repeatcount && --repeatcount == 0)
+               return;
        line++;
        sigemptyset(&emptyset);
        if (!signalled)
                sigsuspend(&emptyset);
        signalled = 0;
        (void)alarm(interval);
-       if (line == 21)
+       if (line == 21 && isatty(STDOUT_FILENO))
                goto banner;
        goto loop;
-       /*NOTREACHED*/
 }
 
 /*
Index: usr.bin/netstat/main.c
===================================================================
RCS file: /home/tedu/cvs/src/usr.bin/netstat/main.c,v
retrieving revision 1.80
diff -u -r1.80 main.c
--- usr.bin/netstat/main.c      4 Oct 2009 16:08:37 -0000       1.80
+++ usr.bin/netstat/main.c      22 Nov 2009 00:56:38 -0000
@@ -158,10 +158,11 @@
        gid_t gid;
        u_long pcbaddr = 0;
        u_int tableid = 0;
+       int repeatcount = 0;
 
        af = AF_UNSPEC;
 
-       while ((ch = getopt(argc, argv, "AabdFf:gI:ilM:mN:np:P:qrsT:tuvW:w:")) 
!= -1)
+       while ((ch = getopt(argc, argv, 
"Aabc:dFf:gI:ilM:mN:np:P:qrsT:tuvW:w:")) != -1)
                switch (ch) {
                case 'A':
                        Aflag = 1;
@@ -172,6 +173,9 @@
                case 'b':
                        bflag = 1;
                        break;
+               case 'c':
+                       repeatcount = strtonum(optarg, 1, INT_MAX, &errstr);
+                       break;
                case 'd':
                        dflag = 1;
                        break;
@@ -372,7 +376,7 @@
        setnetent(1);
 
        if (iflag) {
-               intpr(interval);
+               intpr(interval, repeatcount);
                exit(0);
        }
        if (rflag) {
@@ -531,7 +535,7 @@
            "usage: %s [-Aan] [-f address_family] [-M core] [-N system]\n"
            "       %s [-bdFgilmnqrstu] [-f address_family] [-M core] [-N 
system]\n"
            "               [-T tableid]\n"
-           "       %s [-bdn] [-I interface] [-M core] [-N system] [-w wait]\n"
+           "       %s [-bdn] [-c count] [-I interface] [-M core] [-N system] 
[-w wait]\n"
            "       %s [-M core] [-N system] -P pcbaddr\n"
            "       %s [-s] [-M core] [-N system] [-p protocol]\n"
            "       %s [-a] [-f address_family] [-i | -I interface]\n"
Index: usr.bin/netstat/netstat.1
===================================================================
RCS file: /home/tedu/cvs/src/usr.bin/netstat/netstat.1,v
retrieving revision 1.56
diff -u -r1.56 netstat.1
--- usr.bin/netstat/netstat.1   27 Jun 2009 11:35:57 -0000      1.56
+++ usr.bin/netstat/netstat.1   22 Nov 2009 00:59:56 -0000
@@ -52,6 +52,7 @@
 .Ek
 .Nm netstat
 .Op Fl bdn
+.Op Fl c Ar count
 .Op Fl I Ar interface
 .Op Fl M Ar core
 .Op Fl N Ar system
@@ -119,6 +120,13 @@
 or
 .Fl i ) ,
 show bytes in and out, instead of packet statistics.
+.It Fl c Ar count
+Display
+.Ar count
+updates, then exit.
+This option has no effect unless
+.Fl w
+is specified as well.
 .It Fl d
 With either the interface display (options
 .Fl I
Index: usr.bin/netstat/netstat.h
===================================================================
RCS file: /home/tedu/cvs/src/usr.bin/netstat/netstat.h,v
retrieving revision 1.51
diff -u -r1.51 netstat.h
--- usr.bin/netstat/netstat.h   4 Oct 2009 16:08:37 -0000       1.51
+++ usr.bin/netstat/netstat.h   30 Oct 2009 22:11:45 -0000
@@ -130,7 +130,7 @@
 
 void   nsprotopr(u_long, char *);
 
-void   intpr(int);
+void   intpr(int, int);
 
 void   unixpr(u_long);
 
Index: usr.bin/vmstat/vmstat.c
===================================================================
RCS file: /home/tedu/cvs/src/usr.bin/vmstat/vmstat.c,v
retrieving revision 1.113
diff -u -r1.113 vmstat.c
--- usr.bin/vmstat/vmstat.c     27 Oct 2009 23:59:49 -0000      1.113
+++ usr.bin/vmstat/vmstat.c     16 Nov 2009 01:15:07 -0000
@@ -390,11 +390,11 @@
                        warn("could not read vm.vmmeter");
                        bzero(&total, sizeof(total));
                }
-               (void)printf("%2u%2u%2u",
+               (void)printf(" %u %u %u ",
                    total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw);
 #define        rate(x) ((((unsigned)x) + halfuptime) / uptime) /* round */
 #define pgtok(a) ((a) * ((unsigned int)uvmexp.pagesize >> 10))
-               (void)printf("%7u %7u ",
+               (void)printf("%6u %7u ",
                    pgtok(total.t_avm), pgtok(total.t_free));
                (void)printf("%4u ", rate(uvmexp.faults - ouvmexp.faults));
                (void)printf("%3u ", rate(uvmexp.pdreact - ouvmexp.pdreact));
@@ -427,6 +427,10 @@
 printhdr(void)
 {
        int i;
+       static int printedhdr;
+
+       if (printedhdr && !isatty(STDOUT_FILENO))
+               return;
 
        (void)printf(" procs    memory       page%*s", 20, "");
        if (ndrives > 0)
@@ -445,6 +449,7 @@
                            dr_name[i][strlen(dr_name[i]) - 1]);
        (void)printf(" int   sys   cs us sy id\n");
        hdrcnt = winlines - 2;
+       printedhdr = 1;
 }
 
 /*
Index: usr.sbin/iostat/iostat.c
===================================================================
RCS file: /home/tedu/cvs/src/usr.sbin/iostat/iostat.c,v
retrieving revision 1.26
diff -u -r1.26 iostat.c
--- usr.sbin/iostat/iostat.c    27 Oct 2009 23:59:51 -0000      1.26
+++ usr.sbin/iostat/iostat.c    22 Nov 2009 00:53:09 -0000
@@ -198,6 +198,10 @@
 header(void)
 {
        int i;
+       static int printedheader = 0;
+
+       if (printedheader && !isatty(STDOUT_FILENO))
+               return;
 
        /* Main Headers. */
        if (ISSET(todo, SHOW_TTY))

Reply via email to