From b93bb974cc82d1a0db3b2529780bcd2ce914074a Mon Sep 17 00:00:00 2001 From: Mike Karels Date: Wed, 28 Feb 2018 00:17:08 +0000 Subject: [PATCH] Revert r314685 in ps Revert r314685, and add a comment describing the original behavior and the intent. Reviewed by: dab@ vangyzen@ jhb@ Differential Revision: https://reviews.freebsd.org/D14530 --- bin/ps/ps.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/ps/ps.c b/bin/ps/ps.c index f2526e2d870..5a19db6cd52 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -194,10 +194,17 @@ main(int argc, char *argv[]) (void) setlocale(LC_ALL, ""); time(&now); /* Used by routines in print.c. */ + /* + * Compute default output line length before processing options. + * If COLUMNS is set, use it. Otherwise, if this is part of an + * interactive job (i.e. one associated with a terminal), use + * the terminal width. "Interactive" is determined by whether + * any of stdout, stderr, or stdin is a terminal. The intent + * is that "ps", "ps | more", and "ps | grep" all use the same + * default line length unless -w is specified. + */ if ((cols = getenv("COLUMNS")) != NULL && *cols != '\0') termwidth = atoi(cols); - else if (!isatty(STDOUT_FILENO)) - termwidth = UNLIMITED; else if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 && ioctl(STDERR_FILENO, TIOCGWINSZ, (char *)&ws) == -1 && ioctl(STDIN_FILENO, TIOCGWINSZ, (char *)&ws) == -1) ||