Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/systat Two things:



details:   https://anonhg.NetBSD.org/src/rev/301fe08877b6
branches:  trunk
changeset: 479717:301fe08877b6
user:      jwise <jwise%NetBSD.org@localhost>
date:      Mon Dec 20 03:45:01 1999 +0000

description:
Two things:

  1.) fix a bug which caused coredumps when starting with no mode arguments
  2.) move to table-lookup for mode-specific command parsing as well.
      all command matching is now table-driven.

diffstat:

 usr.bin/systat/cmds.c    |  16 ++++++--
 usr.bin/systat/cmdtab.c  |  76 +++++++++++++++++++++++++++++---------
 usr.bin/systat/disks.c   |  45 +++++++++++-----------
 usr.bin/systat/extern.h  |  26 ++++++++++---
 usr.bin/systat/iostat.c  |  41 +++++++++++++-------
 usr.bin/systat/main.c    |   9 ++--
 usr.bin/systat/netcmds.c |  95 ++++++++++++++++++++++++++++-------------------
 usr.bin/systat/netstat.c |  81 +++++++++++++++++++++++++---------------
 usr.bin/systat/systat.h  |   4 +-
 usr.bin/systat/vmstat.c  |  54 ++++++++++++++------------
 10 files changed, 282 insertions(+), 165 deletions(-)

diffs (truncated from 718 to 300 lines):

diff -r 349cbdecaacb -r 301fe08877b6 usr.bin/systat/cmds.c
--- a/usr.bin/systat/cmds.c     Mon Dec 20 03:37:06 1999 +0000
+++ b/usr.bin/systat/cmds.c     Mon Dec 20 03:45:01 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.13 1999/12/16 06:16:16 jwise Exp $  */
+/*     $NetBSD: cmds.c,v 1.14 1999/12/20 03:45:01 jwise Exp $  */
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c     8.2 (Berkeley) 4/29/95";
 #endif
-__RCSID("$NetBSD: cmds.c,v 1.13 1999/12/16 06:16:16 jwise Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.14 1999/12/20 03:45:01 jwise Exp $");
 #endif /* not lint */
 
 #include <stdlib.h>
@@ -72,6 +72,15 @@
        for (; *cp && isspace((unsigned char)*cp); cp++)
                ;
 
+       if (curmode->c_commands) {
+               for (c = curmode->c_commands; c->c_name; c++) {
+                       if (strcmp(cmd, c->c_name) == 0) {
+                               (c->c_cmd)(cp);
+                               goto done;
+                       }
+               }
+       }
+
        for (c = global_commands; c->c_name; c++) {
                if (strcmp(cmd, c->c_name) == 0) {
                        (c->c_cmd)(cp);
@@ -91,8 +100,7 @@
                }
        }
 
-       if (curmode->c_cmd == 0 || !(*curmode->c_cmd)(cmd, cp))
-               error("%s: Unknown command.", cmd);
+       error("%s: Unknown command.", cmd);
 done:
        sigprocmask(SIG_UNBLOCK, &set, NULL);
 }
diff -r 349cbdecaacb -r 301fe08877b6 usr.bin/systat/cmdtab.c
--- a/usr.bin/systat/cmdtab.c   Mon Dec 20 03:37:06 1999 +0000
+++ b/usr.bin/systat/cmdtab.c   Mon Dec 20 03:45:01 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmdtab.c,v 1.10 1999/12/16 06:16:16 jwise Exp $        */
+/*     $NetBSD: cmdtab.c,v 1.11 1999/12/20 03:45:02 jwise Exp $        */
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -38,13 +38,65 @@
 #if 0
 static char sccsid[] = "@(#)cmdtab.c   8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: cmdtab.c,v 1.10 1999/12/16 06:16:16 jwise Exp $");
+__RCSID("$NetBSD: cmdtab.c,v 1.11 1999/12/20 03:45:02 jwise Exp $");
 #endif /* not lint */
 
 #include "systat.h"
 #include "extern.h"
 
-struct mode modes[] = {
+struct command global_commands[] = {
+       { "help",       global_help,            "show help"},
+       { "interval",   global_interval,        "set update interval"},
+       { "load",       global_load,            "show system load averages"},
+       { "quit",       global_quit,            "exit systat"},
+       /* until prefix matching works, handle the same special case */
+       { "q",          global_quit,            "exit systat"},
+       { "start",      global_interval,        "restart updating display"},
+       { "stop",       global_stop,            "stop updating display"},
+       { 0 }
+};
+
+struct command iostat_commands[] = {
+       { "bars",       iostat_bars,    "show io stats as a bar graph"},
+       { "numbers",    iostat_numbers, "show io stats numerically"},
+       { "secs",       iostat_secs,    "include time statistics"},
+       /* from disks.c */
+       { "add",        disks_add,      "add a disk to displayed disks"},
+       { "show",       disks_add,      "add a disk to displayed disks"},
+       { "delete",     disks_delete,   "remove a disk from displayed disks"},
+       { "ignore",     disks_delete,   "remove a disk from displayed disks"},
+       { "drives",     disks_drives,   "list all disks"},
+       { 0 }
+};
+
+struct command netstat_commands[] = {
+       { "all",        netstat_all,     "include server sockets"},
+       { "display",    netstat_display, "show specified hosts or ports"},
+       { "ignore",     netstat_ignore,  "hide specified hosts or ports"},
+       { "names",      netstat_names,   "show names instead of addresses"},
+       { "numbers",    netstat_numbers, "show addresses instead of names"},
+       { "reset",      netstat_reset,   "return to default display"},
+       { "show",       netstat_show,   "show current display/ignore settings"},
+       { "tcp",        netstat_tcp,     "show only tcp connections"},
+       { "udp",        netstat_udp,     "show only udp connections"},
+       { 0 }
+};
+
+struct command vmstat_commands[] = {
+       { "boot",       vmstat_boot,    "show total vm stats since boot"},
+       { "run",        vmstat_run,     "show running total vm stats"},
+       { "time",       vmstat_time,    "show vm stats for each sample time"},
+       { "zero",       vmstat_zero,    "re-zero running totals"},
+       /* from disks.c */
+       { "add",        disks_add,      "add a disk to displayed disks"},
+       { "show",       disks_add,      "add a disk to displayed disks"},
+       { "delete",     disks_delete,   "remove a disk from displayed disks"},
+       { "ignore",     disks_delete,   "remove a disk from displayed disks"},
+       { "drives",     disks_drives,   "list all disks"},
+       { 0 }
+};
+
+struct mode modes[] = {
        /* "pigs" is the default, it must be first. */
        { "pigs",       showpigs,       fetchpigs,      labelpigs,
          initpigs,     openpigs,       closepigs,      0,
@@ -65,13 +117,13 @@
          inittcp,      opentcp,        closetcp,       0,
          CF_LOADAV },
        { "iostat",     showiostat,     fetchiostat,    labeliostat,
-         initiostat,   openiostat,     closeiostat,    cmdiostat,
+         initiostat,   openiostat,     closeiostat,    iostat_commands,
          CF_LOADAV },
        { "mbufs",      showmbufs,      fetchmbufs,     labelmbufs,
          initmbufs,    openmbufs,      closembufs,     0,
          CF_LOADAV },
        { "netstat",    shownetstat,    fetchnetstat,   labelnetstat,
-         initnetstat,  opennetstat,    closenetstat,   cmdnetstat,
+         initnetstat,  opennetstat,    closenetstat,   netstat_commands,
          CF_LOADAV },
        { "ps",         showps,         fetchpigs,      labelps,
          initpigs,     openpigs,       closepigs,      0,
@@ -80,20 +132,8 @@
          initswap,     openswap,       closeswap,      0,
          CF_LOADAV },
        { "vmstat",     showkre,        fetchkre,       labelkre,
-         initkre,      openkre,        closekre,       cmdkre,
+         initkre,      openkre,        closekre,       vmstat_commands,
          0 },
        { 0 }
 };
 struct  mode *curmode = &modes[0];
-
-struct command global_commands[] = {
-       { "help",       global_help,            "show help"},
-       { "interval",   global_interval,        "set update interval"},
-       { "load",       global_load,            "show system load averages"},
-       { "quit",       global_quit,            "exit systat"},
-       /* until prefix matching works, handle the same special case */
-       { "q",          global_quit,            "exit systat"},
-       { "start",      global_interval,        "restart updating display"},
-       { "stop",       global_stop,            "stop updating display"},
-       { 0 }
-};
diff -r 349cbdecaacb -r 301fe08877b6 usr.bin/systat/disks.c
--- a/usr.bin/systat/disks.c    Mon Dec 20 03:37:06 1999 +0000
+++ b/usr.bin/systat/disks.c    Mon Dec 20 03:45:01 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disks.c,v 1.8 1998/12/19 22:26:13 christos Exp $       */
+/*     $NetBSD: disks.c,v 1.9 1999/12/20 03:45:02 jwise Exp $  */
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)disks.c    8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: disks.c,v 1.8 1998/12/19 22:26:13 christos Exp $");
+__RCSID("$NetBSD: disks.c,v 1.9 1999/12/20 03:45:02 jwise Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -53,29 +53,30 @@
 
 static void dkselect __P((char *args, int truefalse, int selections[]));
 
-int
-dkcmd(cmd, args)
-       char *cmd, *args;
+void
+disks_add (args)
+       char *args;
 {
+       dkselect(args, 1, dk_select);
+}
 
-       if (prefix(cmd, "display") || prefix(cmd, "add")) {
-               dkselect(args, 1, dk_select);
-               return (1);
-       }
-       if (prefix(cmd, "ignore") || prefix(cmd, "delete")) {
-               dkselect(args, 0, dk_select);
-               return (1);
-       }
-       if (prefix(cmd, "drives")) {
-               int i;
+void
+disks_delete (args)
+       char *args;
+{
+       dkselect(args, 0, dk_select);
+}
 
-               move(CMDLINE, 0);
-               clrtoeol();
-               for (i = 0; i < dk_ndrive; i++)
-                       printw("%s ", dr_name[i]);
-               return (1);
-       }
-       return (0);
+void
+disks_drives (args)
+       char *args;
+{
+       int i;
+
+       move(CMDLINE, 0);
+       clrtoeol();
+       for (i = 0; i < dk_ndrive; i++)
+               printw("%s ", dr_name[i]);
 }
 
 static void
diff -r 349cbdecaacb -r 301fe08877b6 usr.bin/systat/extern.h
--- a/usr.bin/systat/extern.h   Mon Dec 20 03:37:06 1999 +0000
+++ b/usr.bin/systat/extern.h   Mon Dec 20 03:45:01 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.14 1999/12/16 06:16:16 jwise Exp $        */
+/*     $NetBSD: extern.h,v 1.15 1999/12/20 03:45:02 jwise Exp $        */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -74,13 +74,12 @@
 void    closepigs __P((WINDOW *));
 void    closeswap __P((WINDOW *));
 void    closetcp __P ((WINDOW *));
-int     cmdiostat __P((char *, char *));
-int     cmdkre __P((char *, char *));
-int     cmdnetstat __P((char *, char *));
 void    command __P((char *));
 void    die __P((int));
+void    disks_add __P((char *));
+void    disks_delete __P((char *));
+void    disks_drives __P((char *));
 void    display __P((int));
-int     dkcmd __P((char *, char *));
 int     dkinit __P((int, gid_t));
 void    error __P((const char *fmt, ...));
 void    fetchbufcache __P((void));
@@ -108,6 +107,9 @@
 int     initpigs __P((void));
 int     initswap __P((void));
 int     inittcp __P((void));
+void    iostat_bars __P((char *));
+void    iostat_numbers __P((char *));
+void    iostat_secs __P((char *));
 int     keyboard __P((void)) __attribute__((__noreturn__));
 ssize_t         kvm_ckread __P((void *, void *, size_t));
 void    labelbufcache __P((void));
@@ -123,7 +125,15 @@
 void    labelswap __P((void));
 void    labeltcp __P((void));
 void    labeltcpsyn __P((void));
-int     netcmd __P((char *, char *));
+void    netstat_all __P((char *));
+void    netstat_display __P((char *));
+void    netstat_ignore __P((char *));
+void    netstat_names __P((char *));
+void    netstat_numbers __P((char *));
+void    netstat_reset __P((char *));
+void    netstat_show __P((char *));
+void    netstat_tcp __P((char *));
+void    netstat_udp __P((char *));
 void    nlisterr __P((struct nlist []));
 WINDOW *openbufcache __P((void));
 WINDOW *openicmp __P((void));
@@ -151,3 +161,7 @@
 void    showtcpsyn __P((void));
 void    status __P((void));
 void    suspend __P((int));
+void    vmstat_boot __P((char *args));
+void    vmstat_run __P((char *args));
+void    vmstat_time __P((char *args));
+void    vmstat_zero __P((char *args));
diff -r 349cbdecaacb -r 301fe08877b6 usr.bin/systat/iostat.c
--- a/usr.bin/systat/iostat.c   Mon Dec 20 03:37:06 1999 +0000
+++ b/usr.bin/systat/iostat.c   Mon Dec 20 03:45:01 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iostat.c,v 1.12 1999/06/29 18:14:15 mjl Exp $  */
+/*     $NetBSD: iostat.c,v 1.13 1999/12/20 03:45:02 jwise Exp $        */
 
 /*
  * Copyright (c) 1980, 1992, 1993
@@ -38,7 +38,7 @@
 #if 0



Home | Main Index | Thread Index | Old Index