WARNS=4 fixes (incomplete, so set NO_WERROR), and lots of extra

cleanup courtesy of automatic checking (lint).
This commit is contained in:
Mark Murray 2002-02-03 14:43:04 +00:00
parent 0e5065e34c
commit 871e8d8c59
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=90143
10 changed files with 239 additions and 235 deletions

View File

@ -10,7 +10,7 @@ SRCS= fmt.c keyword.c nlist.c print.c ps.c lomac.c
# on large systems.
#
CFLAGS+=-DLAZY_PS
WARNS= 0
NO_WERROR=yes
DPADD= ${LIBM} ${LIBKVM}
LDADD= -lm -lkvm
#BINGRP= kmem

View File

@ -42,32 +42,27 @@ struct varent;
extern fixpt_t ccpu;
extern int eval, fscale, mempages, nlistread, rawcpu, cflag;
extern int sumrusage, termwidth, totwidth;
extern VAR var[];
extern VARENT *vhead;
__BEGIN_DECLS
void command(KINFO *, VARENT *);
void cputime(KINFO *, VARENT *);
int donlist(void);
char *fmt_argv(char **, char *, int);
double getpcpu(KINFO *);
double getpmem(KINFO *);
const char *fmt_argv(char **, char *, size_t);
double getpcpu(const KINFO *);
void kvar(KINFO *, VARENT *);
void logname(KINFO *, VARENT *);
void longtname(KINFO *, VARENT *);
void lstarted(KINFO *, VARENT *);
void maxrss(KINFO *, VARENT *);
void mtxname(KINFO *, VARENT *);
void nlisterr(struct nlist *);
void p_rssize(KINFO *, VARENT *);
void pagein(KINFO *, VARENT *);
void parsefmt(char *);
void parsefmt(const char *);
void pcpu(KINFO *, VARENT *);
void pmem(KINFO *, VARENT *);
void pri(KINFO *, VARENT *);
void priorityr(KINFO *, VARENT *);
void printheader(void);
void rssize(KINFO *, VARENT *);
void runame(KINFO *, VARENT *);
int s_runame(KINFO *);
void rvar(KINFO *, VARENT *);

View File

@ -31,23 +31,27 @@
* SUCH DAMAGE.
*/
#ifndef lint
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#if 0
#ifndef lint
static char sccsid[] = "@(#)fmt.c 8.4 (Berkeley) 4/15/94";
#endif
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#endif
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <vis.h>
#include "ps.h"
static char *cmdpart(char *);
@ -61,14 +65,14 @@ static char *
shquote(char **argv)
{
static long arg_max = -1;
long len;
size_t len;
char **p, *dst, *src;
static char *buf = NULL;
if (buf == NULL) {
if ((arg_max = sysconf(_SC_ARG_MAX)) == -1)
errx(1, "sysconf _SC_ARG_MAX failed");
if ((buf = malloc((4 * arg_max) + 1)) == NULL)
if ((buf = malloc((u_int)(4 * arg_max) + 1)) == NULL)
errx(1, "malloc failed");
}
@ -80,7 +84,7 @@ shquote(char **argv)
for (p = argv; (src = *p++) != 0; ) {
if (*src == 0)
continue;
len = (4 * arg_max - (dst - buf)) / 4;
len = (size_t)(4 * arg_max - (dst - buf)) / 4;
strvisx(dst, src, strlen(src) < len ? strlen(src) : len,
VIS_NL | VIS_CSTYLE);
while (*dst)
@ -103,13 +107,13 @@ cmdpart(char *arg0)
return ((cp = strrchr(arg0, '/')) != NULL ? cp + 1 : arg0);
}
char *
fmt_argv(char **argv, char *cmd, int maxlen)
const char *
fmt_argv(char **argv, char *cmd, size_t maxlen)
{
int len;
size_t len;
char *ap, *cp;
if (argv == 0 || argv[0] == 0) {
if (argv == NULL || argv[0] == NULL) {
if (cmd == NULL)
return ("");
ap = NULL;
@ -118,12 +122,13 @@ fmt_argv(char **argv, char *cmd, int maxlen)
ap = shquote(argv);
len = strlen(ap) + maxlen + 4;
}
if ((cp = malloc(len)) == NULL)
cp = malloc(len);
if (cp == NULL)
return (NULL);
if (ap == NULL)
sprintf(cp, " (%.*s)", maxlen, cmd);
sprintf(cp, " (%.*s)", (int)maxlen, cmd);
else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0)
sprintf(cp, "%s (%.*s)", ap, maxlen, cmd);
sprintf(cp, "%s (%.*s)", ap, (int)maxlen, cmd);
else
(void) strcpy(cp, ap);
return (cp);

View File

@ -31,25 +31,24 @@
* SUCH DAMAGE.
*/
#ifndef lint
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#if 0
#ifndef lint
static char sccsid[] = "@(#)keyword.c 8.5 (Berkeley) 4/2/94";
#else
static const char rcsid[] =
"$FreeBSD$";
#endif
#endif /* not lint */
#endif
#include <sys/param.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/proc.h>
#include <sys/sysctl.h>
#include <sys/ucred.h>
#include <sys/user.h>
#include <err.h>
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@ -72,7 +71,6 @@ int utime(), stime(), ixrss(), idrss(), isrss();
/* Compute offset in common structures. */
#define KOFF(x) offsetof(struct kinfo_proc, x)
#define UOFF(x) offsetof(struct usave, x)
#define ROFF(x) offsetof(struct rusage, x)
#define UIDFMT "u"
@ -81,112 +79,130 @@ int utime(), stime(), ixrss(), idrss(), isrss();
#define PIDLEN 5
#define USERLEN UT_NAMESIZE
VAR var[] = {
{"%cpu", "%CPU", NULL, 0, pcpu, NULL, 4},
{"%mem", "%MEM", NULL, 0, pmem, NULL, 4},
{"acflag", "ACFLG",
NULL, 0, kvar, NULL, 3, KOFF(ki_acflag), USHORT, "x"},
{"acflg", "", "acflag"},
{"blocked", "", "sigmask"},
{"caught", "", "sigcatch"},
{"command", "COMMAND", NULL, COMM|LJUST|USER, command, NULL, 16},
{"cpu", "CPU", NULL, 0, kvar, NULL, 3, KOFF(ki_estcpu), UINT, "d"},
{"cputime", "", "time"},
{"f", "F", NULL, 0, kvar, NULL, 7, KOFF(ki_flag), INT, "x"},
{"flags", "", "f"},
{"ignored", "", "sigignore"},
{"inblk", "INBLK",
NULL, USER, rvar, NULL, 4, ROFF(ru_inblock), LONG, "ld"},
{"inblock", "", "inblk"},
{"jobc", "JOBC", NULL, 0, kvar, NULL, 4, KOFF(ki_jobc), SHORT, "d"},
{"ktrace", "KTRACE",
NULL, 0, kvar, NULL, 8, KOFF(ki_traceflag), INT, "x"},
{"lim", "LIM", NULL, 0, maxrss, NULL, 5},
{"login", "LOGIN", NULL, LJUST, logname, NULL, MAXLOGNAME-1},
{"logname", "", "login"},
{"lstart", "STARTED", NULL, LJUST|USER, lstarted, NULL, 28},
{"lvl", "LVL", NULL, LJUST, lattr, NULL, 3},
{"majflt", "MAJFLT",
NULL, USER, rvar, NULL, 4, ROFF(ru_majflt), LONG, "ld"},
{"minflt", "MINFLT",
NULL, USER, rvar, NULL, 4, ROFF(ru_minflt), LONG, "ld"},
{"msgrcv", "MSGRCV",
NULL, USER, rvar, NULL, 4, ROFF(ru_msgrcv), LONG, "ld"},
{"msgsnd", "MSGSND",
NULL, USER, rvar, NULL, 4, ROFF(ru_msgsnd), LONG, "ld"},
{"mtxname", "MUTEX", NULL, LJUST, mtxname, NULL, 6},
{"ni", "", "nice"},
{"nice", "NI", NULL, 0, kvar, NULL, 2, KOFF(ki_nice), CHAR, "d"},
{"nivcsw", "NIVCSW",
NULL, USER, rvar, NULL, 5, ROFF(ru_nivcsw), LONG, "ld"},
{"nsignals", "", "nsigs"},
{"nsigs", "NSIGS",
NULL, USER, rvar, NULL, 4, ROFF(ru_nsignals), LONG, "ld"},
{"nswap", "NSWAP",
NULL, USER, rvar, NULL, 4, ROFF(ru_nswap), LONG, "ld"},
{"nvcsw", "NVCSW",
NULL, USER, rvar, NULL, 5, ROFF(ru_nvcsw), LONG, "ld"},
{"nwchan", "WCHAN", NULL, 0, kvar, NULL, 8, KOFF(ki_wchan), KPTR, "lx"},
{"oublk", "OUBLK",
NULL, USER, rvar, NULL, 4, ROFF(ru_oublock), LONG, "ld"},
{"oublock", "", "oublk"},
{"paddr", "PADDR", NULL, 0, kvar, NULL, 8, KOFF(ki_paddr), KPTR, "lx"},
{"pagein", "PAGEIN", NULL, USER, pagein, NULL, 6},
{"pcpu", "", "%cpu"},
{"pending", "", "sig"},
{"pgid", "PGID",
NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_pgid), UINT, PIDFMT},
{"pid", "PID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_pid), UINT, PIDFMT},
{"pmem", "", "%mem"},
{"ppid", "PPID",
NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_ppid), UINT, PIDFMT},
{"pri", "PRI", NULL, 0, pri, NULL, 3},
{"re", "RE", NULL, 0, kvar, NULL, 3, KOFF(ki_swtime), UINT, "d"},
static VAR var[] = {
{"%cpu", "%CPU", NULL, 0, pcpu, NULL, 4, 0, CHAR, NULL, 0},
{"%mem", "%MEM", NULL, 0, pmem, NULL, 4, 0, CHAR, NULL, 0},
{"acflag", "ACFLG", NULL, 0, kvar, NULL, 3, KOFF(ki_acflag), USHORT,
"x", 0},
{"acflg", "", "acflag", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"blocked", "", "sigmask", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"caught", "", "sigcatch", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"command", "COMMAND", NULL, COMM|LJUST|USER, command, NULL, 16,
0, CHAR, NULL, 0},
{"cpu", "CPU", NULL, 0, kvar, NULL, 3, KOFF(ki_estcpu), UINT, "d",
0},
{"cputime", "", "time", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"f", "F", NULL, 0, kvar, NULL, 7, KOFF(ki_flag), INT, "x", 0},
{"flags", "", "f", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"ignored", "", "sigignore", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"inblk", "INBLK", NULL, USER, rvar, NULL, 4, ROFF(ru_inblock), LONG,
"ld", 0},
{"inblock", "", "inblk", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"jobc", "JOBC", NULL, 0, kvar, NULL, 4, KOFF(ki_jobc), SHORT, "d",
0},
{"ktrace", "KTRACE", NULL, 0, kvar, NULL, 8, KOFF(ki_traceflag), INT,
"x", 0},
{"lim", "LIM", NULL, 0, maxrss, NULL, 5, 0, CHAR, NULL, 0},
{"login", "LOGIN", NULL, LJUST, logname, NULL, MAXLOGNAME-1, 0, CHAR,
NULL, 0},
{"logname", "", "login", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"lstart", "STARTED", NULL, LJUST|USER, lstarted, NULL, 28, 0, CHAR,
NULL, 0},
{"lvl", "LVL", NULL, LJUST, lattr, NULL, 3, 0, CHAR, NULL, 0},
{"majflt", "MAJFLT", NULL, USER, rvar, NULL, 4, ROFF(ru_majflt),
LONG, "ld", 0},
{"minflt", "MINFLT", NULL, USER, rvar, NULL, 4, ROFF(ru_minflt),
LONG, "ld", 0},
{"msgrcv", "MSGRCV", NULL, USER, rvar, NULL, 4, ROFF(ru_msgrcv),
LONG, "ld", 0},
{"msgsnd", "MSGSND", NULL, USER, rvar, NULL, 4, ROFF(ru_msgsnd),
LONG, "ld", 0},
{"mtxname", "MUTEX", NULL, LJUST, mtxname, NULL, 6, 0, CHAR, NULL,
0},
{"ni", "", "nice", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"nice", "NI", NULL, 0, kvar, NULL, 2, KOFF(ki_nice), CHAR, "d",
0},
{"nivcsw", "NIVCSW", NULL, USER, rvar, NULL, 5, ROFF(ru_nivcsw),
LONG, "ld", 0},
{"nsignals", "", "nsigs", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"nsigs", "NSIGS", NULL, USER, rvar, NULL, 4, ROFF(ru_nsignals),
LONG, "ld", 0},
{"nswap", "NSWAP", NULL, USER, rvar, NULL, 4, ROFF(ru_nswap),
LONG, "ld", 0},
{"nvcsw", "NVCSW", NULL, USER, rvar, NULL, 5, ROFF(ru_nvcsw),
LONG, "ld", 0},
{"oublk", "OUBLK", NULL, USER, rvar, NULL, 4, ROFF(ru_oublock),
LONG, "ld", 0},
{"oublock", "", "oublk", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"paddr", "PADDR", NULL, 0, kvar, NULL, 8, KOFF(ki_paddr), KPTR,
"lx", 0},
{"pagein", "PAGEIN", NULL, USER, pagein, NULL, 6, 0, CHAR, NULL, 0},
{"pcpu", "", "%cpu", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"pending", "", "sig", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"pgid", "PGID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_pgid), UINT,
PIDFMT, 0},
{"pid", "PID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_pid), UINT,
PIDFMT, 0},
{"pmem", "", "%mem", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"ppid", "PPID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_ppid), UINT,
PIDFMT, 0},
{"pri", "PRI", NULL, 0, pri, NULL, 3, 0, CHAR, NULL, 0},
{"re", "RE", NULL, 0, kvar, NULL, 3, KOFF(ki_swtime), UINT, "d",
0},
{"rgid", "RGID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_rgid),
UINT, UIDFMT},
{"rss", "RSS", NULL, 0, kvar, NULL, 4, KOFF(ki_rssize), UINT, "d"},
{"rtprio", "RTPRIO", NULL, 0, priorityr, NULL, 7, KOFF(ki_pri)},
UINT, UIDFMT, 0},
{"rss", "RSS", NULL, 0, kvar, NULL, 4, KOFF(ki_rssize), UINT, "d",
0},
{"rtprio", "RTPRIO", NULL, 0, priorityr, NULL, 7, KOFF(ki_pri), CHAR,
NULL, 0},
{"ruid", "RUID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_ruid),
UINT, UIDFMT},
{"ruser", "RUSER", NULL, LJUST|DSIZ, runame, s_runame, USERLEN},
UINT, UIDFMT, 0},
{"ruser", "RUSER", NULL, LJUST|DSIZ, runame, s_runame, USERLEN,
0, CHAR, NULL, 0},
{"sid", "SID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_sid), UINT,
PIDFMT},
{"sig", "PENDING", NULL, 0, kvar, NULL, 8, KOFF(ki_siglist), INT, "x"},
{"sigcatch", "CAUGHT",
NULL, 0, kvar, NULL, 8, KOFF(ki_sigcatch), UINT, "x"},
{"sigignore", "IGNORED",
NULL, 0, kvar, NULL, 8, KOFF(ki_sigignore), UINT, "x"},
{"sigmask", "BLOCKED",
NULL, 0, kvar, NULL, 8, KOFF(ki_sigmask), UINT, "x"},
{"sl", "SL", NULL, 0, kvar, NULL, 3, KOFF(ki_slptime), UINT, "d"},
{"start", "STARTED", NULL, LJUST|USER, started, NULL, 7},
{"stat", "", "state"},
{"state", "STAT", NULL, 0, state, NULL, 4},
{"svgid", "SVGID", NULL, 0,
kvar, NULL, UIDLEN, KOFF(ki_svgid), UINT, UIDFMT},
{"svuid", "SVUID", NULL, 0,
kvar, NULL, UIDLEN, KOFF(ki_svuid), UINT, UIDFMT},
{"tdev", "TDEV", NULL, 0, tdev, NULL, 4},
{"time", "TIME", NULL, USER, cputime, NULL, 9},
{"tpgid", "TPGID",
NULL, 0, kvar, NULL, 4, KOFF(ki_tpgid), UINT, PIDFMT},
PIDFMT, 0},
{"sig", "PENDING", NULL, 0, kvar, NULL, 8, KOFF(ki_siglist), INT,
"x", 0},
{"sigcatch", "CAUGHT", NULL, 0, kvar, NULL, 8, KOFF(ki_sigcatch),
UINT, "x", 0},
{"sigignore", "IGNORED", NULL, 0, kvar, NULL, 8, KOFF(ki_sigignore),
UINT, "x", 0},
{"sigmask", "BLOCKED", NULL, 0, kvar, NULL, 8, KOFF(ki_sigmask),
UINT, "x", 0},
{"sl", "SL", NULL, 0, kvar, NULL, 3, KOFF(ki_slptime), UINT, "d",
0},
{"start", "STARTED", NULL, LJUST|USER, started, NULL, 7, 0, CHAR, NULL,
0},
{"stat", "", "state", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"state", "STAT", NULL, 0, state, NULL, 4, 0, CHAR, NULL, 0},
{"svgid", "SVGID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_svgid),
UINT, UIDFMT, 0},
{"svuid", "SVUID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_svuid),
UINT, UIDFMT, 0},
{"tdev", "TDEV", NULL, 0, tdev, NULL, 4, 0, CHAR, NULL, 0},
{"time", "TIME", NULL, USER, cputime, NULL, 9, 0, CHAR, NULL, 0},
{"tpgid", "TPGID", NULL, 0, kvar, NULL, 4, KOFF(ki_tpgid), UINT,
PIDFMT, 0},
{"tsid", "TSID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_tsid), UINT,
PIDFMT},
{"tsiz", "TSIZ", NULL, 0, tsize, NULL, 4},
{"tt", "TT ", NULL, 0, tname, NULL, 4},
{"tty", "TTY", NULL, LJUST, longtname, NULL, 8},
{"ucomm", "UCOMM", NULL, LJUST, ucomm, NULL, MAXCOMLEN},
{"uid", "UID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_uid),
UINT, UIDFMT},
{"upr", "UPR", NULL, 0, kvar, NULL, 3, KOFF(ki_pri.pri_user),
UCHAR, "d"},
{"user", "USER", NULL, LJUST|DSIZ, uname, s_uname, USERLEN},
{"usrpri", "", "upr"},
{"vsize", "", "vsz"},
{"vsz", "VSZ", NULL, 0, vsize, NULL, 5},
{"wchan", "WCHAN", NULL, LJUST, wchan, NULL, 6},
{"xstat", "XSTAT", NULL, 0, kvar, NULL, 4, KOFF(ki_xstat), USHORT, "x"},
{""},
PIDFMT, 0},
{"tsiz", "TSIZ", NULL, 0, tsize, NULL, 4, 0, CHAR, NULL, 0},
{"tt", "TT ", NULL, 0, tname, NULL, 4, 0, CHAR, NULL, 0},
{"tty", "TTY", NULL, LJUST, longtname, NULL, 8, 0, CHAR, NULL, 0},
{"ucomm", "UCOMM", NULL, LJUST, ucomm, NULL, MAXCOMLEN, 0, CHAR, NULL,
0},
{"uid", "UID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_uid), UINT,
UIDFMT, 0},
{"upr", "UPR", NULL, 0, kvar, NULL, 3, KOFF(ki_pri.pri_user), UCHAR,
"d", 0},
{"user", "USER", NULL, LJUST|DSIZ, uname, s_uname, USERLEN, 0, CHAR,
NULL, 0},
{"usrpri", "", "upr", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"vsize", "", "vsz", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"vsz", "VSZ", NULL, 0, vsize, NULL, 5, 0, CHAR, NULL, 0},
{"wchan", "WCHAN", NULL, LJUST, wchan, NULL, 6, 0, CHAR, NULL, 0},
{"xstat", "XSTAT", NULL, 0, kvar, NULL, 4, KOFF(ki_xstat), USHORT,
"x", 0},
{"", NULL, NULL, 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
};
void
@ -194,7 +210,7 @@ showkey(void)
{
VAR *v;
int i;
char *p, *sep;
const char *p, *sep;
i = 0;
sep = "";
@ -211,17 +227,19 @@ showkey(void)
}
void
parsefmt(char *p)
parsefmt(const char *p)
{
static struct varent *vtail;
char *tempstr, *tempstr1;
#define FMTSEP " \t,\n"
while (p && *p) {
tempstr1 = tempstr = strdup(p);
while (tempstr && *tempstr) {
char *cp;
VAR *v;
struct varent *vent;
while ((cp = strsep(&p, FMTSEP)) != NULL && *cp == '\0')
while ((cp = strsep(&tempstr, FMTSEP)) != NULL && *cp == '\0')
/* void */;
if (cp == NULL || !(v = findvar(cp)))
continue;
@ -236,6 +254,7 @@ parsefmt(char *p)
vtail = vent;
}
}
free(tempstr1);
if (!vhead)
errx(1, "no valid keywords");
}
@ -245,7 +264,6 @@ findvar(char *p)
{
VAR *v, key;
char *hp;
int vcmp();
hp = strchr(p, '=');
if (hp)
@ -273,5 +291,5 @@ findvar(char *p)
static int
vcmp(const void *a, const void *b)
{
return (strcmp(((VAR *)a)->name, ((VAR *)b)->name));
return (strcmp(((const VAR *)a)->name, ((const VAR *)b)->name));
}

View File

@ -32,7 +32,6 @@
* SUCH DAMAGE.
*
* $Id: lomac.c,v 1.3 2001/11/26 21:04:04 bfeldman Exp $
* $FreeBSD$
*/
/*
@ -40,6 +39,10 @@
* this interface to determine the LOMAC attributes of files.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/lomacio.h>
@ -66,7 +69,7 @@ static int devlomac = -1; /* file descriptor for LOMAC_DEVICE */
* Makes `devlomac' a fd to LOMAC_DEVICE
*/
void
static void
lomac_start(void)
{
if ((devlomac = open(LOMAC_DEVICE, O_RDWR)) == -1)

View File

@ -35,6 +35,5 @@
* $FreeBSD$
*/
void lomac_start(void);
void lomac_stop(void);
int get_lattr(int);

View File

@ -31,19 +31,23 @@
* SUCH DAMAGE.
*/
#ifndef lint
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#if 0
#ifndef lint
static char sccsid[] = "@(#)nlist.c 8.4 (Berkeley) 4/2/94";
#endif
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#endif
#include <sys/types.h>
#include <sys/sysctl.h>
#include <stddef.h>
#include "ps.h"
fixpt_t ccpu; /* kernel _ccpu variable */
int nlistread; /* if nlist already read. */
int mempages; /* number of pages of phys. memory */

View File

@ -31,13 +31,15 @@
* SUCH DAMAGE.
*/
#ifndef lint
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#if 0
#ifndef lint
static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94";
#endif
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#endif
#include <sys/param.h>
#include <sys/time.h>
@ -45,10 +47,8 @@ static const char rcsid[] =
#include <sys/proc.h>
#include <sys/stat.h>
#include <sys/ucred.h>
#include <sys/user.h>
#include <sys/sysctl.h>
#include <vm/vm.h>
#include <err.h>
#include <langinfo.h>
@ -58,13 +58,15 @@ static const char rcsid[] =
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <unistd.h>
#include <vis.h>
#include "lomac.h"
#include "ps.h"
static void printval __P((char *, VAR *));
void
printheader(void)
{
@ -423,26 +425,6 @@ vsize(KINFO *k, VARENT *ve)
(k->ki_p->ki_size/1024));
}
void
rssize(KINFO *k, VARENT *ve)
{
VAR *v;
v = ve->var;
/* XXX don't have info about shared */
(void)printf("%*lu", v->width,
(u_long)pgtok(k->ki_p->ki_rssize));
}
void
p_rssize(KINFO *k, VARENT *ve) /* doesn't account for text */
{
VAR *v;
v = ve->var;
(void)printf("%*ld", v->width, (long)pgtok(k->ki_p->ki_rssize));
}
void
cputime(KINFO *k, VARENT *ve)
{
@ -483,7 +465,7 @@ cputime(KINFO *k, VARENT *ve)
}
double
getpcpu(KINFO *k)
getpcpu(const KINFO *k)
{
static int failure;
@ -512,7 +494,7 @@ pcpu(KINFO *k, VARENT *ve)
(void)printf("%*.1f", v->width, getpcpu(k));
}
double
static double
getpmem(KINFO *k)
{
static int failure;
@ -550,8 +532,9 @@ pagein(KINFO *k, VARENT *ve)
k->ki_valid ? k->ki_p->ki_rusage.ru_majflt : 0);
}
/* ARGSUSED */
void
maxrss(KINFO *k, VARENT *ve)
maxrss(KINFO *k __unused, VARENT *ve)
{
VAR *v;
@ -573,14 +556,14 @@ void
priorityr(KINFO *k, VARENT *ve)
{
VAR *v;
struct priority *pri;
struct priority *lpri;
char str[8];
unsigned class, level;
v = ve->var;
pri = (struct priority *) ((char *)k + v->off);
class = pri->pri_class;
level = pri->pri_level;
lpri = (struct priority *) ((char *)k + v->off);
class = lpri->pri_class;
level = lpri->pri_level;
switch (class) {
case PRI_REALTIME:
snprintf(str, sizeof(str), "real:%u", level);

View File

@ -31,42 +31,39 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
static char const copyright[] =
static const char copyright[] =
"@(#) Copyright (c) 1990, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
#if 0
#ifndef lint
static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94";
#endif
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#endif
#include <sys/param.h>
#include <sys/user.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/sysctl.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <kvm.h>
#include <limits.h>
#include <locale.h>
#include <nlist.h>
#include <paths.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
#include <utmp.h>
#include "lomac.h"
@ -74,8 +71,8 @@ static const char rcsid[] =
#define SEP ", \t" /* username separators */
KINFO *kinfo;
struct varent *vhead, *vtail;
static KINFO *kinfo;
struct varent *vhead;
int eval; /* exit value */
int cflag; /* -c */
@ -91,9 +88,9 @@ static int forceuread=0;
static int forceuread=1;
#endif
enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT;
static enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT;
static char *fmt(char **(*)(kvm_t *, const struct kinfo_proc *, int),
static const char *fmt(char **(*)(kvm_t *, const struct kinfo_proc *, int),
KINFO *, char *, int);
static char *kludge_oldps_options(char *);
static int pscomp(const void *, const void *);
@ -104,16 +101,16 @@ static void sizevars(void);
static void usage(void);
static uid_t *getuids(const char *, int *);
char dfmt[] = "pid tt state time command";
char jfmt[] = "user pid ppid pgid jobc state tt time command";
char lfmt[] = "uid pid ppid cpu pri nice vsz rss wchan state tt time command";
char o1[] = "pid";
char o2[] = "tt state time command";
char ufmt[] = "user pid %cpu %mem vsz rss tt state start time command";
char vfmt[] = "pid state time sl re pagein vsz rss lim tsiz %cpu %mem command";
char Zfmt[] = "lvl";
static char dfmt[] = "pid tt state time command";
static char jfmt[] = "user pid ppid pgid jobc state tt time command";
static char lfmt[] = "uid pid ppid cpu pri nice vsz rss wchan state tt time command";
static char o1[] = "pid";
static char o2[] = "tt state time command";
static char ufmt[] = "user pid %cpu %mem vsz rss tt state start time command";
static char vfmt[] = "pid state time sl re pagein vsz rss lim tsiz %cpu %mem command";
static char Zfmt[] = "lvl";
kvm_t *kd;
static kvm_t *kd;
int
main(int argc, char *argv[])
@ -124,9 +121,10 @@ main(int argc, char *argv[])
dev_t ttydev;
pid_t pid;
uid_t *uids;
int all, ch, flag, i, fmt, lineno, nentries, dropgid;
int all, ch, flag, i, _fmt, lineno, nentries, dropgid;
int prtheader, wflag, what, xflg, uid, nuids;
char *nlistf, *memf, errbuf[_POSIX2_LINE_MAX];
char errbuf[_POSIX2_LINE_MAX];
const char *nlistf, *memf;
(void) setlocale(LC_ALL, "");
@ -141,7 +139,7 @@ main(int argc, char *argv[])
if (argc > 1)
argv[1] = kludge_oldps_options(argv[1]);
all = fmt = prtheader = wflag = xflg = 0;
all = _fmt = prtheader = wflag = xflg = 0;
pid = -1;
nuids = 0;
uids = NULL;
@ -174,7 +172,7 @@ main(int argc, char *argv[])
break;
case 'j':
parsefmt(jfmt);
fmt = 1;
_fmt = 1;
jfmt[0] = '\0';
break;
case 'L':
@ -182,7 +180,7 @@ main(int argc, char *argv[])
exit(0);
case 'l':
parsefmt(lfmt);
fmt = 1;
_fmt = 1;
lfmt[0] = '\0';
break;
case 'M':
@ -201,11 +199,11 @@ main(int argc, char *argv[])
parsefmt(optarg);
parsefmt(o2);
o1[0] = o2[0] = '\0';
fmt = 1;
_fmt = 1;
break;
case 'o':
parsefmt(optarg);
fmt = 1;
_fmt = 1;
break;
#if defined(LAZY_PS)
case 'f':
@ -232,7 +230,7 @@ main(int argc, char *argv[])
char *ttypath, pathbuf[PATH_MAX];
if (strcmp(optarg, "co") == 0)
ttypath = _PATH_CONSOLE;
ttypath = strdup(_PATH_CONSOLE);
else if (*optarg != '/')
(void)snprintf(ttypath = pathbuf,
sizeof(pathbuf), "%s%s", _PATH_TTY, optarg);
@ -252,13 +250,13 @@ main(int argc, char *argv[])
case 'u':
parsefmt(ufmt);
sortby = SORTCPU;
fmt = 1;
_fmt = 1;
ufmt[0] = '\0';
break;
case 'v':
parsefmt(vfmt);
sortby = SORTMEM;
fmt = 1;
_fmt = 1;
vfmt[0] = '\0';
break;
case 'w':
@ -304,7 +302,7 @@ main(int argc, char *argv[])
if (kd == 0)
errx(1, "%s", errbuf);
if (!fmt)
if (!_fmt)
parsefmt(dfmt);
/* XXX - should be cleaner */
@ -400,7 +398,8 @@ getuids(const char *arg, int *nuids)
char name[UT_NAMESIZE + 1];
struct passwd *pwd;
uid_t *uids, *moreuids;
int l, alloc;
int alloc;
size_t l;
alloc = 0;
@ -408,7 +407,7 @@ getuids(const char *arg, int *nuids)
uids = NULL;
for (; (l = strcspn(arg, SEP)) > 0; arg += l + strspn(arg + l, SEP)) {
if (l >= sizeof name) {
warnx("%.*s: name too long", l, arg);
warnx("%.*s: name too long", (int)l, arg);
continue;
}
strncpy(name, arg, l);
@ -491,14 +490,14 @@ sizevars(void)
totwidth--;
}
static char *
static const char *
fmt(char **(*fn)(kvm_t *, const struct kinfo_proc *, int), KINFO *ki,
char *comm, int maxlen)
{
char *s;
const char *s;
if ((s =
fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, maxlen)) == NULL)
s = fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, maxlen);
if (s == NULL)
err(1, NULL);
return (s);
}
@ -523,16 +522,15 @@ saveuser(KINFO *ki)
* save arguments if needed
*/
if (needcomm && (UREADOK(ki) || (ki->ki_p->ki_args != NULL))) {
ki->ki_args = fmt(kvm_getargv, ki, ki->ki_p->ki_comm,
MAXCOMLEN);
ki->ki_args = strdup(fmt(kvm_getargv, ki, ki->ki_p->ki_comm,
MAXCOMLEN));
} else if (needcomm) {
ki->ki_args = malloc(strlen(ki->ki_p->ki_comm) + 3);
sprintf(ki->ki_args, "(%s)", ki->ki_p->ki_comm);
asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm);
} else {
ki->ki_args = NULL;
}
if (needenv && UREADOK(ki)) {
ki->ki_env = fmt(kvm_getenvv, ki, (char *)NULL, 0);
ki->ki_env = strdup(fmt(kvm_getenvv, ki, (char *)NULL, 0));
} else if (needenv) {
ki->ki_env = malloc(3);
strcpy(ki->ki_env, "()");
@ -549,12 +547,12 @@ pscomp(const void *a, const void *b)
(k)->ki_p->ki_tsize)
if (sortby == SORTCPU)
return (getpcpu((KINFO *)b) - getpcpu((KINFO *)a));
return (getpcpu((const KINFO *)b) - getpcpu((const KINFO *)a));
if (sortby == SORTMEM)
return (VSIZE((KINFO *)b) - VSIZE((KINFO *)a));
i = ((KINFO *)a)->ki_p->ki_tdev - ((KINFO *)b)->ki_p->ki_tdev;
return (VSIZE((const KINFO *)b) - VSIZE((const KINFO *)a));
i = (int)((const KINFO *)a)->ki_p->ki_tdev - (int)((const KINFO *)b)->ki_p->ki_tdev;
if (i == 0)
i = ((KINFO *)a)->ki_p->ki_pid - ((KINFO *)b)->ki_p->ki_pid;
i = ((const KINFO *)a)->ki_p->ki_pid - ((const KINFO *)b)->ki_p->ki_pid;
return (i);
}

View File

@ -51,9 +51,9 @@ typedef struct varent {
} VARENT;
typedef struct var {
char *name; /* name(s) of variable */
char *header; /* default header */
char *alias; /* aliases */
const char *name; /* name(s) of variable */
const char *header; /* default header */
const char *alias; /* aliases */
#define COMM 0x01 /* needs exec arguments and environment (XXX) */
#define LJUST 0x02 /* left adjust on output (trailing blanks) */
#define USER 0x04 /* needs user structure */
@ -69,10 +69,9 @@ typedef struct var {
* to the generic output routine pvar (which prints simple elements
* from the well known kinfo_proc structure).
*/
int off; /* offset in structure */
off_t off; /* offset in structure */
enum type type; /* type of element */
char *fmt; /* printf format */
char *time; /* time format */
const char *fmt; /* printf format */
short dwidth; /* dynamic printing width */
/*
* glue to link selected fields together