diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-08-09 08:45:33 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-08-09 08:45:33 +0000 |
commit | adf46ad22328061291b5cd5e00bbea631c643bca (patch) | |
tree | be6303e0929f65e26578122ffb0eca249814663e /usr.sbin | |
parent | 46aae13493427b44fe59bafd28c37504f196c4e3 (diff) |
sync, simplify, etc. slstats -i is now called -w, like pppstats
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pppd/pppstats/pppstats.c | 47 | ||||
-rw-r--r-- | usr.sbin/slstats/slstats.8 | 13 | ||||
-rw-r--r-- | usr.sbin/slstats/slstats.c | 46 |
3 files changed, 47 insertions, 59 deletions
diff --git a/usr.sbin/pppd/pppstats/pppstats.c b/usr.sbin/pppd/pppstats/pppstats.c index ff5ce27bfaf..5e23b402642 100644 --- a/usr.sbin/pppd/pppstats/pppstats.c +++ b/usr.sbin/pppd/pppstats/pppstats.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pppstats.c,v 1.5 1998/05/08 04:52:37 millert Exp $ */ +/* $OpenBSD: pppstats.c,v 1.6 2001/08/09 08:45:31 deraadt Exp $ */ /* * print PPP statistics: @@ -37,7 +37,7 @@ #if 0 static char rcsid[] = "Id: pppstats.c,v 1.22 1998/03/31 23:48:03 paulus Exp $"; #else -static char rcsid[] = "$OpenBSD: pppstats.c,v 1.5 1998/05/08 04:52:37 millert Exp $"; +static char rcsid[] = "$OpenBSD: pppstats.c,v 1.6 2001/08/09 08:45:31 deraadt Exp $"; #endif #endif @@ -69,21 +69,20 @@ int s; /* socket file descriptor */ int signalled; /* set if alarm goes off "early" */ char interface[IFNAMSIZ]; -static void usage __P((void)); -static void catchalarm __P((int)); -static void get_ppp_stats __P((struct ppp_stats *)); -static void get_ppp_cstats __P((struct ppp_comp_stats *)); -static void intpr __P((void)); - +void usage __P((void)); +void catchalarm __P((int)); +void get_ppp_stats __P((struct ppp_stats *)); +void get_ppp_cstats __P((struct ppp_comp_stats *)); +void intpr __P((void)); int main __P((int, char *argv[])); -static void +void usage() { extern char *__progname; fprintf(stderr, - "Usage: %s [-a|-d] [-v|-r|-z] [-c count] [-w wait] [interface]\n", + "Usage: %s [-adrvz] [-c count] [-w wait] [interface]\n", __progname); exit(1); } @@ -92,23 +91,21 @@ usage() * Called if an interval expires before intpr has completed a loop. * Sets a flag to not wait for the alarm. */ -static void +void catchalarm(arg) int arg; { - signalled = 1; } -static void +void get_ppp_stats(curp) struct ppp_stats *curp; { struct ifpppstatsreq req; memset(&req, 0, sizeof(req)); - (void)strncpy(req.ifr_name, interface, sizeof(req.ifr_name) - 1); - req.ifr_name[sizeof(req.ifr_name) - 1] = '\0'; + (void)strlcpy(req.ifr_name, interface, sizeof(req.ifr_name)); if (ioctl(s, SIOCGPPPSTATS, &req) < 0) { if (errno == ENOTTY) @@ -119,15 +116,14 @@ get_ppp_stats(curp) *curp = req.stats; } -static void +void get_ppp_cstats(csp) struct ppp_comp_stats *csp; { struct ifpppcstatsreq creq; memset(&creq, 0, sizeof(creq)); - (void)strncpy(creq.ifr_name, interface, sizeof(creq.ifr_name) - 1); - creq.ifr_name[sizeof(creq.ifr_name) - 1] = '\0'; + (void)strlcpy(creq.ifr_name, interface, sizeof(creq.ifr_name)); if (ioctl(s, SIOCGPPPCSTATS, &creq) < 0) { if (errno == ENOTTY) { @@ -156,7 +152,7 @@ get_ppp_cstats(csp) * collected over that interval. Assumes that interval is non-zero. * First line printed is cumulative. */ -static void +void intpr() { register int line = 0; @@ -312,7 +308,7 @@ main(argc, argv) int c; struct ifreq ifr; - (void)strcpy(interface, "ppp0"); + (void)strlcpy(interface, "ppp0", sizeof(interface)); while ((c = getopt(argc, argv, "advrzc:w:")) != -1) { switch (c) { @@ -359,17 +355,16 @@ main(argc, argv) if (argc > 1) usage(); - if (argc > 0) { - (void)strncpy(interface, argv[0], sizeof(interface) - 1); - interface[sizeof(interface) - 1] = '\0'; - } - if (sscanf(interface, "ppp%d", &unit) != 1) + if (argc > 0) + (void)strlcpy(interface, argv[0], sizeof(interface)); + + if (sscanf(interface, "ppp%d", &unit) != 1 || unit < 0) errx(1, "invalid interface '%s' specified", interface); s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) err(1, "couldn't create IP socket"); - (void)strcpy(ifr.ifr_name, interface); + (void)strlcpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) errx(1, "nonexistent interface '%s' specified", interface); diff --git a/usr.sbin/slstats/slstats.8 b/usr.sbin/slstats/slstats.8 index da0588787f9..d8e59723b67 100644 --- a/usr.sbin/slstats/slstats.8 +++ b/usr.sbin/slstats/slstats.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: slstats.8,v 1.9 2000/11/09 17:53:24 aaron Exp $ +.\" $OpenBSD: slstats.8,v 1.10 2001/08/09 08:45:32 deraadt Exp $ .\" $NetBSD: slstats.8,v 1.2.6.1 1996/06/07 01:42:24 thorpej Exp $ .Dd July 5, 1993 .Dt SLSTATS 8 @@ -8,10 +8,8 @@ .Nd report slip statistics .Sh SYNOPSIS .Nm slstats -.Op Fl M Ar core -.Op Fl N Ar system .Op Fl v -.Op Fl i Ar interval +.Op Fl w Ar interval .Op Ar unit-number .Sh DESCRIPTION The @@ -41,14 +39,9 @@ The options are as follows: Display additional statistics demonstrating the efficacy of VJ header compression and providing more explicit information on failure distribution. -.It Fl i +.It Fl w Specifies the interval between reports. The default interval is 5 seconds. -.It Fl M Ar core -Extract values associated with the name list from the specified. -.It Fl N Ar system -Extract the name list from the specified system instead of the default -.Pa /bsd . .El .Pp The following fields are printed on the input side: diff --git a/usr.sbin/slstats/slstats.c b/usr.sbin/slstats/slstats.c index ff61ed01615..7c11fb413d4 100644 --- a/usr.sbin/slstats/slstats.c +++ b/usr.sbin/slstats/slstats.c @@ -1,4 +1,4 @@ -/* $OpenBSD: slstats.c,v 1.11 2001/07/31 19:50:16 deraadt Exp $ */ +/* $OpenBSD: slstats.c,v 1.12 2001/08/09 08:45:32 deraadt Exp $ */ /* $NetBSD: slstats.c,v 1.6.6.1 1996/06/07 01:42:30 thorpej Exp $ */ /* @@ -25,7 +25,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: slstats.c,v 1.11 2001/07/31 19:50:16 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: slstats.c,v 1.12 2001/08/09 08:45:32 deraadt Exp $"; #endif #define INET @@ -79,7 +79,7 @@ main(argc, argv) struct ifreq ifr; int ch; - (void)strcpy(interface, "sl0"); + (void)strlcpy(interface, "sl0", sizeof(interface)); while ((ch = getopt(argc, argv, "i:M:N:v")) != -1) { switch (ch) { @@ -103,17 +103,16 @@ main(argc, argv) if (argc > 1) usage(); - if (argc > 0) { - (void)strncpy(interface, argv[0], sizeof(interface) - 1); - interface[sizeof(interface) - 1] = '\0'; - } - if (sscanf(interface, "sl%d", &unit) != 1) + if (argc > 0) + (void)strlcpy(interface, argv[0], sizeof(interface)); + + if (sscanf(interface, "sl%d", &unit) != 1 || unit < 0) errx(1, "invalid interface '%s' specified", interface); s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) err(1, "couldn't create IP socket"); - (void)strcpy(ifr.ifr_name, interface); + (void)strlcpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) errx(1, "nonexistent interface '%s' specified", interface); @@ -141,8 +140,7 @@ get_sl_stats(curp) struct ifslstatsreq req; memset(&req, 0, sizeof(req)); - (void)strncpy(req.ifr_name, interface, sizeof(req.ifr_name) - 1); - req.ifr_name[sizeof(req.ifr_name) - 1] = '\0'; + (void)strlcpy(req.ifr_name, interface, sizeof(req.ifr_name)); if (ioctl(s, SIOCGSLSTATS, &req) < 0) { if (errno == ENOTTY) @@ -162,9 +160,9 @@ get_sl_stats(curp) void intpr() { - int line = 0; - int oldmask; struct sl_stats cur, old; + sigset_t mask, oldmask; + int line = 0; bzero(&old, sizeof(old)); while (1) { @@ -190,13 +188,10 @@ intpr() V(vj.vjs_uncompressedin), V(vj.vjs_errorin)); if (vflag) printf(" %6u %6u", V(vj.vjs_tossed), - V(sl.sl_ipackets) - - V(vj.vjs_compressedin) - - V(vj.vjs_uncompressedin) - - V(vj.vjs_errorin)); + V(sl.sl_ipackets) - V(vj.vjs_compressedin) - + V(vj.vjs_uncompressedin) - V(vj.vjs_errorin)); printf(" | %8u %6d %6u %6u %6u", V(sl.sl_obytes), - V(sl.sl_opackets), - V(vj.vjs_compressed), + V(sl.sl_opackets), V(vj.vjs_compressed), V(vj.vjs_packets) - V(vj.vjs_compressed), V(sl.sl_opackets) - V(vj.vjs_packets)); if (vflag) @@ -206,10 +201,15 @@ intpr() putchar('\n'); fflush(stdout); line++; - oldmask = sigblock(sigmask(SIGALRM)); - if (!signalled) - sigpause(0); - sigsetmask(oldmask); + + sigemptyset(&mask); + sigaddset(&mask, SIGALRM); + sigprocmask(SIG_BLOCK, &mask, &oldmask); + if (!signalled) { + sigemptyset(&mask); + sigsuspend(&mask); + } + sigprocmask(SIG_BLOCK, &oldmask, NULL); signalled = 0; (void)alarm(interval); old = cur; |