fix problem with losing /vmunix in the middle, a bit of lint cleanup
authorJim Bloom <bloom@ucbvax.Berkeley.EDU>
Thu, 12 Dec 1985 08:08:30 +0000 (00:08 -0800)
committerJim Bloom <bloom@ucbvax.Berkeley.EDU>
Thu, 12 Dec 1985 08:08:30 +0000 (00:08 -0800)
SCCS-vsn: usr.bin/systat/cmds.c 5.4
SCCS-vsn: usr.bin/systat/disks.c 5.2
SCCS-vsn: usr.bin/systat/iostat.c 5.2
SCCS-vsn: usr.bin/systat/mbufs.c 5.2
SCCS-vsn: usr.bin/systat/netcmds.c 5.2
SCCS-vsn: usr.bin/systat/netstat.c 5.2
SCCS-vsn: usr.bin/systat/pigs.c 5.4
SCCS-vsn: usr.bin/systat/swap.c 5.2
SCCS-vsn: usr.bin/systat/vmstat.c 5.4

usr/src/usr.bin/systat/cmds.c
usr/src/usr.bin/systat/disks.c
usr/src/usr.bin/systat/iostat.c
usr/src/usr.bin/systat/mbufs.c
usr/src/usr.bin/systat/netcmds.c
usr/src/usr.bin/systat/netstat.c
usr/src/usr.bin/systat/pigs.c
usr/src/usr.bin/systat/swap.c
usr/src/usr.bin/systat/vmstat.c

index dd0a1ab..2b0e498 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cmds.c     5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmds.c     5.4 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -21,7 +21,6 @@ command(cmd)
         register char *cp;
         register struct cmdtab *p;
        int interval, omask;
         register char *cp;
         register struct cmdtab *p;
        int interval, omask;
-        char *arg;
        extern (*sigtstpdfl)();
 
        omask = sigblock(sigmask(SIGALRM));
        extern (*sigtstpdfl)();
 
        omask = sigblock(sigmask(SIGALRM));
@@ -96,11 +95,13 @@ command(cmd)
                        }
                        p = curcmd;
                }
                        }
                        p = curcmd;
                }
-                curcmd = p;
                if ((p->c_flags & CF_INIT) == 0) {
                if ((p->c_flags & CF_INIT) == 0) {
-                       (*p->c_init)();
-                       p->c_flags |= CF_INIT;
+                       if ((*p->c_init)())
+                               p->c_flags |= CF_INIT;
+                       else
+                               goto done;
                }
                }
+                curcmd = p;
                labels();
                 display();
                 status();
                labels();
                 display();
                 status();
index 9efad27..d043dac 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)disks.c    5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)disks.c    5.2 (Berkeley) %G%";
 #endif not lint
 
 #include "systat.h"
 #endif not lint
 
 #include "systat.h"
@@ -38,17 +38,16 @@ dkinit()
        static char buf[1024];
 
        if (once)
        static char buf[1024];
 
        if (once)
-               return;
-       once = 1;
+               return(1);
        nlist("/vmunix", nlst);
        if (nlst[X_DK_NDRIVE].n_value == 0) {
                error("dk_ndrive undefined in kernel");
        nlist("/vmunix", nlst);
        if (nlst[X_DK_NDRIVE].n_value == 0) {
                error("dk_ndrive undefined in kernel");
-               return;
+               return(0);
        }
        dk_ndrive = getw(nlst[X_DK_NDRIVE].n_value);
        if (dk_ndrive <= 0) {
                error("dk_ndrive=%d according to /vmunix", dk_ndrive);
        }
        dk_ndrive = getw(nlst[X_DK_NDRIVE].n_value);
        if (dk_ndrive <= 0) {
                error("dk_ndrive=%d according to /vmunix", dk_ndrive);
-               return;
+               return(0);
        }
        dk_mspw = (float *)calloc(dk_ndrive, sizeof (float));
        lseek(kmem, nlst[X_DK_MSPW].n_value, L_SET);
        }
        dk_mspw = (float *)calloc(dk_ndrive, sizeof (float));
        lseek(kmem, nlst[X_DK_MSPW].n_value, L_SET);
@@ -62,7 +61,14 @@ dkinit()
                if (dk_mspw[i] != 0.0)
                        dk_select[i] = 1;
        }
                if (dk_mspw[i] != 0.0)
                        dk_select[i] = 1;
        }
-       read_names();
+       if (! read_names()) {
+               free(dr_name);
+               free(dk_select);
+               free(dk_mspw);
+               return(0);
+       }
+       once = 1;
+       return(1);
 }
 
 dkcmd(cmd, args)
 }
 
 dkcmd(cmd, args)
@@ -98,7 +104,6 @@ dkcmd(cmd, args)
 
 read_names()
 {
 
 read_names()
 {
-       static int once = 0;
        struct mba_device mdev;
        struct mba_driver mdrv;
        short two_char;
        struct mba_device mdev;
        struct mba_driver mdrv;
        short two_char;
@@ -112,7 +117,7 @@ read_names()
        up = (struct uba_device *)nlst[X_UBDINIT].n_value;
        if (mp == 0 && up == 0) {
                error("Disk init info not in namelist\n");
        up = (struct uba_device *)nlst[X_UBDINIT].n_value;
        if (mp == 0 && up == 0) {
                error("Disk init info not in namelist\n");
-               return;
+               return(0);
        }
        if (mp) for (;;) {
                steal(mp++, mdev);
        }
        if (mp) for (;;) {
                steal(mp++, mdev);
@@ -136,6 +141,7 @@ read_names()
                sprintf(dr_name[udev.ui_dk], "%c%c%d",
                    cp[0], cp[1], udev.ui_unit);
        }
                sprintf(dr_name[udev.ui_dk], "%c%c%d",
                    cp[0], cp[1], udev.ui_unit);
        }
+       return(1);
 }
 #endif
 
 }
 #endif
 
@@ -154,7 +160,7 @@ read_names()
        mp = (struct mb_device *)nlst[X_MBDINIT].n_value;
        if (mp == 0) {
                error("Disk init info not in namelist\n");
        mp = (struct mb_device *)nlst[X_MBDINIT].n_value;
        if (mp == 0) {
                error("Disk init info not in namelist\n");
-               return;
+               return(0);
        }
        for (;;) {
                steal(mp++, mdev);
        }
        for (;;) {
                steal(mp++, mdev);
@@ -167,6 +173,7 @@ read_names()
                sprintf(dr_name[mdev.md_dk], "%c%c%d",
                    cp[0], cp[1], mdev.md_unit);
        }
                sprintf(dr_name[mdev.md_dk], "%c%c%d",
                    cp[0], cp[1], mdev.md_unit);
        }
+       return(1);
 }
 #endif
 
 }
 #endif
 
index 47413cc..bca772d 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)iostat.c   5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)iostat.c   5.2 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -70,16 +70,16 @@ static  int msps = 0;                   /* default ms/seek shown */
 
 initiostat()
 {
 
 initiostat()
 {
-        register  i;
 
         if (nlst[X_DK_BUSY].n_type == 0) {
                 nlist("/vmunix", nlst);
                 if (nlst[X_DK_BUSY].n_type == 0) {
                         error("Disk init information isn't in namelist");
 
         if (nlst[X_DK_BUSY].n_type == 0) {
                 nlist("/vmunix", nlst);
                 if (nlst[X_DK_BUSY].n_type == 0) {
                         error("Disk init information isn't in namelist");
-                        return;
+                        return(0);
                 }
         }
                 }
         }
-       dkinit();
+       if (! dkinit())
+               return(0);
        if (dk_ndrive) {
 #define        allocate(e, t) \
     s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
        if (dk_ndrive) {
 #define        allocate(e, t) \
     s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
@@ -90,6 +90,7 @@ initiostat()
                allocate(dk_xfer, long);
 #undef allocate
        }
                allocate(dk_xfer, long);
 #undef allocate
        }
+       return(1);
 }
 
 fetchiostat()
 }
 
 fetchiostat()
@@ -250,7 +251,6 @@ static
 stats(row, col, dn)
         int row, dn;
 {
 stats(row, col, dn)
         int row, dn;
 {
-        register i;
         double atime, words, xtime, itime;
 
         atime = s.dk_time[dn];
         double atime, words, xtime, itime;
 
         atime = s.dk_time[dn];
@@ -323,7 +323,6 @@ histogram(val, colwidth, scale)
 cmdiostat(cmd, args)
         char *cmd, *args;
 {
 cmdiostat(cmd, args)
         char *cmd, *args;
 {
-        int i;
 
         if (prefix(cmd, "msps"))
                 msps = !msps;
 
         if (prefix(cmd, "msps"))
                 msps = !msps;
index 6838cc6..0ebda6a 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)mbufs.c    5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)mbufs.c    5.2 (Berkeley) %G%";
 #endif not lint
 
 #include "systat.h"
 #endif not lint
 
 #include "systat.h"
@@ -107,11 +107,12 @@ initmbufs()
                nlist("/vmunix", nlst);
                if (nlst[X_MBSTAT].n_type == 0) {
                        error("namelist on /vmunix failed");
                nlist("/vmunix", nlst);
                if (nlst[X_MBSTAT].n_type == 0) {
                        error("namelist on /vmunix failed");
-                       return;
+                       return(0);
                }
        }
        if (mb == 0)
                mb = (struct mbstat *)calloc(1, sizeof (*mb));
                }
        }
        if (mb == 0)
                mb = (struct mbstat *)calloc(1, sizeof (*mb));
+       return(1);
 }
 
 fetchmbufs()
 }
 
 fetchmbufs()
index 7e96ec9..c577954 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)netcmds.c  5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)netcmds.c  5.2 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -70,7 +70,6 @@ changeitems(args, onoff)
        int onoff;
 {
        register char *cp;
        int onoff;
 {
        register char *cp;
-       register int i;
        struct servent *sp;
        struct hostent *hp;
        struct in_addr in;
        struct servent *sp;
        struct hostent *hp;
        struct in_addr in;
@@ -145,7 +144,7 @@ selectport(port, onoff)
        long port;
        int onoff;
 {
        long port;
        int onoff;
 {
-       register struct pitem *p, *open;
+       register struct pitem *p;
 
        if (port == -1) {
                if (ports == 0)
 
        if (port == -1) {
                if (ports == 0)
@@ -154,7 +153,6 @@ selectport(port, onoff)
                nports = 0;
                return (1);
        }
                nports = 0;
                return (1);
        }
-       open = 0;
        for (p = ports; p < ports+nports; p++)
                if (p->port == port) {
                        p->onoff = onoff;
        for (p = ports; p < ports+nports; p++)
                if (p->port == port) {
                        p->onoff = onoff;
index ec260d7..2cf5a09 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)netstat.c  5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)netstat.c  5.2 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -77,7 +77,7 @@ static        char *inetname();
 closenetstat(w)
         WINDOW *w;
 {
 closenetstat(w)
         WINDOW *w;
 {
-       register struct netinfo *p, *q;
+       register struct netinfo *p;
 
        endhostent();
        endnetent();
 
        endhostent();
        endnetent();
@@ -105,15 +105,15 @@ static struct nlist nlst[] = {
 
 initnetstat()
 {
 
 initnetstat()
 {
-        register  i;
 
        nlist("/vmunix", nlst);
        if (nlst[X_TCB].n_value == 0) {
                error("No symbols in namelist");
 
        nlist("/vmunix", nlst);
        if (nlst[X_TCB].n_value == 0) {
                error("No symbols in namelist");
-               return;
+               return(0);
        }
        netcb.ni_forw = netcb.ni_prev = (struct netinfo *)&netcb;
        protos = TCP|UDP;
        }
        netcb.ni_forw = netcb.ni_prev = (struct netinfo *)&netcb;
        protos = TCP|UDP;
+       return(1);
 }
 
 fetchnetstat()
 }
 
 fetchnetstat()
index df4450f..5ae8f63 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)pigs.c     5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)pigs.c     5.4 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -166,7 +166,7 @@ initpigs()
                nlist("/vmunix", nlst);
                if (nlst[X_PROC].n_type == 0) {
                        error("namelist on /vmunix failed");
                nlist("/vmunix", nlst);
                if (nlst[X_PROC].n_type == 0) {
                        error("namelist on /vmunix failed");
-                       return;
+                       return(0);
                }
        }
         if (procp == NULL) {
                }
        }
         if (procp == NULL) {
@@ -176,13 +176,14 @@ initpigs()
        if (kprocp == NULL)
                 kprocp = (struct proc *)calloc(nproc, sizeof (struct proc));
         if (usrpt != NULL)
        if (kprocp == NULL)
                 kprocp = (struct proc *)calloc(nproc, sizeof (struct proc));
         if (usrpt != NULL)
-               return;
+               return(1);
        usrpt = (struct pte *)nlst[X_USRPT].n_value;
        Usrptma = (struct pte *)nlst[X_USRPTMAP].n_value;
        if (pt == NULL)
                pt = (struct p_times *)calloc(nproc, sizeof (struct p_times));
        lseek(kmem, (long)nlst[X_CPTIME].n_value, L_SET);
        read(kmem, stime, sizeof stime);
        usrpt = (struct pte *)nlst[X_USRPT].n_value;
        Usrptma = (struct pte *)nlst[X_USRPTMAP].n_value;
        if (pt == NULL)
                pt = (struct p_times *)calloc(nproc, sizeof (struct p_times));
        lseek(kmem, (long)nlst[X_CPTIME].n_value, L_SET);
        read(kmem, stime, sizeof stime);
+       return(1);
 }
 
 fetchpigs()
 }
 
 fetchpigs()
@@ -192,7 +193,6 @@ fetchpigs()
         register float time;
         register struct proc *pp;
        long ctime[CPUSTATES];
         register float time;
         register struct proc *pp;
        long ctime[CPUSTATES];
-       char buf[25];
        double t;
 
        if (nlst[X_PROC].n_type == 0)
        double t;
 
        if (nlst[X_PROC].n_type == 0)
index 58f8a22..69a0716 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)swap.c     5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)swap.c     5.2 (Berkeley) %G%";
 #endif not lint
 
 #include "systat.h"
 #endif not lint
 
 #include "systat.h"
@@ -201,7 +201,7 @@ initswap()
                nlist("/vmunix", nlst);
                if (nlst[X_PROC].n_type == 0) {
                        error("namelist on /vmunix failed");
                nlist("/vmunix", nlst);
                if (nlst[X_PROC].n_type == 0) {
                        error("namelist on /vmunix failed");
-                       return;
+                       return(0);
                }
        }
         if (nswdev == 0) {
                }
        }
         if (nswdev == 0) {
@@ -224,11 +224,12 @@ initswap()
        if (kprocp == NULL)
                 kprocp = (struct proc *)calloc(nproc, sizeof (struct proc));
         if (usrpt != NULL)
        if (kprocp == NULL)
                 kprocp = (struct proc *)calloc(nproc, sizeof (struct proc));
         if (usrpt != NULL)
-                return;
+                return(1);
        usrpt = (struct pte *)nlst[X_USRPT].n_value;
        Usrptma = (struct pte *)nlst[X_USRPTMAP].n_value;
        if (pt == NULL)
                pt = (struct p_times *)malloc(nproc * sizeof (struct p_times));
        usrpt = (struct pte *)nlst[X_USRPT].n_value;
        Usrptma = (struct pte *)nlst[X_USRPTMAP].n_value;
        if (pt == NULL)
                pt = (struct p_times *)malloc(nproc * sizeof (struct p_times));
+       return(1);
 }
 
 fetchswap()
 }
 
 fetchswap()
@@ -266,7 +267,6 @@ char        *devnames[] =
 
 labelswap()
 {
 
 labelswap()
 {
-       register int i, j;
        register int row;
 
        if (nswdev == 0) {
        register int row;
 
        if (nswdev == 0) {
index 4cee715..cc7e3e2 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)vmstat.c   5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)vmstat.c   5.4 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -157,17 +157,19 @@ initkre()
 {
        char *intrnamebuf, *cp;
        int i;
 {
        char *intrnamebuf, *cp;
        int i;
+       static int once = 0;
 
        if (name[0].n_type == 0) {
                nlist("/vmunix",name);
                if (name[0].n_type == 0) {
                        error("No namelist");
 
        if (name[0].n_type == 0) {
                nlist("/vmunix",name);
                if (name[0].n_type == 0) {
                        error("No namelist");
-                       return;
+                       return(0);
                }
        }
        hertz = phz ? phz : hz;
                }
        }
        hertz = phz ? phz : hz;
-       dkinit();
-       if (dk_ndrive) {
+       if (! dkinit())
+               return(0);
+       if (dk_ndrive && !once) {
 #define        allocate(e, t) \
     s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
     s1./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
 #define        allocate(e, t) \
     s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
     s1./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
@@ -177,6 +179,7 @@ initkre()
                allocate(dk_wds, long);
                allocate(dk_seek, long);
                allocate(dk_xfer, long);
                allocate(dk_wds, long);
                allocate(dk_seek, long);
                allocate(dk_xfer, long);
+               once = 1;
 #undef allocate
        }
        if (nintr == 0) {
 #undef allocate
        }
        if (nintr == 0) {
@@ -188,7 +191,14 @@ initkre()
                        name[X_INTRNAMES].n_value);
                if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) {
                        error("Out of memory\n");
                        name[X_INTRNAMES].n_value);
                if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) {
                        error("Out of memory\n");
-                       return;
+                       if (intrnamebuf)
+                               free(intrnamebuf);
+                       if (intrname)
+                               free(intrname);
+                       if (intrloc)
+                               free(intrloc);
+                       nintr = 0;
+                       return(0);
                }
                lseek(kmem, (long)name[X_INTRNAMES].n_value, L_SET);
                read(kmem, intrnamebuf, name[X_EINTRNAMES].n_value -
                }
                lseek(kmem, (long)name[X_INTRNAMES].n_value, L_SET);
                read(kmem, intrnamebuf, name[X_EINTRNAMES].n_value -
@@ -205,6 +215,7 @@ initkre()
        }
        getinfo(&s2, RUN);
        copyinfo(&s2, &s1);
        }
        getinfo(&s2, RUN);
        copyinfo(&s2, &s1);
+       return(1);
 }
 
 fetchkre()
 }
 
 fetchkre()
@@ -297,7 +308,7 @@ static      char cpuorder[CPUSTATES] = { CP_SYS, CP_USER, CP_NICE, CP_IDLE };
 showkre()
 {
        float f1, f2;
 showkre()
 {
        float f1, f2;
-       int psiz, interv, hits, inttotal;
+       int psiz, inttotal;
        int i, l, c;
 
        for (i = 0; i < dk_ndrive; i++) {
        int i, l, c;
 
        for (i = 0; i < dk_ndrive; i++) {
@@ -475,7 +486,6 @@ showkre()
 cmdkre(cmd, args)
        char *cmd, *args;
 {
 cmdkre(cmd, args)
        char *cmd, *args;
 {
-       static enum state oldstate;
 
        if (prefix(cmd, "run")) {
                copyinfo(&s2, &s1);
 
        if (prefix(cmd, "run")) {
                copyinfo(&s2, &s1);
@@ -624,7 +634,7 @@ allocinfo(s)
 
        s->intrcnt = (long *) malloc(nintr * sizeof(long));
        if (s->intrcnt == NULL) {
 
        s->intrcnt = (long *) malloc(nintr * sizeof(long));
        if (s->intrcnt == NULL) {
-               fprintf(stderr, "vsta: out of memory\n");
+               fprintf(stderr, "systat: out of memory\n");
                exit(2);
        }
 }
                exit(2);
        }
 }
@@ -634,7 +644,7 @@ copyinfo(from, to)
        register struct Info *from, *to;
 {
        long *time, *wds, *seek, *xfer;
        register struct Info *from, *to;
 {
        long *time, *wds, *seek, *xfer;
-       int *intrcnt;
+       long *intrcnt;
 
        time = to->dk_time; wds = to->dk_wds; seek = to->dk_seek;
        xfer = to->dk_xfer; intrcnt = to->intrcnt;
 
        time = to->dk_time; wds = to->dk_wds; seek = to->dk_seek;
        xfer = to->dk_xfer; intrcnt = to->intrcnt;