xref: /netbsd-src/usr.bin/systat/cmdtab.c (revision 4472dbe5e3bd91ef2540bada7a7ca7384627ff9b)
1 /*	$NetBSD: cmdtab.c,v 1.15 2000/04/11 01:18:35 jwise Exp $	*/
2 
3 /*-
4  * Copyright (c) 1980, 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)cmdtab.c	8.1 (Berkeley) 6/6/93";
40 #endif
41 __RCSID("$NetBSD: cmdtab.c,v 1.15 2000/04/11 01:18:35 jwise Exp $");
42 #endif /* not lint */
43 
44 #include "systat.h"
45 #include "extern.h"
46 
47 /*
48  * NOTE: if one command is a substring of another, the shorter string
49  * MUST come first, or it will be shadowed by the longer
50  */
51 
52 struct	command global_commands[] = {
53 	{ "help",	global_help,		"show help"},
54 	{ "interval",	global_interval,	"set update interval"},
55 	{ "load",	global_load,		"show system load averages"},
56 	{ "quit",	global_quit,		"exit systat"},
57 	{ "start",	global_interval,	"restart updating display"},
58 	{ "stop",	global_stop,		"stop updating display"},
59 	{ 0 }
60 };
61 
62 struct command	iostat_commands[] = {
63 	{ "bars",	iostat_bars,	"show io stats as a bar graph"},
64 	{ "numbers",	iostat_numbers,	"show io stats numerically"},
65 	{ "secs",	iostat_secs,	"include time statistics"},
66 	/* from disks.c */
67 	{ "add",	disks_add,	"add a disk to displayed disks"},
68 	{ "show",	disks_add,	"add a disk to displayed disks"},
69 	{ "delete",	disks_delete,	"remove a disk from displayed disks"},
70 	{ "ignore",	disks_delete,	"remove a disk from displayed disks"},
71 	{ "drives",	disks_drives,	"list all disks"},
72 	{ 0 }
73 };
74 
75 struct command netstat_commands[] = {
76 	{ "all",	netstat_all,	 "include server sockets"},
77 	{ "display",	netstat_display, "show specified hosts or ports"},
78 	{ "ignore",	netstat_ignore,	 "hide specified hosts or ports"},
79 	{ "names",	netstat_names,	 "show names instead of addresses"},
80 	{ "numbers",	netstat_numbers, "show addresses instead of names"},
81 	{ "reset",	netstat_reset,	 "return to default display"},
82 	{ "show",	netstat_show,	"show current display/ignore settings"},
83 	{ "tcp",	netstat_tcp,	 "show only tcp connections"},
84 	{ "udp",	netstat_udp,	 "show only udp connections"},
85 	{ 0 }
86 };
87 
88 struct command ps_commands[] = {
89 	{ "user",	ps_user,	"limit displayed processes to a user"},
90 	{ 0 }
91 };
92 
93 struct command	vmstat_commands[] = {
94 	{ "boot",	vmstat_boot,	"show total vm stats since boot"},
95 	{ "run",	vmstat_run,	"show running total vm stats"},
96 	{ "time",	vmstat_time,	"show vm stats for each sample time"},
97 	{ "zero",	vmstat_zero,	"re-zero running totals"},
98 	/* from disks.c */
99 	{ "add",	disks_add,	"add a disk to displayed disks"},
100 	{ "show",	disks_add,	"add a disk to displayed disks"},
101 	{ "delete",	disks_delete,	"remove a disk from displayed disks"},
102 	{ "ignore",	disks_delete,	"remove a disk from displayed disks"},
103 	{ "drives",	disks_drives,	"list all disks"},
104 	{ 0 }
105 };
106 
107 struct mode modes[] = {
108 	/* "pigs" is the default, it must be first. */
109 	{ "pigs",	showpigs,	fetchpigs,	labelpigs,
110 	  initpigs,	openpigs,	closepigs,	0,
111 	  CF_LOADAV },
112 	{ "bufcache",	showbufcache,	fetchbufcache,	labelbufcache,
113 	  initbufcache,	openbufcache,	closebufcache,	0,
114 	  CF_LOADAV },
115 	{ "inet.icmp",	showicmp,	fetchicmp,	labelicmp,
116 	  initicmp,	openicmp,	closeicmp,	0,
117 	  CF_LOADAV },
118 	{ "inet.ip",	showip,		fetchip,	labelip,
119 	  initip,	openip,		closeip,	0,
120 	  CF_LOADAV },
121 	{ "inet.tcp",	showtcp,	fetchtcp,	labeltcp,
122 	  inittcp,	opentcp,	closetcp,	0,
123 	  CF_LOADAV },
124 	{ "inet.tcpsyn",showtcpsyn,	fetchtcp,	labeltcpsyn,
125 	  inittcp,	opentcp,	closetcp,	0,
126 	  CF_LOADAV },
127 #ifdef INET6
128 	{ "inet6.ip6",	showip6,	fetchip6,	labelip6,
129 	  initip6,	openip6,	closeip6,	0,
130 	  CF_LOADAV },
131 #endif
132 #ifdef IPSEC
133 	{ "ipsec",	showipsec,	fetchipsec,	labelipsec,
134 	  initipsec,	openipsec,	closeipsec,	0,
135 	  CF_LOADAV },
136 #endif
137 	{ "iostat",	showiostat,	fetchiostat,	labeliostat,
138 	  initiostat,	openiostat,	closeiostat,	iostat_commands,
139 	  CF_LOADAV },
140 	{ "mbufs",	showmbufs,	fetchmbufs,	labelmbufs,
141 	  initmbufs,	openmbufs,	closembufs,	0,
142 	  CF_LOADAV },
143 	{ "netstat",	shownetstat,	fetchnetstat,	labelnetstat,
144 	  initnetstat,	opennetstat,	closenetstat,	netstat_commands,
145 	  CF_LOADAV },
146 	{ "ps",		showps,		fetchpigs,	labelps,
147 	  initpigs,	openpigs,	closepigs,	ps_commands,
148 	  CF_LOADAV },
149 	{ "swap",	showswap,	fetchswap,	labelswap,
150 	  initswap,	openswap,	closeswap,	0,
151 	  CF_LOADAV },
152 	{ "vmstat",	showkre,	fetchkre,	labelkre,
153 	  initkre,	openkre,	closekre,	vmstat_commands,
154 	  0 },
155 	{ 0 }
156 };
157 struct  mode *curmode = &modes[0];
158