summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1998-08-05 13:54:07 +0000
committerphk <phk@FreeBSD.org>1998-08-05 13:54:07 +0000
commit9a6ddd8b9fe2ccd695ef9bc35cf1315614d89e48 (patch)
treeb6c4aedc57f383e0aa5d823eff467a93feda9b55 /usr.bin
parent8d4f23abe9b1dbc458a3fa5f64f1fac4f9a42fe2 (diff)
downloadFreeBSD-src-9a6ddd8b9fe2ccd695ef9bc35cf1315614d89e48.zip
FreeBSD-src-9a6ddd8b9fe2ccd695ef9bc35cf1315614d89e48.tar.gz
Don't open /dev/mem until we need it, most cases we don't.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/netstat/main.c51
1 files changed, 25 insertions, 26 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index 30a8927..fd54b12 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -42,7 +42,7 @@ char const copyright[] =
static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 3/1/94";
#endif
static const char rcsid[] =
- "$Id: main.c,v 1.19 1997/07/29 06:51:40 charnier Exp $";
+ "$Id: main.c,v 1.20 1998/05/15 20:19:16 wollman Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -210,6 +210,7 @@ static struct protox *name2protox __P((char *));
static struct protox *knownname __P((char *));
kvm_t *kvmd;
+char *nlistf = NULL, *memf = NULL;
int
main(argc, argv)
@@ -219,7 +220,6 @@ main(argc, argv)
register struct protoent *p;
register struct protox *tp; /* for printing cblocks & stats */
int ch;
- char *nlistf = NULL, *memf = NULL;
char buf[_POSIX2_LINE_MAX];
af = AF_UNSPEC;
@@ -343,28 +343,6 @@ main(argc, argv)
if (nlistf != NULL || memf != NULL)
setgid(getgid());
- /*
- * XXX.
- */
- kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf);
- if (kvmd != NULL) {
- if (kvm_nlist(kvmd, nl) < 0) {
- if(nlistf)
- errx(1, "%s: kvm_nlist: %s", nlistf,
- kvm_geterr(kvmd));
- else
- errx(1, "kvm_nlist: %s", kvm_geterr(kvmd));
- }
-
- if (nl[0].n_type == 0) {
- if(nlistf)
- errx(1, "%s: no namelist", nlistf);
- else
- errx(1, "no namelist");
- }
- } else {
- errx(1, "%s", buf);
- }
if (mflag) {
mbpr();
exit(0);
@@ -484,8 +462,29 @@ kread(addr, buf, size)
int size;
{
if (kvmd == 0) {
- warnx("KVM is not open");
- return -1;
+ /*
+ * XXX.
+ */
+ kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf);
+ if (kvmd != NULL) {
+ if (kvm_nlist(kvmd, nl) < 0) {
+ if(nlistf)
+ errx(1, "%s: kvm_nlist: %s", nlistf,
+ kvm_geterr(kvmd));
+ else
+ errx(1, "kvm_nlist: %s", kvm_geterr(kvmd));
+ }
+
+ if (nl[0].n_type == 0) {
+ if(nlistf)
+ errx(1, "%s: no namelist", nlistf);
+ else
+ errx(1, "no namelist");
+ }
+ } else {
+ warnx("kvm not available");
+ return(-1);
+ }
}
if (kvm_read(kvmd, addr, buf, size) != size) {
warnx("%s", kvm_geterr(kvmd));
OpenPOWER on IntegriCloud