From owner-freebsd-bugs@FreeBSD.ORG Fri Jan 27 11:50:08 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6A2FC1065675 for ; Fri, 27 Jan 2012 11:50:08 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 340308FC1D for ; Fri, 27 Jan 2012 11:50:08 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q0RBo7FV035639 for ; Fri, 27 Jan 2012 11:50:07 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q0RBo7Fd035638; Fri, 27 Jan 2012 11:50:07 GMT (envelope-from gnats) Date: Fri, 27 Jan 2012 11:50:07 GMT Message-Id: <201201271150.q0RBo7Fd035638@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Bruce Evans Cc: Subject: Re: bin/164535: ps(1) truncates command to screen size even when stdout is not a tty X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Bruce Evans List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Jan 2012 11:50:08 -0000 The following reply was made to PR bin/164535; it has been noted by GNATS. From: Bruce Evans To: Marcus Reid Cc: freebsd-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org Subject: Re: bin/164535: ps(1) truncates command to screen size even when stdout is not a tty Date: Fri, 27 Jan 2012 22:49:35 +1100 (EST) On Fri, 27 Jan 2012, Marcus Reid wrote: >> Description: > ps(1) truncates long commands to the size of the screen even when stdout is not a terminal. This is counter-intuitive and differs from another implementation I looked at. Output of ps | grep differs depending on how big your terminal window is for example. >> How-To-Repeat: > ps aux | grep > ps auxww | grep >> Fix: > Patch included. Tested; behavior remains consistent with docs: COLUMNS variable retains effect, and -w limits to 132 characters still. > > > Patch attached with submission follows: > > --- bin/ps/ps.c.orig 2012-01-27 01:24:10.519024952 -0800 > +++ bin/ps/ps.c 2012-01-27 01:24:20.350023629 -0800 > @@ -187,6 +187,8 @@ > > if ((cols = getenv("COLUMNS")) != NULL && *cols != '\0') > termwidth = atoi(cols); > + else if (isatty(STDOUT_FILENO) == 0) > + termwidth = UNLIMITED; This change defeats the else clause, which checks all of STDOUT_FILENO, STDERR_FILENO and STDIN_FILENO and uses the terminal width iff any if these is a terminal according to the TIOCGWINSZ test for being a terminal, and otherwise gives a default of 79 columns (not UNLIMITED, which is only documented for ps -ww and only reachable using that and via the missing sanity checking for COLUMNS=0). > else if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 && > ioctl(STDERR_FILENO, TIOCGWINSZ, (char *)&ws) == -1 && > ioctl(STDIN_FILENO, TIOCGWINSZ, (char *)&ws) == -1) || So the correct way to avoid terminalness when outputting to a file is "ps foo 2>&1". This is too strange for stdin, so apparently checking all 3 fd's is a feature, precisely to get the terminal width from somewhere even when stdout and stderr are redirected to a file. "COLUMNS=0 ps" is an easier way. If this feature is considered a bug, then remove the checks of STDERR_FILENO and STDIN_FILENO. Bruce