Index: usr.bin/procstat/procstat.h =================================================================== --- usr.bin/procstat/procstat.h +++ usr.bin/procstat/procstat.h @@ -35,23 +35,34 @@ #define PROCSTAT_XO_VERSION "1" -extern int hflag, nflag, Cflag, Hflag; +enum { + PS_OPT_CAPABILITIES = 0x01, + PS_OPT_NOHEADER = 0x02, + PS_OPT_PERTHREAD = 0x04, + PS_OPT_SIGNUM = 0x08, + PS_OPT_VERBOSE = 0x10 +}; +#define PS_SUBCOMMAND_OPTS \ + (PS_OPT_CAPABILITIES | PS_OPT_SIGNUM | \ + PS_OPT_PERTHREAD | PS_OPT_VERBOSE) + +extern int procstat_opts; + struct kinfo_proc; void kinfo_proc_sort(struct kinfo_proc *kipp, int count); const char * kinfo_proc_thread_name(const struct kinfo_proc *kipp); void procstat_args(struct procstat *prstat, struct kinfo_proc *kipp); void procstat_auxv(struct procstat *prstat, struct kinfo_proc *kipp); -void procstat_basic(struct kinfo_proc *kipp); +void procstat_basic(struct procstat *prstat, struct kinfo_proc *kipp); void procstat_bin(struct procstat *prstat, struct kinfo_proc *kipp); void procstat_cred(struct procstat *prstat, struct kinfo_proc *kipp); void procstat_cs(struct procstat *prstat, struct kinfo_proc *kipp); void procstat_env(struct procstat *prstat, struct kinfo_proc *kipp); void procstat_files(struct procstat *prstat, struct kinfo_proc *kipp); -void procstat_kstack(struct procstat *prstat, struct kinfo_proc *kipp, - int kflag); -void procstat_ptlwpinfo(struct procstat *prstat); +void procstat_kstack(struct procstat *prstat, struct kinfo_proc *kipp); +void procstat_ptlwpinfo(struct procstat *prstat, struct kinfo_proc *kipp); void procstat_rlimit(struct procstat *prstat, struct kinfo_proc *kipp); void procstat_rusage(struct procstat *prstat, struct kinfo_proc *kipp); void procstat_sigs(struct procstat *prstat, struct kinfo_proc *kipp); Index: usr.bin/procstat/procstat.1 =================================================================== --- usr.bin/procstat/procstat.1 +++ usr.bin/procstat/procstat.1 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 11, 2017 +.Dd May 25, 2017 .Dt PROCSTAT 1 .Os .Sh NAME @@ -34,10 +34,36 @@ .Sh SYNOPSIS .Nm .Op Fl -libxo +.Op Fl h +.Op Fl M Ar core +.Op Fl N Ar system +.Op Fl w Ar interval +.Ar command +.Op Ar pid | Ar core ... +.Nm +.Op Fl -libxo +.Fl a +.Op Fl h +.Op Fl M Ar core +.Op Fl N Ar system +.Op Fl w Ar interval +.Ar command +.Nm +.Op Fl -libxo .Op Fl CHhn +.Op Fl M Ar core +.Op Fl N Ar system .Op Fl w Ar interval .Op Fl b | c | e | f | i | j | k | l | L | r | s | S | t | v | x -.Op Fl a | Ar pid | Ar core ... +.Op Ar pid | Ar core ... +.Nm +.Op Fl -libxo +.Fl a +.Op Fl CHhn +.Op Fl M Ar core +.Op Fl N Ar system +.Op Fl w Ar interval +.Op Fl b | c | e | f | i | j | k | l | L | r | s | S | t | v | x .Sh DESCRIPTION The .Nm @@ -49,49 +75,76 @@ It can also display information extracted from a process core file, if the core file is specified as the argument. .Pp -By default, basic process statistics are printed; one of the following -options may be specified in order to select more detailed process information -for printing: -.Bl -tag -width indent -.It Fl -libxo -Generate output via +If the +.Fl -libxo +flag is specified the output is generated via .Xr libxo 3 in a selection of different human and machine readable formats. See .Xr xo_parse_args 3 for details on command line arguments. -.It Fl b +.Pp +The following commands are available: +.Bl -tag -width indent +.It Ar basic +Print basic process statistics (this is the default). +.It Ar binary | Ar bin | Fl b Display binary information for the process. -.It Fl c +.It Ar arguments | Ar args | Fl c Display command line arguments for the process. -.It Fl e +.It Ar environment | Ar env | Fl e Display environment variables for the process. -.It Fl f +.It Ar files | Ar fds | Ar fd | Fl f Display file descriptor information for the process. -.It Fl i +.Pp +If the +.Fl C +sub-command flag is used then additional capability information is printed. +.It Ar signals | Ar sigs | Ar sig | Fl i Display signal pending and disposition information for the process. -.It Fl j +.Pp +If the +.Fl n +sub-command option is used, the signal numbers are shown instead of signal +names. +.It Ar thread-signals | Ar tsignals | Ar tsigs | Ar tsig | Fl j Display signal pending and blocked information for the process's threads. -.It Fl k +.Pp +If the +.Fl n +sub-command option is used, the signal numbers are shown instead of signal +names. +.It Ar kstack | Fl k Display the stacks of kernel threads in the process, excluding stacks of threads currently running on a CPU and threads with stacks swapped to disk. -If the flag is repeated, function offsets as well as function names are -printed. -.It Fl l +.Pp +If the +.Fl v +sub-command option is used (or the command flag is repeated), function +offsets as well as function names are printed. +.It Ar rlimit | Fl l Display resource limits for the process. -.It Fl L +.It Ar ptlwpinfo | Ar lwpinfo | Ar lwp | Fl L Display LWP info for the process pertaining to its signal driven exit. -.It Fl r +.It Ar rusage | Fl r Display resource usage information for the process. -.It Fl s +.Pp +If the +.Fl v +.Pq or Fl H +sub-command flag +is used then per-thread statistics are printed, rather +than per-process statistics. The second field in the table will +list the thread ID to which the row of information corresponds. +.It Ar credentials | Ar creds | Ar cred | Fl s Display security credential information for the process. -.It Fl S +.It Ar cpuset | Ar cs | Fl S Display the cpuset information for the thread. -.It Fl t +.It Ar threads | Fl t Display thread information for the process. -.It Fl v +.It Ar vm | Fl v Display virtual memory mappings for the process. -.It Fl x +.It Ar auxv | Fl x Display ELF auxiliary vector for the process. .El .Pp @@ -108,23 +161,6 @@ If the .Fl w flag is not specified, the output will not repeat. -.Pp -The -.Fl C -flag requests the printing of additional capability information in the file -descriptor view. -.Pp -The -.Fl H -flag may be used to request per-thread statistics rather than per-process -statistics for some options. -For those options, the second field in the table will list the thread ID -to which the row of information corresponds. -The -.Fl H -flag is implied for the -.Fl S -mode. .Pp Information for VM, file descriptor, and cpuset options is available only to the owner of a process or the superuser. Index: usr.bin/procstat/procstat.c =================================================================== --- usr.bin/procstat/procstat.c +++ usr.bin/procstat/procstat.c @@ -42,19 +42,137 @@ #include "procstat.h" -static int aflag, bflag, cflag, eflag, fflag, iflag, jflag, kflag; -static int lflag, Lflag, rflag, sflag, tflag, vflag, xflag, Sflag; -int hflag, nflag, Cflag, Hflag; +enum procstat_cmd { + PS_CMD_BASIC = 0, + PS_CMD_BINARY, + PS_CMD_ARGUMENTS, + PS_CMD_ENVIRONMENT, + PS_CMD_FILES, + PS_CMD_SIGNALS, + PS_CMD_TSIGNALS, + PS_CMD_KSTACK, + PS_CMD_RLIMIT, + PS_CMD_PTLWPINFO, + PS_CMD_RUSAGE, + PS_CMD_CREDENTIALS, + PS_CMD_CPUSET, + PS_CMD_THREADS, + PS_CMD_VM, + PS_CMD_AUXV +}; +static enum procstat_cmd procstat_cmd = PS_CMD_BASIC; +int procstat_opts = 0; + +static void cmdopt_none(int argc, char *argv[]); +static void cmdopt_verbose(int argc, char *argv[]); +static void cmdopt_signals(int argc, char *argv[]); +static void cmdopt_rusage(int argc, char *argv[]); +static void cmdopt_files(int argc, char *argv[]); +static void cmdopt_cpuset(int argc, char *argv[]); + +static int aflag; + +static const struct { + const char *xocontainer; + const char *usage; + void (*cmd)(struct procstat *, struct kinfo_proc *); + void (*opt)(int, char **); +} cmd_table[] = { + { "basic", NULL, &procstat_basic, &cmdopt_none }, + { "binary", NULL, &procstat_bin, &cmdopt_none }, + { "arguments", NULL, &procstat_args, &cmdopt_none }, + { "environment", NULL, &procstat_env, &cmdopt_none }, + { "files", "[-C]", &procstat_files, &cmdopt_files }, + { "signals", "[-n]", &procstat_sigs, &cmdopt_signals }, + { "thread_signals", "[-n]", &procstat_threads_sigs, &cmdopt_signals }, + { "kstack", "[-v]", &procstat_kstack, &cmdopt_verbose }, + { "rlimit", NULL, &procstat_rlimit, &cmdopt_none }, + { "ptlwpinfo", NULL, &procstat_ptlwpinfo, &cmdopt_none }, + { "rusage", "[-Hv]", &procstat_rusage, &cmdopt_rusage }, + { "credentials", NULL, &procstat_cred, &cmdopt_none }, + { "cs", NULL, &procstat_cs, &cmdopt_cpuset }, + { "threads", NULL, &procstat_threads, &cmdopt_none }, + { "vm", NULL, &procstat_vm, &cmdopt_none }, + { "auxv", NULL, &procstat_auxv, &cmdopt_none } +}; + +static const struct { + const char *command; + enum procstat_cmd value; +} cmd_strings[] = { + { "basic", PS_CMD_BASIC }, + { "binary", PS_CMD_BINARY }, + { "bin", PS_CMD_BINARY }, + { "arguments", PS_CMD_ARGUMENTS }, + { "args", PS_CMD_ARGUMENTS }, + { "environment", PS_CMD_ENVIRONMENT }, + { "env", PS_CMD_ENVIRONMENT }, + { "files", PS_CMD_FILES }, + { "fds", PS_CMD_FILES }, + { "fd", PS_CMD_FILES }, + { "signals", PS_CMD_SIGNALS }, + { "sigs", PS_CMD_SIGNALS }, + { "sig", PS_CMD_SIGNALS }, + { "thread-signals", PS_CMD_TSIGNALS }, + { "tsignals", PS_CMD_TSIGNALS }, + { "tsigs", PS_CMD_TSIGNALS }, + { "tsig", PS_CMD_TSIGNALS }, + { "kstack", PS_CMD_KSTACK }, + { "rlimit", PS_CMD_RLIMIT }, + { "ptlwpinfo", PS_CMD_PTLWPINFO }, + { "lwpinfo", PS_CMD_PTLWPINFO }, + { "lwp", PS_CMD_PTLWPINFO }, + { "rusage", PS_CMD_RUSAGE }, + { "credentials", PS_CMD_CREDENTIALS }, + { "creds", PS_CMD_CREDENTIALS }, + { "cred", PS_CMD_CREDENTIALS }, + { "cpuset", PS_CMD_CPUSET }, + { "cs", PS_CMD_CPUSET }, + { "threads", PS_CMD_THREADS }, + { "vm", PS_CMD_VM }, + { "auxv", PS_CMD_AUXV } +}; + static void usage(void) { + size_t i; + size_t l; + int multi; - xo_error("usage: procstat [-CHhn] [-M core] [-N system] " - "[-w interval]\n" - " [-b | -c | -e | -f | -i | -j | -k | " - "-l | -r | -s | -S | -t | -v | -x]\n" - " [-a | pid | core ...]\n"); + xo_error("usage: procstat [--libxo] [-h] [-M core] [-N system]" + " [-w interval]\n" + " command [pid | core ...]\n" + " procstat [--libxo] -a [-h] [-M core] [-N system] " + " [-w interval]\n" + " command\n" + " procstat [--libxo] [-CHhn] [-M core]" + " [-N system] [-w interval]\n" + " [-b | -c | -e | -f | -i | -j | -k |" + " -l | -L | -r | -s |\n" + " -S | -t | -v | -x] [pid | core ...]\n" + " procstat [--libxo] -a [-CHhn] [-M core]" + " [-N system] [-w interval]\n" + " [-b | -c | -e | -f | -i | -j | -k |" + " -l | -L | -r | -s |\n" + " -S | -t | -v | -x]\n" + "Available commands:\n"); + for (i = 0, l = sizeof(cmd_strings) / sizeof(cmd_strings[0]); + i < l; i++) { + multi = i + 1 < l && cmd_strings[i].value == + cmd_strings[i + 1].value; + xo_error(" %s%s", multi ? "[" : "", + cmd_strings[i].command); + for (; i + 1 < l && cmd_strings[i].value == + cmd_strings[i + 1].value; i++) + xo_error(" | %s", cmd_strings[i + 1].command); + if (multi) + xo_error("]"); + if (cmd_table[cmd_strings[i].value].usage != NULL) + xo_error(" %s", cmd_table[cmd_strings[i].value].usage); + xo_error("\n"); + } xo_finish(); exit(EX_USAGE); } @@ -68,40 +186,7 @@ if (pidstr == NULL) xo_errc(1, ENOMEM, "Failed to allocate memory in procstat()"); xo_open_container(pidstr); - - if (bflag) - procstat_bin(prstat, kipp); - else if (cflag) - procstat_args(prstat, kipp); - else if (eflag) - procstat_env(prstat, kipp); - else if (fflag) - procstat_files(prstat, kipp); - else if (iflag) - procstat_sigs(prstat, kipp); - else if (jflag) - procstat_threads_sigs(prstat, kipp); - else if (kflag) - procstat_kstack(prstat, kipp, kflag); - else if (lflag) - procstat_rlimit(prstat, kipp); - else if (Lflag) - procstat_ptlwpinfo(prstat); - else if (rflag) - procstat_rusage(prstat, kipp); - else if (sflag) - procstat_cred(prstat, kipp); - else if (tflag) - procstat_threads(prstat, kipp); - else if (vflag) - procstat_vm(prstat, kipp); - else if (xflag) - procstat_auxv(prstat, kipp); - else if (Sflag) - procstat_cs(prstat, kipp); - else - procstat_basic(kipp); - + cmd_table[procstat_cmd].cmd(prstat, kipp); xo_close_container(pidstr); free(pidstr); } @@ -145,6 +230,30 @@ return (name); } +static int +getcmd(int argc, char *argv[]) +{ + size_t i; + + if (argv[0] == NULL) + return (0); + for (i = 0; i < sizeof(cmd_strings) / sizeof(cmd_strings[0]); i++) { + if (strcasecmp(argv[0], cmd_strings[i].command) == 0) { + procstat_cmd = cmd_strings[i].value; + if (cmd_table[procstat_cmd].opt != NULL) { + if (procstat_opts & PS_SUBCOMMAND_OPTS) + usage(); + optreset = 1; + optind = 1; + cmd_table[procstat_cmd].opt(argc, argv); + return (optind); + } + return (1); + } + } + return (0); +} + int main(int argc, char *argv[]) { @@ -156,22 +265,22 @@ pid_t pid; char *dummy; char *nlistf, *memf; - const char *xocontainer; + int ncmd; int cnt; interval = 0; memf = nlistf = NULL; argc = xo_parse_args(argc, argv); - xocontainer = "basic"; + ncmd = 0; - while ((ch = getopt(argc, argv, "CHN:M:abcefijklLhrsStvw:x")) != -1) { + while ((ch = getopt(argc, argv, "abCcefHhijkLlM:N:nrSstvw:x")) != -1) { switch (ch) { case 'C': - Cflag++; + procstat_opts |= PS_OPT_CAPABILITIES; break; case 'H': - Hflag++; + procstat_opts |= PS_OPT_PERTHREAD; break; case 'M': @@ -181,84 +290,85 @@ nlistf = optarg; break; case 'S': - Sflag++; - xocontainer = "cs"; + ncmd++; + procstat_cmd = PS_CMD_CPUSET; break; case 'a': aflag++; break; case 'b': - bflag++; - xocontainer = "binary"; + ncmd++; + procstat_cmd = PS_CMD_BINARY; break; case 'c': - cflag++; - xocontainer = "arguments"; + ncmd++; + procstat_cmd = PS_CMD_ARGUMENTS; break; case 'e': - eflag++; - xocontainer = "environment"; + ncmd++; + procstat_cmd = PS_CMD_ENVIRONMENT; break; case 'f': - fflag++; - xocontainer = "files"; + ncmd++; + procstat_cmd = PS_CMD_FILES; break; case 'i': - iflag++; - xocontainer = "signals"; + ncmd++; + procstat_cmd = PS_CMD_SIGNALS; break; case 'j': - jflag++; - xocontainer = "thread_signals"; + ncmd++; + procstat_cmd = PS_CMD_TSIGNALS; break; case 'k': - kflag++; - xocontainer = "kstack"; + if (procstat_cmd == PS_CMD_KSTACK) + procstat_opts |= PS_OPT_VERBOSE; + else + ncmd++; + procstat_cmd = PS_CMD_KSTACK; break; case 'l': - lflag++; - xocontainer = "rlimit"; + procstat_cmd = PS_CMD_RLIMIT; break; case 'L': - Lflag++; - xocontainer = "ptlwpinfo"; + procstat_cmd = PS_CMD_PTLWPINFO; break; case 'n': - nflag++; + procstat_opts |= PS_OPT_SIGNUM; break; case 'h': - hflag++; + procstat_opts |= PS_OPT_NOHEADER; break; case 'r': - rflag++; - xocontainer = "rusage"; + ncmd++; + procstat_cmd = PS_CMD_RUSAGE; break; case 's': - sflag++; - xocontainer = "credentials"; + ncmd++; + procstat_cmd = PS_CMD_CREDENTIALS; break; case 't': - tflag++; - xocontainer = "threads"; + ncmd++; + procstat_cmd = PS_CMD_THREADS; break; case 'v': - vflag++; - xocontainer = "vm"; + ncmd++; + procstat_cmd = PS_CMD_VM; break; case 'w': @@ -271,8 +381,8 @@ break; case 'x': - xflag++; - xocontainer = "auxv"; + ncmd++; + procstat_cmd = PS_CMD_AUXV; break; case '?': @@ -284,24 +394,21 @@ argc -= optind; argv += optind; - /* We require that either 0 or 1 mode flags be set. */ - tmp = bflag + cflag + eflag + fflag + iflag + jflag + (kflag ? 1 : 0) + - lflag + rflag + sflag + tflag + vflag + xflag + Sflag; - if (!(tmp == 0 || tmp == 1)) + if (ncmd > 1) usage(); - /* We allow -k to be specified up to twice, but not more. */ - if (kflag > 2) + if (ncmd == 0 && argv[0] != NULL) { + tmp = getcmd(argc, argv); + argc -= tmp; + argv += tmp; + } else if (procstat_cmd != PS_CMD_FILES && + (procstat_opts & PS_OPT_CAPABILITIES)) usage(); /* Must specify either the -a flag or a list of pids. */ if (!(aflag == 1 && argc == 0) && !(aflag == 0 && argc > 0)) usage(); - /* Only allow -C with -f. */ - if (Cflag && !fflag) - usage(); - if (memf != NULL) prstat = procstat_open_kvm(nlistf, memf); else @@ -311,7 +418,7 @@ do { xo_set_version(PROCSTAT_XO_VERSION); xo_open_container("procstat"); - xo_open_container(xocontainer); + xo_open_container(cmd_table[procstat_cmd].xocontainer); if (aflag) { p = procstat_getprocs(prstat, KERN_PROC_PROC, 0, &cnt); @@ -322,7 +429,7 @@ procstat(prstat, &p[i]); /* Suppress header after first process. */ - hflag = 1; + procstat_opts |= PS_OPT_NOHEADER; xo_flush(); } procstat_freeprocs(prstat, p); @@ -357,10 +464,10 @@ procstat_close(cprstat); } /* Suppress header after first process. */ - hflag = 1; + procstat_opts |= PS_OPT_NOHEADER; } - xo_close_container(xocontainer); + xo_close_container(cmd_table[procstat_cmd].xocontainer); xo_close_container("procstat"); xo_finish(); if (interval) @@ -370,4 +477,96 @@ procstat_close(prstat); exit(0); +} + +void +cmdopt_none(int argc, char *argv[]) +{ + int ch; + + while ((ch = getopt(argc, argv, "")) != -1) { + switch (ch) { + case '?': + default: + usage(); + } + } +} + +void +cmdopt_verbose(int argc, char *argv[]) +{ + int ch; + + while ((ch = getopt(argc, argv, "v")) != -1) { + switch (ch) { + case 'v': + procstat_opts |= PS_OPT_VERBOSE; + break; + case '?': + default: + usage(); + } + } +} + +void +cmdopt_signals(int argc, char *argv[]) +{ + int ch; + + while ((ch = getopt(argc, argv, "n")) != -1) { + switch (ch) { + case 'n': + procstat_opts |= PS_OPT_SIGNUM; + break; + case '?': + default: + usage(); + } + } +} + +void +cmdopt_rusage(int argc, char *argv[]) +{ + int ch; + + while ((ch = getopt(argc, argv, "Ht")) != -1) { + switch (ch) { + case 'H': + /* FALLTHROUGH */ + case 't': + procstat_opts |= PS_OPT_PERTHREAD; + break; + case '?': + default: + usage(); + } + } +} + +void +cmdopt_files(int argc, char *argv[]) +{ + int ch; + + while ((ch = getopt(argc, argv, "C")) != -1) { + switch (ch) { + case 'C': + procstat_opts |= PS_OPT_CAPABILITIES; + break; + case '?': + default: + usage(); + } + } +} + +void +cmdopt_cpuset(int argc, char *argv[]) +{ + + procstat_opts |= PS_OPT_PERTHREAD; + cmdopt_none(argc, argv); } Index: usr.bin/procstat/procstat_args.c =================================================================== --- usr.bin/procstat/procstat_args.c +++ usr.bin/procstat/procstat_args.c @@ -47,7 +47,7 @@ int i; char **args; - if (!hflag) { + if (!(procstat_opts & PS_OPT_NOHEADER)) { xo_emit("{T:/%5s %-16s %-53s}\n", "PID", "COMM", "ARGS"); } @@ -74,7 +74,7 @@ int i; char **envs; - if (!hflag) { + if (!(procstat_opts & PS_OPT_NOHEADER)) { xo_emit("{T:/%5s %-16s %-53s}\n", "PID", "COMM", "ENVIRONMENT"); } Index: usr.bin/procstat/procstat_auxv.c =================================================================== --- usr.bin/procstat/procstat_auxv.c +++ usr.bin/procstat/procstat_auxv.c @@ -51,7 +51,7 @@ u_int count, i; static char prefix[256]; - if (!hflag) + if (!(procstat_opts & PS_OPT_NOHEADER)) xo_emit("{T:/%5s %-16s %-16s %-16s}\n", "PID", "COMM", "AUXV", "VALUE"); Index: usr.bin/procstat/procstat_basic.c =================================================================== --- usr.bin/procstat/procstat_basic.c +++ usr.bin/procstat/procstat_basic.c @@ -39,10 +39,10 @@ #include "procstat.h" void -procstat_basic(struct kinfo_proc *kipp) +procstat_basic(struct procstat *procstat __unused, struct kinfo_proc *kipp) { - if (!hflag) + if (!(procstat_opts & PS_OPT_NOHEADER)) xo_emit("{T:/%5s %5s %5s %5s %5s %3s %-8s %-9s %-13s %-12s}\n", "PID", "PPID", "PGID", "SID", "TSID", "THR", "LOGIN", "WCHAN", "EMUL", "COMM"); Index: usr.bin/procstat/procstat_bin.c =================================================================== --- usr.bin/procstat/procstat_bin.c +++ usr.bin/procstat/procstat_bin.c @@ -46,7 +46,7 @@ int osrel; static char pathname[PATH_MAX]; - if (!hflag) + if (!(procstat_opts & PS_OPT_NOHEADER)) xo_emit("{T:/%5s %-16s %8s %s}\n", "PID", "COMM", "OSREL", "PATH"); Index: usr.bin/procstat/procstat_cred.c =================================================================== --- usr.bin/procstat/procstat_cred.c +++ usr.bin/procstat/procstat_cred.c @@ -48,7 +48,7 @@ unsigned int i, ngroups; gid_t *groups; - if (!hflag) + if (!(procstat_opts & PS_OPT_NOHEADER)) xo_emit("{T:/%5s %-16s %5s %5s %5s %5s %5s %5s %5s %5s %-15s}\n", "PID", "COMM", "EUID", "RUID", "SVUID", "EGID", "RGID", "SVGID", "UMASK", "FLAGS", "GROUPS"); Index: usr.bin/procstat/procstat_cs.c =================================================================== --- usr.bin/procstat/procstat_cs.c +++ usr.bin/procstat/procstat_cs.c @@ -52,7 +52,7 @@ unsigned int count, i; int once, twice, lastcpu, cpu; - if (!hflag) + if (!(procstat_opts & PS_OPT_NOHEADER)) xo_emit("{T:/%5s %6s %-19s %-19s %2s %4s %-7s}\n", "PID", "TID", "COMM", "TDNAME", "CPU", "CSID", "CPU MASK"); Index: usr.bin/procstat/procstat_files.c =================================================================== --- usr.bin/procstat/procstat_files.c +++ usr.bin/procstat/procstat_files.c @@ -303,7 +303,7 @@ */ capwidth = 0; head = procstat_getfiles(procstat, kipp, 0); - if (head != NULL && Cflag) { + if (head != NULL && (procstat_opts & PS_OPT_CAPABILITIES)) { STAILQ_FOREACH(fst, head, next) { width = width_capability(&fst->fs_cap_rights); if (width > capwidth) @@ -313,8 +313,8 @@ capwidth = strlen("CAPABILITIES"); } - if (!hflag) { - if (Cflag) + if (!(procstat_opts & PS_OPT_NOHEADER)) { + if (procstat_opts & PS_OPT_CAPABILITIES) xo_emit("{T:/%5s %-16s %5s %1s %-8s %-*s " "%-3s %-12s}\n", "PID", "COMM", "FD", "T", "FLAGS", capwidth, "CAPABILITIES", "PRO", @@ -412,7 +412,7 @@ break; } xo_emit("{d:fd_type/%1s/%s} ", str); - if (!Cflag) { + if (!(procstat_opts & PS_OPT_CAPABILITIES)) { str = "-"; if (fst->fs_type == PS_FST_TYPE_VNODE) { error = procstat_get_vnode_info(procstat, fst, @@ -509,7 +509,7 @@ xo_emit("{elq:fd_flags/lock_held}"); xo_close_list("fd_flags"); - if (!Cflag) { + if (!(procstat_opts & PS_OPT_CAPABILITIES)) { if (fst->fs_ref_count > -1) xo_emit("{:ref_count/%3d/%d} ", fst->fs_ref_count); @@ -521,7 +521,7 @@ else xo_emit("{q:offset/%7c/%c} ", '-'); } - if (Cflag) { + if (procstat_opts & PS_OPT_CAPABILITIES) { print_capability(&fst->fs_cap_rights, capwidth); xo_emit(" "); } Index: usr.bin/procstat/procstat_kstack.c =================================================================== --- usr.bin/procstat/procstat_kstack.c +++ usr.bin/procstat/procstat_kstack.c @@ -162,7 +162,7 @@ void -procstat_kstack(struct procstat *procstat, struct kinfo_proc *kipp, int kflag) +procstat_kstack(struct procstat *procstat, struct kinfo_proc *kipp) { struct kinfo_kstack *kkstp, *kkstp_free; struct kinfo_proc *kip, *kip_free; @@ -170,7 +170,7 @@ unsigned int i, j; unsigned int kip_count, kstk_count; - if (!hflag) + if (!(procstat_opts & PS_OPT_NOHEADER)) xo_emit("{T:/%5s %6s %-19s %-19s %-29s}\n", "PID", "TID", "COMM", "TDNAME", "KSTACK"); @@ -234,9 +234,11 @@ * entries, but for a more compact view, we convert carriage * returns to spaces. */ - kstack_cleanup(kkstp->kkst_trace, trace, kflag); + kstack_cleanup(kkstp->kkst_trace, trace, + (procstat_opts & PS_OPT_VERBOSE) ? 2 : 1); xo_open_list("trace"); - kstack_cleanup_encoded(kkstp->kkst_trace, encoded_trace, kflag); + kstack_cleanup_encoded(kkstp->kkst_trace, encoded_trace, + (procstat_opts & PS_OPT_VERBOSE) ? 2 : 1); xo_close_list("trace"); xo_emit("{d:trace/%-29s}\n", trace); } Index: usr.bin/procstat/procstat_ptlwpinfo.c =================================================================== --- usr.bin/procstat/procstat_ptlwpinfo.c +++ usr.bin/procstat/procstat_ptlwpinfo.c @@ -36,7 +36,7 @@ #include "procstat.h" void -procstat_ptlwpinfo(struct procstat *prstat) +procstat_ptlwpinfo(struct procstat *prstat, struct kinfo_proc *kipp __unused) { struct ptrace_lwpinfo *pl; unsigned int count, i; @@ -45,7 +45,7 @@ if (pl == NULL) return; - if (!hflag) + if (!(procstat_opts & PS_OPT_NOHEADER)) xo_emit("{:/%6s %7s %5s %5s %5s %6s %5s} {[:/%d}{:/%s}{]:}" " {:/%s}\n", "LWPID", "EVENT", "SIGNO", "CODE", "ERRNO", "PID", "UID", Index: usr.bin/procstat/procstat_rlimit.c =================================================================== --- usr.bin/procstat/procstat_rlimit.c +++ usr.bin/procstat/procstat_rlimit.c @@ -94,7 +94,7 @@ struct rlimit rlimit; int i; - if (!hflag) { + if (!(procstat_opts & PS_OPT_NOHEADER)) { xo_emit("{T:/%5s %-16s %-16s %16s %16s}\n", "PID", "COMM", "RLIMIT", "SOFT ", "HARD "); } Index: usr.bin/procstat/procstat_rusage.c =================================================================== --- usr.bin/procstat/procstat_rusage.c +++ usr.bin/procstat/procstat_rusage.c @@ -106,7 +106,7 @@ { xo_emit("{d:process_id/%5d/%d} ", kipp->ki_pid); - if (Hflag) + if (procstat_opts & PS_OPT_PERTHREAD) xo_emit("{d:thread_id/%6d/%d} ", kipp->ki_tid); xo_emit("{d:command/%-16s/%s} ", kipp->ki_comm); } @@ -125,7 +125,7 @@ xo_emit("{d:resource/%-14s} {d:usage/%29s}{P: }\n", "system time", format_time(&kipp->ki_rusage.ru_stime)); - if (Hflag) { + if (procstat_opts & PS_OPT_PERTHREAD) { asprintf(&threadid, "%d", kipp->ki_tid); if (threadid == NULL) xo_errc(1, ENOMEM, @@ -154,7 +154,7 @@ rusage_info[i].ri_scale)); lp++; } - if (Hflag) { + if (procstat_opts & PS_OPT_PERTHREAD) { xo_close_container(threadid); free(threadid); } @@ -166,15 +166,15 @@ struct kinfo_proc *kip; unsigned int count, i; - if (!hflag) { + if (!(procstat_opts & PS_OPT_NOHEADER)) { xo_emit("{d:ta/%5s} ", "PID"); - if (Hflag) + if (procstat_opts & PS_OPT_PERTHREAD) xo_emit("{d:tb/%6s} ", "TID"); xo_emit("{d:tc/%-16s %-32s %14s}\n", "COMM", "RESOURCE", "VALUE "); } - if (!Hflag) { + if (!(procstat_opts & PS_OPT_PERTHREAD)) { print_rusage(kipp); return; } Index: usr.bin/procstat/procstat_sigs.c =================================================================== --- usr.bin/procstat/procstat_sigs.c +++ usr.bin/procstat/procstat_sigs.c @@ -48,7 +48,7 @@ char name[12]; int i; - if (!nflag && sig < sys_nsig) { + if (!(procstat_opts & PS_OPT_SIGNUM) && sig < sys_nsig) { strlcpy(name, sys_signame[sig], sizeof(name)); for (i = 0; name[i] != 0; i++) name[i] = toupper(name[i]); @@ -67,7 +67,7 @@ char name[12]; int i; - if (!nflag && sig < sys_nsig) { + if (!(procstat_opts & PS_OPT_SIGNUM) && sig < sys_nsig) { strlcpy(name, sys_signame[sig], sizeof(name)); for (i = 0; name[i] != 0; i++) name[i] = toupper(name[i]); @@ -110,7 +110,7 @@ { int j; - if (!hflag) + if (!(procstat_opts & PS_OPT_NOHEADER)) xo_emit("{T:/%5s %-16s %-7s %4s}\n", "PID", "COMM", "SIG", "FLAGS"); @@ -139,7 +139,7 @@ unsigned int count, i; char *threadid; - if (!hflag) + if (!(procstat_opts & PS_OPT_NOHEADER)) xo_emit("{T:/%5s %6s %-16s %-7s %4s}\n", "PID", "TID", "COMM", "SIG", "FLAGS"); Index: usr.bin/procstat/procstat_threads.c =================================================================== --- usr.bin/procstat/procstat_threads.c +++ usr.bin/procstat/procstat_threads.c @@ -48,7 +48,7 @@ const char *str; char *threadid; - if (!hflag) + if (!(procstat_opts & PS_OPT_NOHEADER)) xo_emit("{T:/%5s %6s %-19s %-19s %2s %4s %-7s %-9s}\n", "PID", "TID", "COMM", "TDNAME", "CPU", "PRI", "STATE", "WCHAN"); Index: usr.bin/procstat/procstat_vm.c =================================================================== --- usr.bin/procstat/procstat_vm.c +++ usr.bin/procstat/procstat_vm.c @@ -50,7 +50,7 @@ const char *str, *lstr; ptrwidth = 2*sizeof(void *) + 2; - if (!hflag) + if (!(procstat_opts & PS_OPT_NOHEADER)) xo_emit("{T:/%5s %*s %*s %3s %4s %4s %3s %3s %-4s %-2s %-s}\n", "PID", ptrwidth, "START", ptrwidth, "END", "PRT", "RES", "PRES", "REF", "SHD", "FLAG", "TP", "PATH");