- Make pstat(8) WARNS=6 safe.
- While here, eliminate the check for len > 0 in ttymode_sysctl as the code is able to handle this case well. Reviewed by: ed (initial version)
This commit is contained in:
parent
c3ea428a25
commit
52074d389f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=194014
@ -6,7 +6,7 @@ LINKS= ${BINDIR}/pstat ${BINDIR}/swapinfo
|
|||||||
MAN= pstat.8
|
MAN= pstat.8
|
||||||
MLINKS= pstat.8 swapinfo.8
|
MLINKS= pstat.8 swapinfo.8
|
||||||
|
|
||||||
WARNS?= 3
|
WARNS?= 6
|
||||||
|
|
||||||
DPADD= ${LIBKVM} ${LIBUTIL}
|
DPADD= ${LIBKVM} ${LIBUTIL}
|
||||||
LDADD= -lkvm -lutil
|
LDADD= -lkvm -lutil
|
||||||
|
@ -76,16 +76,22 @@ enum {
|
|||||||
NL_CONSTTY,
|
NL_CONSTTY,
|
||||||
NL_MAXFILES,
|
NL_MAXFILES,
|
||||||
NL_NFILES,
|
NL_NFILES,
|
||||||
NL_TTY_LIST
|
NL_TTY_LIST,
|
||||||
|
NL_MARKER
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct nlist nl[] = {
|
static struct {
|
||||||
{ .n_name = "_constty" },
|
int order;
|
||||||
{ .n_name = "_maxfiles" },
|
const char *name;
|
||||||
{ .n_name = "_openfiles" },
|
} namelist[] = {
|
||||||
{ .n_name = "_tty_list" },
|
{ NL_CONSTTY, "_constty" },
|
||||||
{ .n_name = "" }
|
{ NL_MAXFILES, "_maxfiles" },
|
||||||
|
{ NL_NFILES, "_openfiles" },
|
||||||
|
{ NL_TTY_LIST, "_tty_list" },
|
||||||
|
{ NL_MARKER, "" },
|
||||||
};
|
};
|
||||||
|
#define NNAMES (sizeof(namelist) / sizeof(*namelist))
|
||||||
|
static struct nlist nl[NNAMES];
|
||||||
|
|
||||||
static int humanflag;
|
static int humanflag;
|
||||||
static int usenumflag;
|
static int usenumflag;
|
||||||
@ -98,7 +104,7 @@ static kvm_t *kd;
|
|||||||
static const char *usagestr;
|
static const char *usagestr;
|
||||||
|
|
||||||
static void filemode(void);
|
static void filemode(void);
|
||||||
static int getfiles(char **, size_t *);
|
static int getfiles(struct xfile **, size_t *);
|
||||||
static void swapmode(void);
|
static void swapmode(void);
|
||||||
static void ttymode(void);
|
static void ttymode(void);
|
||||||
static void ttyprt(struct xtty *);
|
static void ttyprt(struct xtty *);
|
||||||
@ -107,8 +113,9 @@ static void usage(void);
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ch, i, quit, ret;
|
int ch, quit, ret;
|
||||||
int fileflag, ttyflag;
|
int fileflag, ttyflag;
|
||||||
|
unsigned int i;
|
||||||
char buf[_POSIX2_LINE_MAX];
|
char buf[_POSIX2_LINE_MAX];
|
||||||
const char *opts;
|
const char *opts;
|
||||||
|
|
||||||
@ -170,6 +177,12 @@ main(int argc, char *argv[])
|
|||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize symbol names list.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < NNAMES; i++)
|
||||||
|
nl[namelist[i].order].n_name = strdup(namelist[i].name);
|
||||||
|
|
||||||
if (memf != NULL) {
|
if (memf != NULL) {
|
||||||
kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf);
|
kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf);
|
||||||
if (kd == NULL)
|
if (kd == NULL)
|
||||||
@ -253,12 +266,12 @@ ttymode_kvm(void)
|
|||||||
static void
|
static void
|
||||||
ttymode_sysctl(void)
|
ttymode_sysctl(void)
|
||||||
{
|
{
|
||||||
struct xtty *xt, *end;
|
struct xtty *xttys;
|
||||||
void *xttys;
|
|
||||||
size_t len;
|
size_t len;
|
||||||
|
unsigned int i, n;
|
||||||
|
|
||||||
(void)printf("%s", hdr);
|
(void)printf("%s", hdr);
|
||||||
if ((xttys = malloc(len = sizeof *xt)) == NULL)
|
if ((xttys = malloc(len = sizeof(*xttys))) == NULL)
|
||||||
err(1, "malloc()");
|
err(1, "malloc()");
|
||||||
while (sysctlbyname("kern.ttys", xttys, &len, 0, 0) == -1) {
|
while (sysctlbyname("kern.ttys", xttys, &len, 0, 0) == -1) {
|
||||||
if (errno != ENOMEM)
|
if (errno != ENOMEM)
|
||||||
@ -267,11 +280,9 @@ ttymode_sysctl(void)
|
|||||||
if ((xttys = realloc(xttys, len)) == NULL)
|
if ((xttys = realloc(xttys, len)) == NULL)
|
||||||
err(1, "realloc()");
|
err(1, "realloc()");
|
||||||
}
|
}
|
||||||
if (len > 0) {
|
n = len / sizeof(*xttys);
|
||||||
end = (struct xtty *)((char *)xttys + len);
|
for (i = 0; i < n; i++)
|
||||||
for (xt = xttys; xt < end; xt++)
|
ttyprt(&xttys[i]);
|
||||||
ttyprt(xt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -355,8 +366,8 @@ ttyprt(struct xtty *xt)
|
|||||||
static void
|
static void
|
||||||
filemode(void)
|
filemode(void)
|
||||||
{
|
{
|
||||||
struct xfile *fp;
|
struct xfile *fp, *buf;
|
||||||
char *buf, flagbuf[16], *fbp;
|
char flagbuf[16], *fbp;
|
||||||
int maxf, openf;
|
int maxf, openf;
|
||||||
size_t len;
|
size_t len;
|
||||||
static char const * const dtypes[] = { "???", "inode", "socket",
|
static char const * const dtypes[] = { "???", "inode", "socket",
|
||||||
@ -413,11 +424,11 @@ filemode(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
getfiles(char **abuf, size_t *alen)
|
getfiles(struct xfile **abuf, size_t *alen)
|
||||||
{
|
{
|
||||||
|
struct xfile *buf;
|
||||||
size_t len;
|
size_t len;
|
||||||
int mib[2];
|
int mib[2];
|
||||||
char *buf;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XXX
|
* XXX
|
||||||
|
Loading…
Reference in New Issue
Block a user