summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1996-06-10 08:38:54 +0000
committerderaadt <deraadt@openbsd.org>1996-06-10 08:38:54 +0000
commitf5228b4bf41a38fb4ab9ef94a79720c34fe50764 (patch)
tree3a3c20253ed673f6cf99614bc3a43506ae399bdc
parentupdate ttystats (diff)
downloadwireguard-openbsd-f5228b4bf41a38fb4ab9ef94a79720c34fe50764.tar.xz
wireguard-openbsd-f5228b4bf41a38fb4ab9ef94a79720c34fe50764.zip
support strip, use kvm_openfiles
-rw-r--r--usr.sbin/slstats/slstats.826
-rw-r--r--usr.sbin/slstats/slstats.c187
2 files changed, 92 insertions, 121 deletions
diff --git a/usr.sbin/slstats/slstats.8 b/usr.sbin/slstats/slstats.8
index ae2ab8b5511..6c600815d78 100644
--- a/usr.sbin/slstats/slstats.8
+++ b/usr.sbin/slstats/slstats.8
@@ -1,4 +1,5 @@
-.\" @(#) $Header: /home/cvs/src/usr.sbin/slstats/Attic/slstats.8,v 1.1.1.1 1995/10/18 08:48:21 deraadt Exp $ (LBL)
+.\" $OpenBSD: slstats.8,v 1.2 1996/06/10 08:38:54 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
.Sh NAME
@@ -6,13 +7,11 @@
.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 Ar unit-number
-.Oo
-.Ar system
-.Op Ar core
-.Oc
.Sh DESCRIPTION
.Pp
The
@@ -36,21 +35,18 @@ statistics. All further output will describe activity between report
intervals.
.Pp
The options are as follows:
-.Bl -tag -width Ds
+.Bl -tag -width "system "
.It Fl v
Display additional statistics demonstrating the efficacy of VJ header
compression and providing more explicit information on failure
distribution.
.It Fl i
Specifies the interval between reports. The default interval is 5 seconds.
-.It Ar system
+.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 /netbsd .
-.It Ar core
-Extract values associated with the name list from the specified
-.Ar core
-instead of the default
-.Pa /dev/kmem .
.El
.Pp
The following fields are printed on the input side:
@@ -101,12 +97,6 @@ compressed packet. Only reported when the
option is specified.
.El
.Sh BUGS
-Should use
-.Fl M Ar core
-and
-.Fl N Ar system
-like most other programs using the kvm library.
-.Pp
Should take an interface name and not a unit number.
.Pp
.Sh SEE ALSO
diff --git a/usr.sbin/slstats/slstats.c b/usr.sbin/slstats/slstats.c
index 1d3c1df3aaa..8c90162e9ed 100644
--- a/usr.sbin/slstats/slstats.c
+++ b/usr.sbin/slstats/slstats.c
@@ -1,6 +1,9 @@
+/* $OpenBSD: slstats.c,v 1.4 1996/06/10 08:38:55 deraadt Exp $ */
+/* $NetBSD: slstats.c,v 1.6.6.1 1996/06/07 01:42:30 thorpej Exp $ */
+
/*
* print serial line IP statistics:
- * slstats [-i interval] [-v] [interface] [system] [core]
+ * slstats [-i interval] [-v] [interface] [system [core]]
*
* Copyright (c) 1989, 1990, 1991, 1992 Regents of the University of
* California. All rights reserved.
@@ -22,15 +25,9 @@
*/
#ifndef lint
-/*static char rcsid[] =
- "@(#) $Header: /home/cvs/src/usr.sbin/slstats/Attic/slstats.c,v 1.3 1996/06/04 07:52:01 deraadt Exp $ (LBL)";*/
-static char rcsid[] = "$Id: slstats.c,v 1.3 1996/06/04 07:52:01 deraadt Exp $";
+static char rcsid[] = "$OpenBSD";
#endif
-#include <stdio.h>
-#include <paths.h>
-#include <nlist.h>
-
#define INET
#include <sys/param.h>
@@ -38,8 +35,7 @@ static char rcsid[] = "$Id: slstats.c,v 1.3 1996/06/04 07:52:01 deraadt Exp $";
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/file.h>
-#include <errno.h>
-#include <signal.h>
+
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@@ -49,72 +45,105 @@ static char rcsid[] = "$Id: slstats.c,v 1.3 1996/06/04 07:52:01 deraadt Exp $";
#include <net/slcompress.h>
#include <net/if_slvar.h>
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <kvm.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <paths.h>
+#include <nlist.h>
+#include <unistd.h>
+
struct nlist nl[] = {
#define N_SOFTC 0
{ "_sl_softc" },
"",
};
-char *system = _PATH_UNIX;
-char *kmemf = _PATH_KMEM;
+extern char __progname; /* from crt0.o */
+
+char *kernel; /* kernel for namelist */
+char *kmemf; /* memory file */
+
+kvm_t *kd;
-int kflag;
int vflag;
unsigned interval = 5;
int unit;
-extern char *malloc();
-extern off_t lseek();
+void catchalarm __P((void));
+void intpr __P((void));
+void usage __P((void));
+int
main(argc, argv)
int argc;
char *argv[];
{
- --argc; ++argv;
- while (argc > 0) {
- if (strcmp(argv[0], "-v") == 0) {
- ++vflag;
- ++argv, --argc;
- continue;
- }
- if (strcmp(argv[0], "-i") == 0 && argv[1] &&
- isdigit(argv[1][0])) {
- interval = atoi(argv[1]);
+ char errbuf[_POSIX2_LINE_MAX];
+ int ch;
+
+ while ((ch = getopt(argc, argv, "i:M:N:v")) != -1) {
+ switch (ch) {
+ case 'i':
+ interval = atoi(optarg);
if (interval <= 0)
usage();
- ++argv, --argc;
- ++argv, --argc;
- continue;
+ break;
+
+ case 'M':
+ kmemf = optarg;
+ break;
+
+ case 'N':
+ kernel = optarg;
+ break;
+
+ case 'v':
+ ++vflag;
+ break;
+
+ default:
+ usage();
}
- if (isdigit(argv[0][0])) {
- unit = atoi(argv[0]);
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc > 1)
+ usage();
+
+ while (argc--) {
+ if (isdigit(*argv[0])) {
+ unit = atoi(*argv);
if (unit < 0)
usage();
- ++argv, --argc;
continue;
}
- if (kflag)
- usage();
- system = *argv;
- ++argv, --argc;
- if (argc > 0) {
- kmemf = *argv++;
- --argc;
- kflag++;
- }
+ /* Fall to here, we have bogus arguments. */
+ usage();
}
- /*
+
+ /*
* Discard setgid privileges if not the running kernel so that bad
* guys can't print interesting stuff from kernel memory.
*/
- if (!strcmp(kmemf, _PATH_KMEM) || !strcmp(system, _PATH_UNIX))
+ if (kmemf != NULL || kernel != NULL)
setgid(getgid());
- if (kopen(system, kmemf, "slstats") < 0)
- exit(1);
- if (knlist(system, nl, "slstats") < 0)
- exit(1);
+ memset(errbuf, 0, sizeof(errbuf));
+ if ((kd = kvm_openfiles(kernel, kmemf, NULL, O_RDONLY, errbuf)) == NULL)
+ errx(1, "can't open kvm: %s", errbuf);
+
+ if (kvm_nlist(kd, nl) < 0 || nl[0].n_type == 0)
+ errx(1, "%s: SLIP symbols not in namelist",
+ kernel == NULL ? _PATH_UNIX : kernel);
+
intpr();
exit(0);
}
@@ -122,12 +151,12 @@ main(argc, argv)
#define V(offset) ((line % 20)? sc->offset - osc->offset : sc->offset)
#define AMT (sizeof(*sc) - 2 * sizeof(sc->sc_comp.tstate))
+void
usage()
{
- static char umsg[] =
- "usage: slstats [-i interval] [-v] [unit] [system] [core]\n";
- fprintf(stderr, umsg);
+ fprintf(stderr, "usage: %s [-M core] [-N system] [-i interval] %s",
+ __progname, "[-v] [unit]\n");
exit(1);
}
@@ -139,13 +168,13 @@ u_char signalled; /* set if alarm goes off "early" */
* collected over that interval. Assumes that interval is non-zero.
* First line printed at top of screen is always cumulative.
*/
+void
intpr()
{
register int line = 0;
int oldmask;
- void catchalarm();
struct sl_softc *sc, *osc;
- off_t addr;
+ u_long addr;
addr = nl[N_SOFTC].n_value + unit * sizeof(struct sl_softc);
sc = (struct sl_softc *)malloc(AMT);
@@ -153,9 +182,10 @@ intpr()
bzero((char *)osc, AMT);
while (1) {
- if (kread(addr, (char *)sc, AMT) < 0)
- perror("kmem read");
- (void)signal(SIGALRM, catchalarm);
+ if (kvm_read(kd, addr, (char *)sc, AMT) != AMT)
+ errx(1, "kvm_read: %s", kvm_geterr(kd));
+
+ (void)signal(SIGALRM, (void (*)())catchalarm);
signalled = 0;
(void)alarm(interval);
@@ -217,52 +247,3 @@ catchalarm()
{
signalled = 1;
}
-
-#include <kvm.h>
-#include <fcntl.h>
-
-kvm_t *kd;
-
-kopen(system, kmemf, errstr)
- char *system;
- char *kmemf;
- char *errstr;
-{
- if (strcmp(system, _PATH_UNIX) == 0 &&
- strcmp(kmemf, _PATH_KMEM) == 0) {
- system = 0;
- kmemf = 0;
- }
- kd = kvm_open(system, kmemf, NULL, O_RDONLY, "slstats");
- if (kd == NULL)
- return -1;
- return 0;
-}
-
-int
-knlist(system, nl, errstr)
- char *system;
- struct nlist *nl;
- char *errstr;
-{
- if (kd == 0)
- /* kopen() must be called first */
- abort();
-
- if (kvm_nlist(kd, nl) < 0 || nl[0].n_type == 0) {
- fprintf(stderr, "%s: %s: no namelist\n", errstr, system);
- return -1;
- }
- return 0;
-}
-
-int
-kread(addr, buf, size)
- off_t addr;
- char *buf;
- int size;
-{
- if (kvm_read(kd, (u_long)addr, buf, size) != size)
- return -1;
- return 0;
-}