diff options
author | 2009-11-22 22:22:14 +0000 | |
---|---|---|
committer | 2009-11-22 22:22:14 +0000 | |
commit | fe30a845b597a04da29832b9e03a5e00312cab2b (patch) | |
tree | 4b93207ba3269ddb4a2b6e8acbed7b175794c1e5 | |
parent | brconfig will soon be gone (diff) | |
download | wireguard-openbsd-fe30a845b597a04da29832b9e03a5e00312cab2b.tar.xz wireguard-openbsd-fe30a845b597a04da29832b9e03a5e00312cab2b.zip |
don't repeat the banner if not a tty.
add a -c count option to netstat.
tweak spacing to not smear fields in vmstat.
ok deraadt sthen
-rw-r--r-- | usr.bin/netstat/if.c | 15 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 12 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.1 | 12 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 4 | ||||
-rw-r--r-- | usr.bin/vmstat/vmstat.c | 11 | ||||
-rw-r--r-- | usr.sbin/iostat/iostat.c | 6 |
6 files changed, 41 insertions, 19 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index c823347fb10..340fdb4e218 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.61 2009/08/04 03:45:47 tedu Exp $ */ +/* $OpenBSD: if.c,v 1.62 2009/11/22 22:22:14 tedu Exp $ */ /* $NetBSD: if.c,v 1.16.4.2 1996/06/07 21:46:46 thorpej Exp $ */ /* @@ -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 @@ static void fetchifs(void); * 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 @@ intpr(int interval) size_t len; if (interval) { - sidewaysintpr((unsigned)interval); + sidewaysintpr((unsigned)interval, repeatcount); return; } @@ -350,7 +350,7 @@ volatile sig_atomic_t signalled; /* set if alarm goes off "early" */ * 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 @@ loop: 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*/ } /* diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index ba2c79b4528..3bf8336340f 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.81 2009/11/05 20:50:14 michele Exp $ */ +/* $OpenBSD: main.c,v 1.82 2009/11/22 22:22:14 tedu Exp $ */ /* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */ /* @@ -161,10 +161,11 @@ main(int argc, char *argv[]) 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; @@ -175,6 +176,9 @@ main(int argc, char *argv[]) case 'b': bflag = 1; break; + case 'c': + repeatcount = strtonum(optarg, 1, INT_MAX, &errstr); + break; case 'd': dflag = 1; break; @@ -375,7 +379,7 @@ main(int argc, char *argv[]) setnetent(1); if (iflag) { - intpr(interval); + intpr(interval, repeatcount); exit(0); } if (rflag) { @@ -534,7 +538,7 @@ usage(void) "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" diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1 index 3c0100c47ad..80709ba9df4 100644 --- a/usr.bin/netstat/netstat.1 +++ b/usr.bin/netstat/netstat.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: netstat.1,v 1.56 2009/06/27 11:35:57 michele Exp $ +.\" $OpenBSD: netstat.1,v 1.57 2009/11/22 22:22:14 tedu Exp $ .\" $NetBSD: netstat.1,v 1.11 1995/10/03 21:42:43 thorpej Exp $ .\" .\" Copyright (c) 1983, 1990, 1992, 1993 @@ -30,7 +30,7 @@ .\" .\" from: @(#)netstat.1 8.8 (Berkeley) 4/18/94 .\" -.Dd $Mdocdate: June 27 2009 $ +.Dd $Mdocdate: November 22 2009 $ .Dt NETSTAT 1 .Os .Sh NAME @@ -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 @@ With the interface display (options 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 diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index 87a4c8f4c0a..7265e6513ee 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netstat.h,v 1.52 2009/11/05 20:50:14 michele Exp $ */ +/* $OpenBSD: netstat.h,v 1.53 2009/11/22 22:22:14 tedu Exp $ */ /* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */ /* @@ -131,7 +131,7 @@ void routepr(u_long, u_long, u_long, u_long, u_int); void nsprotopr(u_long, char *); -void intpr(int); +void intpr(int, int); void unixpr(u_long); diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index d7b5fdedf5d..288e70795e8 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -1,5 +1,5 @@ /* $NetBSD: vmstat.c,v 1.29.4.1 1996/06/05 00:21:05 cgd Exp $ */ -/* $OpenBSD: vmstat.c,v 1.113 2009/10/27 23:59:49 deraadt Exp $ */ +/* $OpenBSD: vmstat.c,v 1.114 2009/11/22 22:22:14 tedu Exp $ */ /* * Copyright (c) 1980, 1986, 1991, 1993 @@ -390,11 +390,11 @@ dovmstat(u_int interval, int reps) 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 @@ void 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 @@ printhdr(void) dr_name[i][strlen(dr_name[i]) - 1]); (void)printf(" int sys cs us sy id\n"); hdrcnt = winlines - 2; + printedhdr = 1; } /* diff --git a/usr.sbin/iostat/iostat.c b/usr.sbin/iostat/iostat.c index 8280b5b52a4..7da45b59b4e 100644 --- a/usr.sbin/iostat/iostat.c +++ b/usr.sbin/iostat/iostat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iostat.c,v 1.26 2009/10/27 23:59:51 deraadt Exp $ */ +/* $OpenBSD: iostat.c,v 1.27 2009/11/22 22:22:14 tedu Exp $ */ /* $NetBSD: iostat.c,v 1.10 1996/10/25 18:21:58 scottr Exp $ */ /* @@ -198,6 +198,10 @@ static void header(void) { int i; + static int printedheader = 0; + + if (printedheader && !isatty(STDOUT_FILENO)) + return; /* Main Headers. */ if (ISSET(todo, SHOW_TTY)) |