svn commit: r235891 - stable/9/bin/ps
Edward Tomasz Napierala
trasz at FreeBSD.org
Thu May 24 10:20:23 UTC 2012
Author: trasz
Date: Thu May 24 10:20:23 2012
New Revision: 235891
URL: http://svn.freebsd.org/changeset/base/235891
Log:
MFC r225868:
Make ps(1) automatically size its column widths.
Modified:
stable/9/bin/ps/extern.h
stable/9/bin/ps/keyword.c
stable/9/bin/ps/print.c
stable/9/bin/ps/ps.c
stable/9/bin/ps/ps.h
Directory Properties:
stable/9/bin/ps/ (props changed)
Modified: stable/9/bin/ps/extern.h
==============================================================================
--- stable/9/bin/ps/extern.h Thu May 24 10:02:42 2012 (r235890)
+++ stable/9/bin/ps/extern.h Thu May 24 10:20:23 2012 (r235891)
@@ -39,63 +39,52 @@ extern fixpt_t ccpu;
extern int cflag, eval, fscale, nlistread, rawcpu;
extern unsigned long mempages;
extern time_t now;
-extern int showthreads, sumrusage, termwidth, totwidth;
+extern int showthreads, sumrusage, termwidth;
extern STAILQ_HEAD(velisthead, varent) varlist;
__BEGIN_DECLS
-void arguments(KINFO *, VARENT *);
-void command(KINFO *, VARENT *);
-void cputime(KINFO *, VARENT *);
+char *arguments(KINFO *, VARENT *);
+char *command(KINFO *, VARENT *);
+char *cputime(KINFO *, VARENT *);
int donlist(void);
-void elapsed(KINFO *, VARENT *);
-void elapseds(KINFO *, VARENT *);
-void emulname(KINFO *, VARENT *);
+char *elapsed(KINFO *, VARENT *);
+char *elapseds(KINFO *, VARENT *);
+char *emulname(KINFO *, VARENT *);
VARENT *find_varentry(VAR *);
const char *fmt_argv(char **, char *, size_t);
double getpcpu(const KINFO *);
-void kvar(KINFO *, VARENT *);
-void label(KINFO *, VARENT *);
-void loginclass(KINFO *, VARENT *);
-void logname(KINFO *, VARENT *);
-void longtname(KINFO *, VARENT *);
-void lstarted(KINFO *, VARENT *);
-void maxrss(KINFO *, VARENT *);
-void lockname(KINFO *, VARENT *);
-void mwchan(KINFO *, VARENT *);
-void nwchan(KINFO *, VARENT *);
-void pagein(KINFO *, VARENT *);
+char *kvar(KINFO *, VARENT *);
+char *label(KINFO *, VARENT *);
+char *loginclass(KINFO *, VARENT *);
+char *logname(KINFO *, VARENT *);
+char *longtname(KINFO *, VARENT *);
+char *lstarted(KINFO *, VARENT *);
+char *maxrss(KINFO *, VARENT *);
+char *lockname(KINFO *, VARENT *);
+char *mwchan(KINFO *, VARENT *);
+char *nwchan(KINFO *, VARENT *);
+char *pagein(KINFO *, VARENT *);
void parsefmt(const char *, int);
-void pcpu(KINFO *, VARENT *);
-void pmem(KINFO *, VARENT *);
-void pri(KINFO *, VARENT *);
+char *pcpu(KINFO *, VARENT *);
+char *pmem(KINFO *, VARENT *);
+char *pri(KINFO *, VARENT *);
void printheader(void);
-void priorityr(KINFO *, VARENT *);
-void egroupname(KINFO *, VARENT *);
-void rgroupname(KINFO *, VARENT *);
-void runame(KINFO *, VARENT *);
-void rvar(KINFO *, VARENT *);
-int s_comm(KINFO *);
-int s_cputime(KINFO *);
-int s_label(KINFO *);
-int s_loginclass(KINFO *);
-int s_logname(KINFO *);
-int s_egroupname(KINFO *);
-int s_rgroupname(KINFO *);
-int s_runame(KINFO *);
-int s_systime(KINFO *);
-int s_uname(KINFO *);
-int s_usertime(KINFO *);
+char *priorityr(KINFO *, VARENT *);
+char *egroupname(KINFO *, VARENT *);
+char *rgroupname(KINFO *, VARENT *);
+char *runame(KINFO *, VARENT *);
+char *rvar(KINFO *, VARENT *);
void showkey(void);
-void started(KINFO *, VARENT *);
-void state(KINFO *, VARENT *);
-void systime(KINFO *, VARENT *);
-void tdev(KINFO *, VARENT *);
-void tdnam(KINFO *, VARENT *);
-void tname(KINFO *, VARENT *);
-void ucomm(KINFO *, VARENT *);
-void uname(KINFO *, VARENT *);
-void upr(KINFO *, VARENT *);
-void usertime(KINFO *, VARENT *);
-void vsize(KINFO *, VARENT *);
-void wchan(KINFO *, VARENT *);
+char *started(KINFO *, VARENT *);
+char *state(KINFO *, VARENT *);
+char *systime(KINFO *, VARENT *);
+char *tdev(KINFO *, VARENT *);
+char *tdnam(KINFO *, VARENT *);
+char *tname(KINFO *, VARENT *);
+char *ucomm(KINFO *, VARENT *);
+char *uname(KINFO *, VARENT *);
+char *upr(KINFO *, VARENT *);
+char *usertime(KINFO *, VARENT *);
+char *vsize(KINFO *, VARENT *);
+char *wchan(KINFO *, VARENT *);
__END_DECLS
Modified: stable/9/bin/ps/keyword.c
==============================================================================
--- stable/9/bin/ps/keyword.c Thu May 24 10:02:42 2012 (r235890)
+++ stable/9/bin/ps/keyword.c Thu May 24 10:20:23 2012 (r235891)
@@ -57,178 +57,116 @@ static int vcmp(const void *, const voi
#define KOFF(x) offsetof(struct kinfo_proc, x)
#define ROFF(x) offsetof(struct rusage, x)
-#define EMULLEN 13 /* enough for "FreeBSD ELF32" */
#define LWPFMT "d"
-#define LWPLEN 6
#define NLWPFMT "d"
-#define NLWPLEN 4
#define UIDFMT "u"
-#define UIDLEN 5
#define PIDFMT "d"
-#define PIDLEN 5
-#define USERLEN (MAXLOGNAME - 1)
/* PLEASE KEEP THE TABLE BELOW SORTED ALPHABETICALLY!!! */
static VAR var[] = {
- {"%cpu", "%CPU", NULL, 0, pcpu, NULL, 5, 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},
- {"args", "COMMAND", NULL, COMM|LJUST|USER, arguments, NULL, 16, 0,
+ {"%cpu", "%CPU", NULL, 0, pcpu, 0, CHAR, NULL, 0},
+ {"%mem", "%MEM", NULL, 0, pmem, 0, CHAR, NULL, 0},
+ {"acflag", "ACFLG", NULL, 0, kvar, KOFF(ki_acflag), USHORT, "x", 0},
+ {"acflg", "", "acflag", 0, NULL, 0, CHAR, NULL, 0},
+ {"args", "COMMAND", NULL, COMM|LJUST|USER, arguments, 0,
CHAR, NULL, 0},
- {"blocked", "", "sigmask", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
- {"caught", "", "sigcatch", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
- {"class", "CLASS", NULL, LJUST, loginclass, s_loginclass,
- MAXLOGNAME-1, 0, CHAR, NULL, 0},
- {"comm", "COMMAND", NULL, LJUST, ucomm, s_comm,
- COMMLEN + TDNAMLEN + 1, 0, CHAR, NULL, 0},
- {"command", "COMMAND", NULL, COMM|LJUST|USER, command, NULL, 16, 0,
+ {"blocked", "", "sigmask", 0, NULL, 0, CHAR, NULL, 0},
+ {"caught", "", "sigcatch", 0, NULL, 0, CHAR, NULL, 0},
+ {"class", "CLASS", NULL, LJUST, loginclass, 0, CHAR, NULL, 0},
+ {"comm", "COMMAND", NULL, LJUST, ucomm, 0, CHAR, NULL, 0},
+ {"command", "COMMAND", NULL, COMM|LJUST|USER, command, 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},
- {"egid", "", "gid", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
- {"egroup", "", "group", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
- {"emul", "EMUL", NULL, LJUST, emulname, NULL, EMULLEN, 0, CHAR,
- NULL, 0},
- {"etime", "ELAPSED", NULL, USER, elapsed, NULL, 12, 0, CHAR, NULL, 0},
- {"etimes", "ELAPSED", NULL, USER, elapseds, NULL, 12, 0, CHAR, NULL, 0},
- {"euid", "", "uid", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
- {"f", "F", NULL, 0, kvar, NULL, 8, KOFF(ki_flag), INT, "x", 0},
- {"flags", "", "f", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
- {"gid", "GID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_groups),
- UINT, UIDFMT, 0},
- {"group", "GROUP", NULL, LJUST, egroupname, s_egroupname,
- USERLEN, 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},
- {"jid", "JID", NULL, 0, kvar, NULL, 6, KOFF(ki_jid), INT, "d", 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},
- {"label", "LABEL", NULL, LJUST, label, s_label, SHRT_MAX, 0, CHAR,
- NULL, 0},
- {"lim", "LIM", NULL, 0, maxrss, NULL, 5, 0, CHAR, NULL, 0},
- {"lockname", "LOCK", NULL, LJUST, lockname, NULL, 6, 0, CHAR, NULL,
- 0},
- {"login", "LOGIN", NULL, LJUST, logname, s_logname, 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},
- {"lwp", "LWP", NULL, 0, kvar, NULL, LWPLEN, KOFF(ki_tid), UINT,
- LWPFMT, 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},
- {"mwchan", "MWCHAN", NULL, LJUST, mwchan, 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},
- {"nlwp", "NLWP", NULL, 0, kvar, NULL, NLWPLEN, KOFF(ki_numthreads),
- UINT, NLWPFMT, 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},
- {"nwchan", "NWCHAN", NULL, LJUST, nwchan, NULL, sizeof(void *) * 2, 0,
- CHAR, NULL, 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, sizeof(void *) * 2,
- 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, INF127, kvar, NULL, 3, KOFF(ki_swtime), UINT, "d",
- 0},
- {"rgid", "RGID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_rgid),
- UINT, UIDFMT, 0},
- {"rgroup", "RGROUP", NULL, LJUST, rgroupname, s_rgroupname,
- USERLEN, 0, CHAR, NULL, 0},
- {"rss", "RSS", NULL, 0, kvar, NULL, 6, KOFF(ki_rssize), PGTOK, "ld", 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, 0},
- {"ruser", "RUSER", NULL, LJUST, runame, s_runame, USERLEN,
- 0, CHAR, NULL, 0},
- {"sid", "SID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_sid), UINT,
- 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),
+ {"cpu", "CPU", NULL, 0, kvar, KOFF(ki_estcpu), UINT, "d", 0},
+ {"cputime", "", "time", 0, NULL, 0, CHAR, NULL, 0},
+ {"egid", "", "gid", 0, NULL, 0, CHAR, NULL, 0},
+ {"egroup", "", "group", 0, NULL, 0, CHAR, NULL, 0},
+ {"emul", "EMUL", NULL, LJUST, emulname, 0, CHAR, NULL, 0},
+ {"etime", "ELAPSED", NULL, USER, elapsed, 0, CHAR, NULL, 0},
+ {"etimes", "ELAPSED", NULL, USER, elapseds, 0, CHAR, NULL, 0},
+ {"euid", "", "uid", 0, NULL, 0, CHAR, NULL, 0},
+ {"f", "F", NULL, 0, kvar, KOFF(ki_flag), INT, "x", 0},
+ {"flags", "", "f", 0, NULL, 0, CHAR, NULL, 0},
+ {"gid", "GID", NULL, 0, kvar, KOFF(ki_groups), UINT, UIDFMT, 0},
+ {"group", "GROUP", NULL, LJUST, egroupname, 0, CHAR, NULL, 0},
+ {"ignored", "", "sigignore", 0, NULL, 0, CHAR, NULL, 0},
+ {"inblk", "INBLK", NULL, USER, rvar, ROFF(ru_inblock), LONG, "ld", 0},
+ {"inblock", "", "inblk", 0, NULL, 0, CHAR, NULL, 0},
+ {"jid", "JID", NULL, 0, kvar, KOFF(ki_jid), INT, "d", 0},
+ {"jobc", "JOBC", NULL, 0, kvar, KOFF(ki_jobc), SHORT, "d", 0},
+ {"ktrace", "KTRACE", NULL, 0, kvar, KOFF(ki_traceflag), INT, "x", 0},
+ {"label", "LABEL", NULL, LJUST, label, 0, CHAR, NULL, 0},
+ {"lim", "LIM", NULL, 0, maxrss, 0, CHAR, NULL, 0},
+ {"lockname", "LOCK", NULL, LJUST, lockname, 0, CHAR, NULL, 0},
+ {"login", "LOGIN", NULL, LJUST, logname, 0, CHAR, NULL, 0},
+ {"logname", "", "login", 0, NULL, 0, CHAR, NULL, 0},
+ {"lstart", "STARTED", NULL, LJUST|USER, lstarted, 0, CHAR, NULL, 0},
+ {"lwp", "LWP", NULL, 0, kvar, KOFF(ki_tid), UINT, LWPFMT, 0},
+ {"majflt", "MAJFLT", NULL, USER, rvar, ROFF(ru_majflt), LONG, "ld", 0},
+ {"minflt", "MINFLT", NULL, USER, rvar, ROFF(ru_minflt), LONG, "ld", 0},
+ {"msgrcv", "MSGRCV", NULL, USER, rvar, ROFF(ru_msgrcv), LONG, "ld", 0},
+ {"msgsnd", "MSGSND", NULL, USER, rvar, ROFF(ru_msgsnd), LONG, "ld", 0},
+ {"mwchan", "MWCHAN", NULL, LJUST, mwchan, 0, CHAR, NULL, 0},
+ {"ni", "", "nice", 0, NULL, 0, CHAR, NULL, 0},
+ {"nice", "NI", NULL, 0, kvar, KOFF(ki_nice), CHAR, "d", 0},
+ {"nivcsw", "NIVCSW", NULL, USER, rvar, ROFF(ru_nivcsw), LONG, "ld", 0},
+ {"nlwp", "NLWP", NULL, 0, kvar, KOFF(ki_numthreads), UINT, NLWPFMT, 0},
+ {"nsignals", "", "nsigs", 0, NULL, 0, CHAR, NULL, 0},
+ {"nsigs", "NSIGS", NULL, USER, rvar, ROFF(ru_nsignals), LONG, "ld", 0},
+ {"nswap", "NSWAP", NULL, USER, rvar, ROFF(ru_nswap), LONG, "ld", 0},
+ {"nvcsw", "NVCSW", NULL, USER, rvar, ROFF(ru_nvcsw), LONG, "ld", 0},
+ {"nwchan", "NWCHAN", NULL, LJUST, nwchan, 0, CHAR, NULL, 0},
+ {"oublk", "OUBLK", NULL, USER, rvar, ROFF(ru_oublock), LONG, "ld", 0},
+ {"oublock", "", "oublk", 0, NULL, 0, CHAR, NULL, 0},
+ {"paddr", "PADDR", NULL, 0, kvar, KOFF(ki_paddr), KPTR, "lx", 0},
+ {"pagein", "PAGEIN", NULL, USER, pagein, 0, CHAR, NULL, 0},
+ {"pcpu", "", "%cpu", 0, NULL, 0, CHAR, NULL, 0},
+ {"pending", "", "sig", 0, NULL, 0, CHAR, NULL, 0},
+ {"pgid", "PGID", NULL, 0, kvar, KOFF(ki_pgid), UINT, PIDFMT, 0},
+ {"pid", "PID", NULL, 0, kvar, KOFF(ki_pid), UINT, PIDFMT, 0},
+ {"pmem", "", "%mem", 0, NULL, 0, CHAR, NULL, 0},
+ {"ppid", "PPID", NULL, 0, kvar, KOFF(ki_ppid), UINT, PIDFMT, 0},
+ {"pri", "PRI", NULL, 0, pri, 0, CHAR, NULL, 0},
+ {"re", "RE", NULL, INF127, kvar, KOFF(ki_swtime), UINT, "d", 0},
+ {"rgid", "RGID", NULL, 0, kvar, KOFF(ki_rgid), UINT, UIDFMT, 0},
+ {"rgroup", "RGROUP", NULL, LJUST, rgroupname, 0, CHAR, NULL, 0},
+ {"rss", "RSS", NULL, 0, kvar, KOFF(ki_rssize), PGTOK, "ld", 0},
+ {"rtprio", "RTPRIO", NULL, 0, priorityr, KOFF(ki_pri), CHAR, NULL, 0},
+ {"ruid", "RUID", NULL, 0, kvar, KOFF(ki_ruid), UINT, UIDFMT, 0},
+ {"ruser", "RUSER", NULL, LJUST, runame, 0, CHAR, NULL, 0},
+ {"sid", "SID", NULL, 0, kvar, KOFF(ki_sid), UINT, PIDFMT, 0},
+ {"sig", "PENDING", NULL, 0, kvar, KOFF(ki_siglist), INT, "x", 0},
+ {"sigcatch", "CAUGHT", NULL, 0, kvar, KOFF(ki_sigcatch), UINT, "x", 0},
+ {"sigignore", "IGNORED", NULL, 0, kvar, KOFF(ki_sigignore),
UINT, "x", 0},
- {"sigmask", "BLOCKED", NULL, 0, kvar, NULL, 8, KOFF(ki_sigmask),
- UINT, "x", 0},
- {"sl", "SL", NULL, INF127, 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},
- {"systime", "SYSTIME", NULL, USER, systime, s_systime, 15, 0, CHAR,
- NULL, 0},
- {"tdaddr", "TDADDR", NULL, 0, kvar, NULL, sizeof(void *) * 2,
- KOFF(ki_tdaddr), KPTR, "lx", 0},
- {"tdev", "TDEV", NULL, 0, tdev, NULL, 5, 0, CHAR, NULL, 0},
- {"tdnam", "TDNAM", NULL, LJUST, tdnam, NULL, COMMLEN, 0, CHAR, NULL, 0},
- {"time", "TIME", NULL, USER, cputime, s_cputime, 15, 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, 0},
- {"tsiz", "TSIZ", NULL, 0, kvar, NULL, 4, KOFF(ki_tsize), PGTOK, "ld", 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, s_comm,
- COMMLEN + TDNAMLEN + 1, 0, CHAR, NULL, 0},
- {"uid", "UID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_uid), UINT,
- UIDFMT, 0},
- {"upr", "UPR", NULL, 0, upr, NULL, 3, 0, CHAR, NULL, 0},
- {"uprocp", "UPROCP", NULL, 0, kvar, NULL, sizeof(void *) * 2,
- KOFF(ki_paddr), KPTR, "lx", 0},
- {"user", "USER", NULL, LJUST, uname, s_uname, USERLEN, 0, CHAR,
- NULL, 0},
- {"usertime", "USERTIME", NULL, USER, usertime, s_usertime, 15, 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, 6, 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},
+ {"sigmask", "BLOCKED", NULL, 0, kvar, KOFF(ki_sigmask), UINT, "x", 0},
+ {"sl", "SL", NULL, INF127, kvar, KOFF(ki_slptime), UINT, "d", 0},
+ {"start", "STARTED", NULL, LJUST|USER, started, 0, CHAR, NULL, 0},
+ {"stat", "", "state", 0, NULL, 0, CHAR, NULL, 0},
+ {"state", "STAT", NULL, LJUST, state, 0, CHAR, NULL, 0},
+ {"svgid", "SVGID", NULL, 0, kvar, KOFF(ki_svgid), UINT, UIDFMT, 0},
+ {"svuid", "SVUID", NULL, 0, kvar, KOFF(ki_svuid), UINT, UIDFMT, 0},
+ {"systime", "SYSTIME", NULL, USER, systime, 0, CHAR, NULL, 0},
+ {"tdaddr", "TDADDR", NULL, 0, kvar, KOFF(ki_tdaddr), KPTR, "lx", 0},
+ {"tdev", "TDEV", NULL, 0, tdev, 0, CHAR, NULL, 0},
+ {"tdnam", "TDNAM", NULL, LJUST, tdnam, 0, CHAR, NULL, 0},
+ {"time", "TIME", NULL, USER, cputime, 0, CHAR, NULL, 0},
+ {"tpgid", "TPGID", NULL, 0, kvar, KOFF(ki_tpgid), UINT, PIDFMT, 0},
+ {"tsid", "TSID", NULL, 0, kvar, KOFF(ki_tsid), UINT, PIDFMT, 0},
+ {"tsiz", "TSIZ", NULL, 0, kvar, KOFF(ki_tsize), PGTOK, "ld", 0},
+ {"tt", "TT ", NULL, 0, tname, 0, CHAR, NULL, 0},
+ {"tty", "TTY", NULL, LJUST, longtname, 0, CHAR, NULL, 0},
+ {"ucomm", "UCOMM", NULL, LJUST, ucomm, 0, CHAR, NULL, 0},
+ {"uid", "UID", NULL, 0, kvar, KOFF(ki_uid), UINT, UIDFMT, 0},
+ {"upr", "UPR", NULL, 0, upr, 0, CHAR, NULL, 0},
+ {"uprocp", "UPROCP", NULL, 0, kvar, KOFF(ki_paddr), KPTR, "lx", 0},
+ {"user", "USER", NULL, LJUST, uname, 0, CHAR, NULL, 0},
+ {"usertime", "USERTIME", NULL, USER, usertime, 0, CHAR, NULL, 0},
+ {"usrpri", "", "upr", 0, NULL, 0, CHAR, NULL, 0},
+ {"vsize", "", "vsz", 0, NULL, 0, CHAR, NULL, 0},
+ {"vsz", "VSZ", NULL, 0, vsize, 0, CHAR, NULL, 0},
+ {"wchan", "WCHAN", NULL, LJUST, wchan, 0, CHAR, NULL, 0},
+ {"xstat", "XSTAT", NULL, 0, kvar, KOFF(ki_xstat), USHORT, "x", 0},
+ {"", NULL, NULL, 0, NULL, 0, CHAR, NULL, 0},
};
void
Modified: stable/9/bin/ps/print.c
==============================================================================
--- stable/9/bin/ps/print.c Thu May 24 10:02:42 2012 (r235890)
+++ stable/9/bin/ps/print.c Thu May 24 10:20:23 2012 (r235891)
@@ -64,6 +64,9 @@ __FBSDID("$FreeBSD$");
#include "ps.h"
+#define COMMAND_WIDTH 16
+#define ARGUMENTS_WIDTH 16
+
#define ps_pgtok(a) (((a) * getpagesize()) / 1024)
void
@@ -93,53 +96,42 @@ printheader(void)
(void)putchar('\n');
}
-void
+char *
arguments(KINFO *k, VARENT *ve)
{
VAR *v;
- int left;
- char *cp, *vis_args;
+ char *vis_args;
v = ve->var;
if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
errx(1, "malloc failed");
strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
- if (STAILQ_NEXT(ve, next_ve) == NULL) {
- /* last field */
- if (termwidth == UNLIMITED) {
- (void)printf("%s", vis_args);
- } else {
- left = termwidth - (totwidth - v->width);
- if (left < 1) /* already wrapped, just use std width */
- left = v->width;
- for (cp = vis_args; --left >= 0 && *cp != '\0';)
- (void)putchar(*cp++);
- }
- } else {
- (void)printf("%-*.*s", v->width, v->width, vis_args);
- }
- free(vis_args);
+
+ if (STAILQ_NEXT(ve, next_ve) != NULL && strlen(vis_args) > ARGUMENTS_WIDTH)
+ vis_args[ARGUMENTS_WIDTH] = '\0';
+
+ return (vis_args);
}
-void
+char *
command(KINFO *k, VARENT *ve)
{
VAR *v;
- int left;
- char *cp, *vis_env, *vis_args;
+ char *vis_args, *vis_env, *str;
v = ve->var;
if (cflag) {
/* If it is the last field, then don't pad */
if (STAILQ_NEXT(ve, next_ve) == NULL) {
- if (k->ki_d.prefix)
- (void)printf("%s", k->ki_d.prefix);
- (void)printf("%s", k->ki_p->ki_comm);
- if (showthreads && k->ki_p->ki_numthreads > 1)
- (void)printf("/%s", k->ki_p->ki_tdname);
+ asprintf(&str, "%s%s%s%s",
+ k->ki_d.prefix ? k->ki_d.prefix : "",
+ k->ki_p->ki_comm,
+ (showthreads && k->ki_p->ki_numthreads > 1) ? "/" : "",
+ (showthreads && k->ki_p->ki_numthreads > 1) ? k->ki_p->ki_tdname : "");
} else
- (void)printf("%-*s", v->width, k->ki_p->ki_comm);
- return;
+ str = strdup(k->ki_p->ki_comm);
+
+ return (str);
}
if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
errx(1, "malloc failed");
@@ -157,89 +149,84 @@ command(KINFO *k, VARENT *ve)
} else
vis_env = NULL;
- if (termwidth == UNLIMITED) {
- if (k->ki_d.prefix)
- (void)printf("%s", k->ki_d.prefix);
- if (vis_env)
- (void)printf("%s ", vis_env);
- (void)printf("%s", vis_args);
- } else {
- left = termwidth - (totwidth - v->width);
- if (left < 1) /* already wrapped, just use std width */
- left = v->width;
- if ((cp = k->ki_d.prefix) != NULL)
- while (--left >= 0 && *cp)
- (void)putchar(*cp++);
- if ((cp = vis_env) != NULL) {
- while (--left >= 0 && *cp)
- (void)putchar(*cp++);
- if (--left >= 0)
- putchar(' ');
- }
- for (cp = vis_args; --left >= 0 && *cp != '\0';)
- (void)putchar(*cp++);
- }
+ asprintf(&str, "%s%s%s%s",
+ k->ki_d.prefix ? k->ki_d.prefix : "",
+ vis_env ? vis_env : "",
+ vis_env ? " " : "",
+ vis_args);
+
if (vis_env != NULL)
free(vis_env);
- } else
+ free(vis_args);
+ } else {
/* ki_d.prefix & ki_env aren't shown for interim fields */
- (void)printf("%-*.*s", v->width, v->width, vis_args);
- free(vis_args);
+ str = vis_args;
+
+ if (strlen(str) > COMMAND_WIDTH)
+ str[COMMAND_WIDTH] = '\0';
+ }
+
+ return (str);
}
-void
+char *
ucomm(KINFO *k, VARENT *ve)
{
- char tmpbuff[COMMLEN + TDNAMLEN + 2];
VAR *v;
+ char *str;
v = ve->var;
if (STAILQ_NEXT(ve, next_ve) == NULL) { /* last field, don't pad */
- if (k->ki_d.prefix)
- (void)printf("%s", k->ki_d.prefix);
- (void)printf("%s", k->ki_p->ki_comm);
- if (showthreads && k->ki_p->ki_numthreads > 1)
- printf("/%s", k->ki_p->ki_tdname);
+ asprintf(&str, "%s%s%s%s",
+ k->ki_d.prefix ? k->ki_d.prefix : "",
+ k->ki_p->ki_comm,
+ (showthreads && k->ki_p->ki_numthreads > 1) ? "/" : "",
+ (showthreads && k->ki_p->ki_numthreads > 1) ? k->ki_p->ki_tdname : "");
} else {
- bzero(tmpbuff, sizeof(tmpbuff));
if (showthreads && k->ki_p->ki_numthreads > 1)
- sprintf(tmpbuff, "%s/%s", k->ki_p->ki_comm,
- k->ki_p->ki_tdname);
+ asprintf(&str, "%s/%s", k->ki_p->ki_comm, k->ki_p->ki_tdname);
else
- sprintf(tmpbuff, "%s", k->ki_p->ki_comm);
- (void)printf("%-*s", v->width, tmpbuff);
+ str = strdup(k->ki_p->ki_comm);
}
+ return (str);
}
-void
+char *
tdnam(KINFO *k, VARENT *ve)
{
VAR *v;
+ char *str;
v = ve->var;
if (showthreads && k->ki_p->ki_numthreads > 1)
- (void)printf("%-*s", v->width, k->ki_p->ki_tdname);
+ str = strdup(k->ki_p->ki_tdname);
else
- (void)printf("%-*s", v->width, " ");
+ str = strdup(" ");
+
+ return (str);
}
-void
+char *
logname(KINFO *k, VARENT *ve)
{
VAR *v;
- char *s;
v = ve->var;
- (void)printf("%-*s", v->width, (s = k->ki_p->ki_login, *s) ? s : "-");
+ if (*k->ki_p->ki_login == '\0')
+ return (NULL);
+ return (strdup(k->ki_p->ki_login));
}
-void
+char *
state(KINFO *k, VARENT *ve)
{
int flag, tdflags;
- char *cp;
+ char *cp, *buf;
VAR *v;
- char buf[16];
+
+ buf = malloc(16);
+ if (buf == NULL)
+ errx(1, "malloc failed");
v = ve->var;
flag = k->ki_p->ki_flag;
@@ -301,278 +288,270 @@ state(KINFO *k, VARENT *ve)
if (flag & P_JAILED)
*cp++ = 'J';
*cp = '\0';
- (void)printf("%-*s", v->width, buf);
+ return (buf);
}
#define scalepri(x) ((x) - PZERO)
-void
+char *
pri(KINFO *k, VARENT *ve)
{
VAR *v;
+ char *str;
v = ve->var;
- (void)printf("%*d", v->width, scalepri(k->ki_p->ki_pri.pri_level));
+ asprintf(&str, "%d", scalepri(k->ki_p->ki_pri.pri_level));
+ return (str);
}
-void
+char *
upr(KINFO *k, VARENT *ve)
{
VAR *v;
+ char *str;
v = ve->var;
- (void)printf("%*d", v->width, scalepri(k->ki_p->ki_pri.pri_user));
+ asprintf(&str, "%d", scalepri(k->ki_p->ki_pri.pri_user));
+ return (str);
}
#undef scalepri
-void
+char *
uname(KINFO *k, VARENT *ve)
{
VAR *v;
v = ve->var;
- (void)printf("%-*s", v->width, user_from_uid(k->ki_p->ki_uid, 0));
-}
-
-int
-s_uname(KINFO *k)
-{
- return (strlen(user_from_uid(k->ki_p->ki_uid, 0)));
+ return (strdup(user_from_uid(k->ki_p->ki_uid, 0)));
}
-void
+char *
egroupname(KINFO *k, VARENT *ve)
{
VAR *v;
v = ve->var;
- (void)printf("%-*s", v->width,
- group_from_gid(k->ki_p->ki_groups[0], 0));
-}
-
-int
-s_egroupname(KINFO *k)
-{
- return (strlen(group_from_gid(k->ki_p->ki_groups[0], 0)));
+ return (strdup(group_from_gid(k->ki_p->ki_groups[0], 0)));
}
-void
+char *
rgroupname(KINFO *k, VARENT *ve)
{
VAR *v;
v = ve->var;
- (void)printf("%-*s", v->width, group_from_gid(k->ki_p->ki_rgid, 0));
-}
-
-int
-s_rgroupname(KINFO *k)
-{
- return (strlen(group_from_gid(k->ki_p->ki_rgid, 0)));
+ return (strdup(group_from_gid(k->ki_p->ki_rgid, 0)));
}
-void
+char *
runame(KINFO *k, VARENT *ve)
{
VAR *v;
v = ve->var;
- (void)printf("%-*s", v->width, user_from_uid(k->ki_p->ki_ruid, 0));
+ return (strdup(user_from_uid(k->ki_p->ki_ruid, 0)));
}
-int
-s_runame(KINFO *k)
-{
- return (strlen(user_from_uid(k->ki_p->ki_ruid, 0)));
-}
-
-
-void
+char *
tdev(KINFO *k, VARENT *ve)
{
VAR *v;
dev_t dev;
- char buff[16];
+ char *str;
v = ve->var;
dev = k->ki_p->ki_tdev;
if (dev == NODEV)
- (void)printf("%*s", v->width, "??");
- else {
- (void)snprintf(buff, sizeof(buff),
- "%d/%d", major(dev), minor(dev));
- (void)printf("%*s", v->width, buff);
- }
+ str = strdup("??");
+ else
+ asprintf(&str, "%d/%d", major(dev), minor(dev));
+
+ return (str);
}
-void
+char *
tname(KINFO *k, VARENT *ve)
{
VAR *v;
dev_t dev;
- char *ttname;
+ char *ttname, *str;
v = ve->var;
dev = k->ki_p->ki_tdev;
if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
- (void)printf("%*s ", v->width - 1, "??");
+ str = strdup("?? ");
else {
if (strncmp(ttname, "tty", 3) == 0 ||
strncmp(ttname, "cua", 3) == 0)
ttname += 3;
if (strncmp(ttname, "pts/", 4) == 0)
ttname += 4;
- (void)printf("%*.*s%c", v->width - 1, v->width - 1, ttname,
+ asprintf(&str, "%s%c", ttname,
k->ki_p->ki_kiflag & KI_CTTY ? ' ' : '-');
}
+
+ return (str);
}
-void
+char *
longtname(KINFO *k, VARENT *ve)
{
VAR *v;
dev_t dev;
- char *ttname;
+ const char *ttname;
v = ve->var;
dev = k->ki_p->ki_tdev;
if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
- (void)printf("%-*s", v->width, "??");
- else
- (void)printf("%-*s", v->width, ttname);
+ ttname = "??";
+
+ return (strdup(ttname));
}
-void
+char *
started(KINFO *k, VARENT *ve)
{
VAR *v;
time_t then;
struct tm *tp;
static int use_ampm = -1;
- char buf[100];
+ size_t buflen = 100;
+ char *buf;
+
+ buf = malloc(buflen);
+ if (buf == NULL)
+ errx(1, "malloc failed");
v = ve->var;
- if (!k->ki_valid) {
- (void)printf("%-*s", v->width, "-");
- return;
- }
+ if (!k->ki_valid)
+ return (NULL);
if (use_ampm < 0)
use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');
then = k->ki_p->ki_start.tv_sec;
tp = localtime(&then);
if (now - k->ki_p->ki_start.tv_sec < 24 * 3600) {
- (void)strftime(buf, sizeof(buf),
+ (void)strftime(buf, buflen,
use_ampm ? "%l:%M%p" : "%k:%M ", tp);
} else if (now - k->ki_p->ki_start.tv_sec < 7 * 86400) {
- (void)strftime(buf, sizeof(buf),
+ (void)strftime(buf, buflen,
use_ampm ? "%a%I%p" : "%a%H ", tp);
} else
- (void)strftime(buf, sizeof(buf), "%e%b%y", tp);
- (void)printf("%-*s", v->width, buf);
+ (void)strftime(buf, buflen, "%e%b%y", tp);
+ return (buf);
}
-void
+char *
lstarted(KINFO *k, VARENT *ve)
{
VAR *v;
time_t then;
- char buf[100];
+ char *buf;
+ size_t buflen = 100;
+
+ buf = malloc(buflen);
+ if (buf == NULL)
+ errx(1, "malloc failed");
v = ve->var;
- if (!k->ki_valid) {
- (void)printf("%-*s", v->width, "-");
- return;
- }
+ if (!k->ki_valid)
+ return (NULL);
then = k->ki_p->ki_start.tv_sec;
- (void)strftime(buf, sizeof(buf), "%c", localtime(&then));
- (void)printf("%-*s", v->width, buf);
+ (void)strftime(buf, buflen, "%c", localtime(&then));
+ return (buf);
}
-void
+char *
lockname(KINFO *k, VARENT *ve)
{
VAR *v;
+ char *str;
v = ve->var;
if (k->ki_p->ki_kiflag & KI_LOCKBLOCK) {
if (k->ki_p->ki_lockname[0] != 0)
- (void)printf("%-*.*s", v->width, v->width,
- k->ki_p->ki_lockname);
+ str = strdup(k->ki_p->ki_lockname);
else
- (void)printf("%-*s", v->width, "???");
+ str = strdup("???");
} else
- (void)printf("%-*s", v->width, "-");
+ str = NULL;
+
+ return (str);
}
-void
+char *
wchan(KINFO *k, VARENT *ve)
{
VAR *v;
+ char *str;
v = ve->var;
if (k->ki_p->ki_wchan) {
if (k->ki_p->ki_wmesg[0] != 0)
- (void)printf("%-*.*s", v->width, v->width,
- k->ki_p->ki_wmesg);
+ str = strdup(k->ki_p->ki_wmesg);
else
- (void)printf("%-*lx", v->width,
- (long)k->ki_p->ki_wchan);
+ asprintf(&str, "%lx", (long)k->ki_p->ki_wchan);
} else
- (void)printf("%-*s", v->width, "-");
+ str = NULL;
+
+ return (str);
}
-void
+char *
nwchan(KINFO *k, VARENT *ve)
{
VAR *v;
+ char *str;
v = ve->var;
- if (k->ki_p->ki_wchan) {
- (void)printf("%0*lx", v->width,
- (long)k->ki_p->ki_wchan);
- } else
- (void)printf("%-*s", v->width, "-");
+ if (k->ki_p->ki_wchan)
+ asprintf(&str, "%0lx", (long)k->ki_p->ki_wchan);
+ else
+ str = NULL;
+
+ return (str);
}
-void
+char *
mwchan(KINFO *k, VARENT *ve)
{
VAR *v;
+ char *str;
v = ve->var;
if (k->ki_p->ki_wchan) {
if (k->ki_p->ki_wmesg[0] != 0)
- (void)printf("%-*.*s", v->width, v->width,
- k->ki_p->ki_wmesg);
+ str = strdup(k->ki_p->ki_wmesg);
else
- (void)printf("%-*lx", v->width,
- (long)k->ki_p->ki_wchan);
+ asprintf(&str, "%lx", (long)k->ki_p->ki_wchan);
} else if (k->ki_p->ki_kiflag & KI_LOCKBLOCK) {
if (k->ki_p->ki_lockname[0]) {
- (void)printf("%-*.*s", v->width, v->width,
- k->ki_p->ki_lockname);
+ str = strdup(k->ki_p->ki_lockname);
} else
- (void)printf("%-*s", v->width, "???");
+ str = strdup("???");
} else
- (void)printf("%-*s", v->width, "-");
+ str = NULL;
+
+ return (str);
}
-void
+char *
vsize(KINFO *k, VARENT *ve)
{
VAR *v;
+ char *str;
v = ve->var;
- (void)printf("%*lu", v->width, (u_long)(k->ki_p->ki_size / 1024));
+ asprintf(&str, "%lu", (u_long)(k->ki_p->ki_size / 1024));
+ return (str);
}
-static void
+static char *
printtime(KINFO *k, VARENT *ve, long secs, long psecs)
/* psecs is "parts" of a second. first micro, then centi */
{
VAR *v;
- char obuff[128];
static char decimal_point;
+ char *str;
if (decimal_point == '\0')
decimal_point = localeconv()->decimal_point[0];
@@ -586,21 +565,12 @@ printtime(KINFO *k, VARENT *ve, long sec
secs += psecs / 100;
psecs = psecs % 100;
}
- (void)snprintf(obuff, sizeof(obuff), "%ld:%02ld%c%02ld",
+ asprintf(&str, "%ld:%02ld%c%02ld",
secs / 60, secs % 60, decimal_point, psecs);
- (void)printf("%*s", v->width, obuff);
+ return (str);
}
-static int
-sizetime(long secs)
-{
-
- if (secs < 60)
- return (7);
- return (log10(secs / 60) + 7);
-}
-
-void
+char *
cputime(KINFO *k, VARENT *ve)
{
long secs, psecs;
@@ -616,10 +586,10 @@ cputime(KINFO *k, VARENT *ve)
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-stable-9
mailing list