diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2014-06-05 07:29:21 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2014-06-05 07:29:21 +0000 |
commit | 1c9cd75908cee5925c6e2e14b185984ed70cb292 (patch) | |
tree | 38ee38465b1f75e75e6b1d6ecd3f1ee944a5b4bc /bin | |
parent | 31f4d5b52a1451d75979ee148509f40db39080a4 (diff) |
Add support for COLUMNS env variable, inspired by FreeBSD but with a dash
of strtonum() from millert@ sprinkled on top.
Also, we've always supported TZ for formatting dates, so say so.
ok jmc@ millert@
Diffstat (limited to 'bin')
-rw-r--r-- | bin/ps/ps.1 | 28 | ||||
-rw-r--r-- | bin/ps/ps.c | 29 |
2 files changed, 38 insertions, 19 deletions
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index c7f49567ece..2a52b97b483 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ps.1,v 1.94 2014/05/21 06:01:19 jmc Exp $ +.\" $OpenBSD: ps.1,v 1.95 2014/06/05 07:29:20 guenther Exp $ .\" $NetBSD: ps.1,v 1.16 1996/03/21 01:36:28 jtc Exp $ .\" .\" Copyright (c) 1980, 1990, 1991, 1993, 1994 @@ -30,7 +30,7 @@ .\" .\" @(#)ps.1 8.3 (Berkeley) 4/18/94 .\" -.Dd $Mdocdate: May 21 2014 $ +.Dd $Mdocdate: June 5 2014 $ .Dt PS 1 .Os .Sh NAME @@ -527,6 +527,21 @@ as 324000. .It Cm xstat Exit or stop status (valid only for stopped or zombie process). .El +.Sh ENVIRONMENT +The following environment variables affect the execution of +.Nm : +.Bl -tag -width "COLUMNS" +.It Ev COLUMNS +If set, specifies the user's preferred output width in column positions. +By default, +.Nm +attempts to automatically determine the terminal width. +.It Ev TZ +The time zone to use when displaying dates. +See +.Xr environ 7 +for more information. +.El .Sh FILES .Bl -tag -width "/var/db/kvm_bsd.dbXXX" -compact .It Pa /dev @@ -567,15 +582,10 @@ utility is compliant with the specification, except that the flag .Op Fl G -is unsupported, +is unsupported and the flags .Op Fl ptU -support only single arguments, not lists, -and the environment variables -.Ev COLUMNS -and -.Ev TZ -are unsupported. +support only single arguments, not lists. .Pp The flags .Op Fl defglnu diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 608ddd78804..4456af835ce 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ps.c,v 1.60 2014/05/07 01:31:25 tedu Exp $ */ +/* $OpenBSD: ps.c,v 1.61 2014/06/05 07:29:20 guenther Exp $ */ /* $NetBSD: ps.c,v 1.15 1995/05/18 20:33:25 mycroft Exp $ */ /*- @@ -98,15 +98,24 @@ main(int argc, char *argv[]) uid_t uid; int all, ch, flag, i, fmt, lineno, nentries; int prtheader, showthreads, wflag, kflag, what, Uflag, xflg; - char *nlistf, *memf, *swapf, errbuf[_POSIX2_LINE_MAX]; - - if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 && - ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 && - ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) || - ws.ws_col == 0) - termwidth = 79; - else - termwidth = ws.ws_col - 1; + char *nlistf, *memf, *swapf, *cols, errbuf[_POSIX2_LINE_MAX]; + + if ((cols = getenv("COLUMNS")) != NULL && *cols != '\0') { + const char *errstr; + + termwidth = strtonum(cols, 1, INT_MAX, &errstr); + if (errstr != NULL) + warnx("COLUMNS: %s: %s", cols, errstr); + } + if (termwidth == 0) { + if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 && + ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 && + ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) || + ws.ws_col == 0) + termwidth = 79; + else + termwidth = ws.ws_col - 1; + } if (argc > 1) argv[1] = kludge_oldps_options(argv[1]); |