1994-05-26 05:23:31 +00:00
|
|
|
/*-
|
1997-03-11 13:00:41 +00:00
|
|
|
* Copyright (c) 1980, 1991, 1993, 1994
|
1994-05-26 05:23:31 +00:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-10-09 07:22:08 +00:00
|
|
|
static const char copyright[] =
|
1997-03-11 13:00:41 +00:00
|
|
|
"@(#) Copyright (c) 1980, 1991, 1993, 1994\n\
|
1994-05-26 05:23:31 +00:00
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-10-09 07:22:08 +00:00
|
|
|
#if 0
|
1997-03-11 13:00:41 +00:00
|
|
|
static char sccsid[] = "@(#)pstat.c 8.16 (Berkeley) 5/9/95";
|
1997-10-09 07:22:08 +00:00
|
|
|
#endif
|
|
|
|
static const char rcsid[] =
|
1999-08-28 01:35:59 +00:00
|
|
|
"$FreeBSD$";
|
1994-05-26 05:23:31 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
1999-12-29 05:07:58 +00:00
|
|
|
#define _KERNEL
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <sys/file.h>
|
1997-03-11 13:00:41 +00:00
|
|
|
#include <sys/uio.h>
|
1999-12-29 05:07:58 +00:00
|
|
|
#undef _KERNEL
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
1995-05-07 22:15:46 +00:00
|
|
|
#include <sys/ioctl_compat.h> /* XXX NTTYDISC is too well hidden */
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/conf.h>
|
1999-01-21 08:08:55 +00:00
|
|
|
#include <sys/blist.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
|
1995-10-29 09:57:50 +00:00
|
|
|
#include <sys/user.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
1996-09-29 19:25:10 +00:00
|
|
|
#include <fcntl.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <kvm.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <nlist.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static struct nlist nl[] = {
|
1999-01-22 10:36:48 +00:00
|
|
|
#define NLMANDATORYBEG 0
|
|
|
|
#define V_MOUNTLIST 0
|
1994-05-26 05:23:31 +00:00
|
|
|
{ "_mountlist" }, /* address of head of mount list. */
|
1999-01-22 10:36:48 +00:00
|
|
|
#define V_NUMV 1
|
1994-05-26 05:23:31 +00:00
|
|
|
{ "_numvnodes" },
|
1999-01-22 10:36:48 +00:00
|
|
|
#define FNL_NFILE 2
|
1994-05-26 05:23:31 +00:00
|
|
|
{"_nfiles"},
|
1999-01-22 10:36:48 +00:00
|
|
|
#define FNL_MAXFILE 3
|
1994-05-26 05:23:31 +00:00
|
|
|
{"_maxfiles"},
|
1999-01-21 08:08:55 +00:00
|
|
|
#define NLMANDATORYEND FNL_MAXFILE /* names up to here are mandatory */
|
|
|
|
#define SCONS NLMANDATORYEND + 1
|
2002-05-23 14:41:52 +00:00
|
|
|
{ "_constty" },
|
1999-01-21 08:08:55 +00:00
|
|
|
#define SPTY NLMANDATORYEND + 2
|
1994-05-26 05:23:31 +00:00
|
|
|
{ "_pt_tty" },
|
1999-01-21 08:08:55 +00:00
|
|
|
#define SNPTY NLMANDATORYEND + 3
|
1994-05-26 05:23:31 +00:00
|
|
|
{ "_npty" },
|
|
|
|
|
|
|
|
|
|
|
|
|
1994-11-03 11:41:34 +00:00
|
|
|
#ifdef __FreeBSD__
|
1999-01-22 10:36:48 +00:00
|
|
|
#define SCCONS (SNPTY+1)
|
1995-04-28 09:08:18 +00:00
|
|
|
{ "_sccons" },
|
1999-01-22 10:36:48 +00:00
|
|
|
#define NSCCONS (SNPTY+2)
|
1995-04-28 09:08:18 +00:00
|
|
|
{ "_nsccons" },
|
1999-01-22 10:36:48 +00:00
|
|
|
#define SIO (SNPTY+3)
|
1995-05-07 22:15:46 +00:00
|
|
|
{ "_sio_tty" },
|
1999-01-22 10:36:48 +00:00
|
|
|
#define NSIO (SNPTY+4)
|
1995-05-07 22:15:46 +00:00
|
|
|
{ "_nsio_tty" },
|
1999-01-22 10:36:48 +00:00
|
|
|
#define RC (SNPTY+5)
|
1995-05-07 22:15:46 +00:00
|
|
|
{ "_rc_tty" },
|
1999-01-22 10:36:48 +00:00
|
|
|
#define NRC (SNPTY+6)
|
1995-05-07 22:15:46 +00:00
|
|
|
{ "_nrc_tty" },
|
1999-01-22 10:36:48 +00:00
|
|
|
#define CY (SNPTY+7)
|
1995-07-21 17:02:29 +00:00
|
|
|
{ "_cy_tty" },
|
1999-01-22 10:36:48 +00:00
|
|
|
#define NCY (SNPTY+8)
|
1995-07-21 17:02:29 +00:00
|
|
|
{ "_ncy_tty" },
|
1999-01-22 10:36:48 +00:00
|
|
|
#define SI (SNPTY+9)
|
1995-09-22 20:01:34 +00:00
|
|
|
{ "_si_tty" },
|
1999-01-22 10:36:48 +00:00
|
|
|
#define NSI (SNPTY+10)
|
1995-09-22 20:01:34 +00:00
|
|
|
{ "_si_Nports" },
|
1994-11-03 11:41:34 +00:00
|
|
|
#endif
|
1994-05-26 05:23:31 +00:00
|
|
|
{ "" }
|
|
|
|
};
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static int usenumflag;
|
|
|
|
static int totalflag;
|
|
|
|
static int swapflag;
|
2002-05-23 14:58:07 +00:00
|
|
|
static char *nlistf;
|
|
|
|
static char *memf;
|
2002-05-23 14:44:23 +00:00
|
|
|
static kvm_t *kd;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static char *usagestr;
|
1995-05-13 17:25:23 +00:00
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
#define SVAR(var) __STRING(var) /* to force expansion */
|
|
|
|
#define KGET(idx, var) \
|
|
|
|
KGET1(idx, &var, sizeof(var), SVAR(var))
|
|
|
|
#define KGET1(idx, p, s, msg) \
|
|
|
|
KGET2(nl[idx].n_value, p, s, msg)
|
|
|
|
#define KGET2(addr, p, s, msg) \
|
|
|
|
if (kvm_read(kd, (u_long)(addr), p, s) != s) \
|
|
|
|
warnx("cannot read %s: %s", msg, kvm_geterr(kd))
|
1999-01-21 08:08:55 +00:00
|
|
|
#define KGETN(idx, var) \
|
|
|
|
KGET1N(idx, &var, sizeof(var), SVAR(var))
|
|
|
|
#define KGET1N(idx, p, s, msg) \
|
|
|
|
KGET2N(nl[idx].n_value, p, s, msg)
|
|
|
|
#define KGET2N(addr, p, s, msg) \
|
|
|
|
((kvm_read(kd, (u_long)(addr), p, s) == s) ? 1 : 0)
|
1994-05-26 05:23:31 +00:00
|
|
|
#define KGETRET(addr, p, s, msg) \
|
|
|
|
if (kvm_read(kd, (u_long)(addr), p, s) != s) { \
|
|
|
|
warnx("cannot read %s: %s", msg, kvm_geterr(kd)); \
|
|
|
|
return (0); \
|
|
|
|
}
|
|
|
|
|
2002-05-23 14:48:25 +00:00
|
|
|
static void filemode(void);
|
|
|
|
static int getfiles(char **, int *);
|
|
|
|
static void swapmode(void);
|
|
|
|
static void ttymode(void);
|
|
|
|
static void ttyprt(struct tty *, int);
|
|
|
|
static void ttytype(struct tty *, char *, int, int, int);
|
|
|
|
static void usage(void);
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
int
|
2002-05-23 14:48:25 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
|
|
|
int ch, i, quit, ret;
|
2002-05-23 14:53:04 +00:00
|
|
|
int fileflag, ttyflag;
|
1995-05-13 17:25:23 +00:00
|
|
|
char buf[_POSIX2_LINE_MAX],*opts;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2002-05-23 14:53:04 +00:00
|
|
|
fileflag = swapflag = ttyflag = 0;
|
1995-05-13 17:25:23 +00:00
|
|
|
|
|
|
|
/* We will behave like good old swapinfo if thus invoked */
|
|
|
|
opts = strrchr(argv[0],'/');
|
|
|
|
if (opts)
|
|
|
|
opts++;
|
|
|
|
else
|
|
|
|
opts = argv[0];
|
|
|
|
if (!strcmp(opts,"swapinfo")) {
|
|
|
|
swapflag = 1;
|
1996-05-29 19:57:25 +00:00
|
|
|
opts = "kM:N:";
|
1997-10-09 07:22:08 +00:00
|
|
|
usagestr = "swapinfo [-k] [-M core] [-N system]";
|
1995-05-13 17:25:23 +00:00
|
|
|
} else {
|
2002-05-23 14:53:04 +00:00
|
|
|
opts = "TM:N:fknst";
|
2002-05-23 14:58:07 +00:00
|
|
|
usagestr = "pstat [-Tfknst] [-M core] [-N system]";
|
1995-05-13 17:25:23 +00:00
|
|
|
}
|
|
|
|
|
1997-03-31 05:11:47 +00:00
|
|
|
while ((ch = getopt(argc, argv, opts)) != -1)
|
1994-05-26 05:23:31 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 'f':
|
|
|
|
fileflag = 1;
|
|
|
|
break;
|
1995-05-13 17:25:23 +00:00
|
|
|
case 'k':
|
|
|
|
putenv("BLOCKSIZE=1K");
|
|
|
|
break;
|
1994-05-26 05:23:31 +00:00
|
|
|
case 'M':
|
|
|
|
memf = optarg;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
nlistf = optarg;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
usenumflag = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
1999-01-21 08:08:55 +00:00
|
|
|
++swapflag;
|
1994-05-26 05:23:31 +00:00
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
totalflag = 1;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
ttyflag = 1;
|
|
|
|
break;
|
|
|
|
default:
|
1997-10-09 07:22:08 +00:00
|
|
|
usage();
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Discard setgid privileges if not the running kernel so that bad
|
|
|
|
* guys can't print interesting stuff from kernel memory.
|
|
|
|
*/
|
|
|
|
if (nlistf != NULL || memf != NULL)
|
|
|
|
(void)setgid(getgid());
|
|
|
|
|
|
|
|
if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == 0)
|
|
|
|
errx(1, "kvm_openfiles: %s", buf);
|
2001-08-31 16:26:37 +00:00
|
|
|
(void)setgid(getgid());
|
1994-05-26 05:23:31 +00:00
|
|
|
if ((ret = kvm_nlist(kd, nl)) != 0) {
|
|
|
|
if (ret == -1)
|
|
|
|
errx(1, "kvm_nlist: %s", kvm_geterr(kd));
|
1999-01-21 08:08:55 +00:00
|
|
|
for (i = NLMANDATORYBEG, quit = 0; i <= NLMANDATORYEND; i++)
|
1994-05-26 05:23:31 +00:00
|
|
|
if (!nl[i].n_value) {
|
|
|
|
quit = 1;
|
1997-10-09 07:22:08 +00:00
|
|
|
warnx("undefined symbol: %s", nl[i].n_name);
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
if (quit)
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-05-23 14:53:04 +00:00
|
|
|
if (!(fileflag | ttyflag | swapflag | totalflag))
|
1997-10-09 07:22:08 +00:00
|
|
|
usage();
|
1994-05-26 05:23:31 +00:00
|
|
|
if (fileflag || totalflag)
|
|
|
|
filemode();
|
|
|
|
if (ttyflag)
|
|
|
|
ttymode();
|
|
|
|
if (swapflag || totalflag)
|
|
|
|
swapmode();
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
1997-10-09 07:22:08 +00:00
|
|
|
static void
|
2002-05-23 14:48:25 +00:00
|
|
|
usage(void)
|
1997-10-09 07:22:08 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "usage: %s\n", usagestr);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static const char hdr[] =
|
1998-08-19 01:32:28 +00:00
|
|
|
" LINE RAW CAN OUT IHIWT ILOWT OHWT LWT COL STATE SESS PGID DISC\n";
|
1994-05-26 05:23:31 +00:00
|
|
|
int ttyspace = 128;
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static void
|
2002-05-23 14:48:25 +00:00
|
|
|
ttymode(void)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
|
|
|
struct tty *tty;
|
1999-08-08 19:44:00 +00:00
|
|
|
struct tty ttyb[1000];
|
2001-07-30 21:42:26 +00:00
|
|
|
int error;
|
|
|
|
size_t len, i;
|
1999-08-08 19:44:00 +00:00
|
|
|
|
2001-06-17 02:01:43 +00:00
|
|
|
(void)printf("%s", hdr);
|
1999-08-08 19:44:00 +00:00
|
|
|
len = sizeof(ttyb);
|
|
|
|
error = sysctlbyname("kern.ttys", &ttyb, &len, 0, 0);
|
|
|
|
if (!error) {
|
|
|
|
len /= sizeof(ttyb[0]);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
ttyprt(&ttyb[i], 0);
|
|
|
|
}
|
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
if ((tty = malloc(ttyspace * sizeof(*tty))) == NULL)
|
1997-10-09 07:22:08 +00:00
|
|
|
errx(1, "malloc");
|
1994-11-03 11:41:34 +00:00
|
|
|
if (nl[SCONS].n_type != 0) {
|
|
|
|
(void)printf("1 console\n");
|
|
|
|
KGET(SCONS, *tty);
|
|
|
|
ttyprt(&tty[0], 0);
|
|
|
|
}
|
|
|
|
#ifdef __FreeBSD__
|
1995-04-28 09:08:18 +00:00
|
|
|
if (nl[NSCCONS].n_type != 0)
|
1995-09-22 20:01:34 +00:00
|
|
|
ttytype(tty, "vty", SCCONS, NSCCONS, 0);
|
1995-05-07 22:15:46 +00:00
|
|
|
if (nl[NSIO].n_type != 0)
|
1995-09-22 20:01:34 +00:00
|
|
|
ttytype(tty, "sio", SIO, NSIO, 0);
|
1995-05-07 22:15:46 +00:00
|
|
|
if (nl[NRC].n_type != 0)
|
1995-09-22 20:01:34 +00:00
|
|
|
ttytype(tty, "rc", RC, NRC, 0);
|
1995-07-21 17:02:29 +00:00
|
|
|
if (nl[NCY].n_type != 0)
|
1995-09-22 20:01:34 +00:00
|
|
|
ttytype(tty, "cy", CY, NCY, 0);
|
|
|
|
if (nl[NSI].n_type != 0)
|
|
|
|
ttytype(tty, "si", SI, NSI, 1);
|
1994-05-26 05:23:31 +00:00
|
|
|
#endif
|
|
|
|
if (nl[SNPTY].n_type != 0)
|
1995-09-22 20:01:34 +00:00
|
|
|
ttytype(tty, "pty", SPTY, SNPTY, 0);
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static void
|
2002-05-23 14:48:25 +00:00
|
|
|
ttytype(struct tty *tty, char *name, int type, int number, int indir)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
1997-03-11 13:00:41 +00:00
|
|
|
struct tty *tp;
|
1994-05-26 05:23:31 +00:00
|
|
|
int ntty;
|
1995-09-22 20:01:34 +00:00
|
|
|
struct tty **ttyaddr;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
if (tty == NULL)
|
|
|
|
return;
|
|
|
|
KGET(number, ntty);
|
|
|
|
(void)printf("%d %s %s\n", ntty, name, (ntty == 1) ? "line" : "lines");
|
|
|
|
if (ntty > ttyspace) {
|
|
|
|
ttyspace = ntty;
|
|
|
|
if ((tty = realloc(tty, ttyspace * sizeof(*tty))) == 0)
|
1997-10-09 07:22:08 +00:00
|
|
|
errx(1, "realloc");
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
1995-09-22 20:01:34 +00:00
|
|
|
if (indir) {
|
|
|
|
KGET(type, ttyaddr);
|
|
|
|
KGET2(ttyaddr, tty, ntty * sizeof(struct tty), "tty structs");
|
|
|
|
} else {
|
|
|
|
KGET1(type, tty, ntty * sizeof(struct tty), "tty structs");
|
|
|
|
}
|
2001-06-17 02:01:43 +00:00
|
|
|
(void)printf("%s", hdr);
|
1994-05-26 05:23:31 +00:00
|
|
|
for (tp = tty; tp < &tty[ntty]; tp++)
|
|
|
|
ttyprt(tp, tp - tty);
|
|
|
|
}
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static struct {
|
1994-05-26 05:23:31 +00:00
|
|
|
int flag;
|
|
|
|
char val;
|
|
|
|
} ttystates[] = {
|
1995-07-21 17:02:29 +00:00
|
|
|
#ifdef TS_WOPEN
|
1994-05-26 05:23:31 +00:00
|
|
|
{ TS_WOPEN, 'W'},
|
1995-07-21 17:02:29 +00:00
|
|
|
#endif
|
1994-05-26 05:23:31 +00:00
|
|
|
{ TS_ISOPEN, 'O'},
|
|
|
|
{ TS_CARR_ON, 'C'},
|
1995-07-21 17:02:29 +00:00
|
|
|
#ifdef TS_CONNECTED
|
|
|
|
{ TS_CONNECTED, 'c'},
|
|
|
|
#endif
|
1994-05-26 05:23:31 +00:00
|
|
|
{ TS_TIMEOUT, 'T'},
|
|
|
|
{ TS_FLUSH, 'F'},
|
|
|
|
{ TS_BUSY, 'B'},
|
1995-07-21 17:02:29 +00:00
|
|
|
#ifdef TS_ASLEEP
|
1994-05-26 05:23:31 +00:00
|
|
|
{ TS_ASLEEP, 'A'},
|
1995-07-21 17:02:29 +00:00
|
|
|
#endif
|
|
|
|
#ifdef TS_SO_OLOWAT
|
|
|
|
{ TS_SO_OLOWAT, 'A'},
|
|
|
|
#endif
|
|
|
|
#ifdef TS_SO_OCOMPLETE
|
|
|
|
{ TS_SO_OCOMPLETE, 'a'},
|
|
|
|
#endif
|
1994-05-26 05:23:31 +00:00
|
|
|
{ TS_XCLUDE, 'X'},
|
|
|
|
{ TS_TTSTOP, 'S'},
|
1995-07-21 17:02:29 +00:00
|
|
|
#ifdef TS_CAR_OFLOW
|
|
|
|
{ TS_CAR_OFLOW, 'm'},
|
|
|
|
#endif
|
|
|
|
#ifdef TS_CTS_OFLOW
|
|
|
|
{ TS_CTS_OFLOW, 'o'},
|
|
|
|
#endif
|
|
|
|
#ifdef TS_DSR_OFLOW
|
|
|
|
{ TS_DSR_OFLOW, 'd'},
|
|
|
|
#endif
|
1994-05-26 05:23:31 +00:00
|
|
|
{ TS_TBLOCK, 'K'},
|
|
|
|
{ TS_ASYNC, 'Y'},
|
|
|
|
{ TS_BKSL, 'D'},
|
|
|
|
{ TS_ERASE, 'E'},
|
|
|
|
{ TS_LNCH, 'L'},
|
|
|
|
{ TS_TYPEN, 'P'},
|
|
|
|
{ TS_CNTTB, 'N'},
|
1995-07-21 17:02:29 +00:00
|
|
|
#ifdef TS_CAN_BYPASS_L_RINT
|
1995-05-07 23:19:53 +00:00
|
|
|
{ TS_CAN_BYPASS_L_RINT, 'l'},
|
1995-07-21 17:02:29 +00:00
|
|
|
#endif
|
|
|
|
#ifdef TS_SNOOP
|
|
|
|
{ TS_SNOOP, 's'},
|
|
|
|
#endif
|
|
|
|
#ifdef TS_ZOMBIE
|
|
|
|
{ TS_ZOMBIE, 'Z'},
|
1995-05-07 23:19:53 +00:00
|
|
|
#endif
|
1994-05-26 05:23:31 +00:00
|
|
|
{ 0, '\0'},
|
|
|
|
};
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static void
|
2002-05-23 14:48:25 +00:00
|
|
|
ttyprt(struct tty *tp, int line)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
1997-03-11 13:00:41 +00:00
|
|
|
int i, j;
|
1994-05-26 05:23:31 +00:00
|
|
|
pid_t pgid;
|
|
|
|
char *name, state[20];
|
|
|
|
|
|
|
|
if (usenumflag || tp->t_dev == 0 ||
|
|
|
|
(name = devname(tp->t_dev, S_IFCHR)) == NULL)
|
2001-07-04 22:53:19 +00:00
|
|
|
(void)printf(" %2d,%-2d", major(tp->t_dev), minor(tp->t_dev));
|
1994-05-26 05:23:31 +00:00
|
|
|
else
|
|
|
|
(void)printf("%7s ", name);
|
|
|
|
(void)printf("%2d %3d ", tp->t_rawq.c_cc, tp->t_canq.c_cc);
|
1998-08-19 01:32:28 +00:00
|
|
|
(void)printf("%3d %5d %5d %4d %3d %7d ", tp->t_outq.c_cc,
|
1998-03-07 15:36:29 +00:00
|
|
|
tp->t_ihiwat, tp->t_ilowat, tp->t_ohiwat, tp->t_olowat,
|
|
|
|
tp->t_column);
|
1994-05-26 05:23:31 +00:00
|
|
|
for (i = j = 0; ttystates[i].flag; i++)
|
|
|
|
if (tp->t_state&ttystates[i].flag)
|
|
|
|
state[j++] = ttystates[i].val;
|
|
|
|
if (j == 0)
|
|
|
|
state[j++] = '-';
|
|
|
|
state[j] = '\0';
|
1998-08-19 01:32:28 +00:00
|
|
|
(void)printf("%-6s %8lx", state, (u_long)(void *)tp->t_session);
|
1994-05-26 05:23:31 +00:00
|
|
|
pgid = 0;
|
|
|
|
if (tp->t_pgrp != NULL)
|
|
|
|
KGET2(&tp->t_pgrp->pg_id, &pgid, sizeof(pid_t), "pgid");
|
|
|
|
(void)printf("%6d ", pgid);
|
|
|
|
switch (tp->t_line) {
|
|
|
|
case TTYDISC:
|
|
|
|
(void)printf("term\n");
|
|
|
|
break;
|
1995-05-07 22:15:46 +00:00
|
|
|
case NTTYDISC:
|
|
|
|
(void)printf("ntty\n");
|
|
|
|
break;
|
1994-05-26 05:23:31 +00:00
|
|
|
case SLIPDISC:
|
|
|
|
(void)printf("slip\n");
|
|
|
|
break;
|
1995-05-07 22:15:46 +00:00
|
|
|
case PPPDISC:
|
|
|
|
(void)printf("ppp\n");
|
|
|
|
break;
|
1994-05-26 05:23:31 +00:00
|
|
|
default:
|
|
|
|
(void)printf("%d\n", tp->t_line);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static void
|
2002-05-23 14:48:25 +00:00
|
|
|
filemode(void)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
1997-03-11 13:00:41 +00:00
|
|
|
struct file *fp;
|
1994-05-26 05:23:31 +00:00
|
|
|
struct file *addr;
|
|
|
|
char *buf, flagbuf[16], *fbp;
|
|
|
|
int len, maxfile, nfile;
|
|
|
|
static char *dtypes[] = { "???", "inode", "socket" };
|
|
|
|
|
|
|
|
KGET(FNL_MAXFILE, maxfile);
|
|
|
|
if (totalflag) {
|
|
|
|
KGET(FNL_NFILE, nfile);
|
|
|
|
(void)printf("%3d/%3d files\n", nfile, maxfile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (getfiles(&buf, &len) == -1)
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* Getfiles returns in malloc'd memory a pointer to the first file
|
|
|
|
* structure, and then an array of file structs (whose addresses are
|
|
|
|
* derivable from the previous entry).
|
|
|
|
*/
|
2000-12-30 14:19:07 +00:00
|
|
|
addr = LIST_FIRST((struct filelist *)buf);
|
1996-03-11 05:41:43 +00:00
|
|
|
fp = (struct file *)(buf + sizeof(struct filelist));
|
|
|
|
nfile = (len - sizeof(struct filelist)) / sizeof(struct file);
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
(void)printf("%d/%d open files\n", nfile, maxfile);
|
|
|
|
(void)printf(" LOC TYPE FLG CNT MSG DATA OFFSET\n");
|
2000-12-30 14:19:07 +00:00
|
|
|
for (; (char *)fp < buf + len; addr = LIST_NEXT(fp, f_list), fp++) {
|
1994-05-26 05:23:31 +00:00
|
|
|
if ((unsigned)fp->f_type > DTYPE_SOCKET)
|
|
|
|
continue;
|
1998-08-19 01:32:28 +00:00
|
|
|
(void)printf("%8lx ", (u_long)(void *)addr);
|
1994-05-26 05:23:31 +00:00
|
|
|
(void)printf("%-8.8s", dtypes[fp->f_type]);
|
|
|
|
fbp = flagbuf;
|
|
|
|
if (fp->f_flag & FREAD)
|
|
|
|
*fbp++ = 'R';
|
|
|
|
if (fp->f_flag & FWRITE)
|
|
|
|
*fbp++ = 'W';
|
|
|
|
if (fp->f_flag & FAPPEND)
|
|
|
|
*fbp++ = 'A';
|
|
|
|
if (fp->f_flag & FASYNC)
|
|
|
|
*fbp++ = 'I';
|
|
|
|
*fbp = '\0';
|
|
|
|
(void)printf("%6s %3d", flagbuf, fp->f_count);
|
|
|
|
(void)printf(" %3d", fp->f_msgcount);
|
1998-08-19 01:32:28 +00:00
|
|
|
(void)printf(" %8lx", (u_long)(void *)fp->f_data);
|
1994-05-26 05:23:31 +00:00
|
|
|
if (fp->f_offset < 0)
|
|
|
|
(void)printf(" %qx\n", fp->f_offset);
|
|
|
|
else
|
|
|
|
(void)printf(" %qd\n", fp->f_offset);
|
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static int
|
2002-05-23 14:48:25 +00:00
|
|
|
getfiles(char **abuf, int *alen)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
int mib[2];
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* Add emulation of KINFO_FILE here.
|
|
|
|
*/
|
|
|
|
if (memf != NULL)
|
1997-10-09 07:22:08 +00:00
|
|
|
errx(1, "files on dead kernel, not implemented");
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_FILE;
|
|
|
|
if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1) {
|
|
|
|
warn("sysctl: KERN_FILE");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if ((buf = malloc(len)) == NULL)
|
1997-10-09 07:22:08 +00:00
|
|
|
errx(1, "malloc");
|
1994-05-26 05:23:31 +00:00
|
|
|
if (sysctl(mib, 2, buf, &len, NULL, 0) == -1) {
|
|
|
|
warn("sysctl: KERN_FILE");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
*abuf = buf;
|
|
|
|
*alen = len;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* swapmode is based on a program called swapinfo written
|
|
|
|
* by Kevin Lahey <kml@rokkaku.atl.ga.us>.
|
|
|
|
*/
|
2002-05-23 14:44:23 +00:00
|
|
|
static void
|
1999-01-21 08:08:55 +00:00
|
|
|
swapmode(void)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
1999-01-22 10:36:48 +00:00
|
|
|
struct kvm_swap kswap[16];
|
|
|
|
int i;
|
|
|
|
int n;
|
|
|
|
int pagesize = getpagesize();
|
|
|
|
const char *header;
|
|
|
|
int hlen;
|
|
|
|
long blocksize;
|
|
|
|
|
|
|
|
n = kvm_getswapinfo(
|
2002-05-23 14:42:17 +00:00
|
|
|
kd,
|
1999-01-22 10:36:48 +00:00
|
|
|
kswap,
|
|
|
|
sizeof(kswap)/sizeof(kswap[0]),
|
1999-01-22 10:57:22 +00:00
|
|
|
((swapflag > 1) ? SWIF_DUMP_TREE : 0) | SWIF_DEV_PREFIX
|
1999-01-22 10:36:48 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
#define CONVERT(v) ((int)((quad_t)(v) * pagesize / blocksize))
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
header = getbsize(&hlen, &blocksize);
|
1999-01-22 10:36:48 +00:00
|
|
|
if (totalflag == 0) {
|
1999-12-05 20:04:56 +00:00
|
|
|
(void)printf("%-15s %*s %8s %8s %8s %s\n",
|
1994-05-26 05:23:31 +00:00
|
|
|
"Device", hlen, header,
|
|
|
|
"Used", "Avail", "Capacity", "Type");
|
1999-01-21 08:08:55 +00:00
|
|
|
|
1999-01-22 10:36:48 +00:00
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
(void)printf(
|
1999-12-05 20:04:56 +00:00
|
|
|
"%-15s %*d ",
|
1999-01-22 10:36:48 +00:00
|
|
|
kswap[i].ksw_devname,
|
|
|
|
hlen,
|
|
|
|
CONVERT(kswap[i].ksw_total)
|
|
|
|
);
|
|
|
|
(void)printf(
|
|
|
|
"%8d %8d %5.0f%% %s\n",
|
|
|
|
CONVERT(kswap[i].ksw_used),
|
|
|
|
CONVERT(kswap[i].ksw_total - kswap[i].ksw_used),
|
|
|
|
(double)kswap[i].ksw_used * 100.0 /
|
|
|
|
(double)kswap[i].ksw_total,
|
|
|
|
(kswap[i].ksw_flags & SW_SEQUENTIAL) ?
|
|
|
|
"Sequential" : "Interleaved"
|
|
|
|
);
|
1999-01-21 08:08:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
if (totalflag) {
|
1999-01-22 10:36:48 +00:00
|
|
|
blocksize = 1024 * 1024;
|
|
|
|
|
|
|
|
(void)printf(
|
2002-05-23 14:42:17 +00:00
|
|
|
"%dM/%dM swap space\n",
|
1999-01-22 10:36:48 +00:00
|
|
|
CONVERT(kswap[n].ksw_used),
|
|
|
|
CONVERT(kswap[n].ksw_total)
|
|
|
|
);
|
|
|
|
} else if (n > 1) {
|
|
|
|
(void)printf(
|
1999-12-05 20:04:56 +00:00
|
|
|
"%-15s %*d %8d %8d %5.0f%%\n",
|
1999-01-22 10:36:48 +00:00
|
|
|
"Total",
|
2002-05-23 14:42:17 +00:00
|
|
|
hlen,
|
1999-01-22 10:36:48 +00:00
|
|
|
CONVERT(kswap[n].ksw_total),
|
|
|
|
CONVERT(kswap[n].ksw_used),
|
|
|
|
CONVERT(kswap[n].ksw_total - kswap[n].ksw_used),
|
|
|
|
(double)kswap[n].ksw_used * 100.0 /
|
|
|
|
(double)kswap[n].ksw_total
|
|
|
|
);
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
}
|