From fracture@cx420564-b.tucson1.az.home.com  Fri Mar 16 12:00:11 2001
Return-Path: <fracture@cx420564-b.tucson1.az.home.com>
Received: from cx420564-b.tucson1.az.home.com (cx420564-b.tucson1.az.home.com [24.21.112.225])
	by hub.freebsd.org (Postfix) with ESMTP id 7666D37B718
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 16 Mar 2001 12:00:11 -0800 (PST)
	(envelope-from fracture@cx420564-b.tucson1.az.home.com)
Received: (from fracture@localhost)
	by cx420564-b.tucson1.az.home.com (8.11.1/8.11.1) id f2GCpuk22673;
	Fri, 16 Mar 2001 12:51:56 GMT
	(envelope-from fracture)
Message-Id: <200103161251.f2GCpuk22673@cx420564-b.tucson1.az.home.com>
Date: Fri, 16 Mar 2001 12:51:56 GMT
From: fracture@allusion.net
Reply-To: fracture@allusion.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: /bin/ps issue when output isn't to a tty
X-Send-Pr-Version: 3.2

>Number:         25855
>Category:       bin
>Synopsis:       /bin/ps issue when output isn't to a tty
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 16 12:10:01 PST 2001
>Closed-Date:    Wed Mar 28 11:07:46 PST 2001
>Last-Modified:  Wed Mar 28 11:08:10 PST 2001
>Originator:     Jordan DeLong
>Release:        FreeBSD 4.2-RELEASE i386
>Organization:
N/A
>Environment:

	N/A
	
>Description:

	When the output from /bin/ps is piped to another program, it limits it's output to
	a width of 79 cols.  This causes problems with commands such as:
	ps aux | grep httpd
	because if the httpd part is past the 79 col mark, the grep wont find it.  right
	now the way around this is to use
	ps wwaux | grep httpd
	but it doesn't make sense to have to specify terminal "width" if the output isn't to
	a terminal

>How-To-Repeat:

	easiest way to repeat is to use the -e options so nothing will manage to be in the
	<79 cols for the grep to read it.  so for instance:
	# ps eaxu | grep getty
	will not show anything.
	
>Fix:

	this checks if the stdout is a tty before limiting the cols used

diff -crN /usr/src/bin/ps/ps.c ps/ps.c
*** /usr/src/bin/ps/ps.c	Sat Jul  8 05:14:43 2000
--- ps/ps.c	Fri Mar 16 10:56:18 2001
***************
*** 127,139 ****
  
  	(void) setlocale(LC_ALL, "");
  
! 	if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
! 	     ioctl(STDERR_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
! 	     ioctl(STDIN_FILENO,  TIOCGWINSZ, (char *)&ws) == -1) ||
! 	     ws.ws_col == 0)
! 		termwidth = 79;
! 	else
! 		termwidth = ws.ws_col - 1;
  
  	if (argc > 1)
  		argv[1] = kludge_oldps_options(argv[1]);
--- 127,143 ----
  
  	(void) setlocale(LC_ALL, "");
  
! 	if (isatty(STDOUT_FILENO)) {
! 		if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
! 		     ioctl(STDERR_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
! 		     ioctl(STDIN_FILENO,  TIOCGWINSZ, (char *)&ws) == -1) ||
! 		     ws.ws_col == 0)
! 			termwidth = 79;
! 		else
! 			termwidth = ws.ws_col - 1;
! 	} else {
! 		termwidth = UNLIMITED;
! 	}
  
  	if (argc > 1)
  		argv[1] = kludge_oldps_options(argv[1]);

>Release-Note:
>Audit-Trail:

From: Peter Pentchev <roam@orbitel.bg>
To: fracture@allusion.net
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/25855: /bin/ps issue when output isn't to a tty
Date: Fri, 16 Mar 2001 22:14:26 +0200

 I don't really think this would be such a good idea; does ps already
 do something different when stdout is not a terminal?  If not, wouldn't
 this be an (arguably minor) POLA violation?
 
 G'luck,
 Peter
 
 -- 
 This inert sentence is my body, but my soul is alive, dancing in the sparks of your brain.
 
 On Fri, Mar 16, 2001 at 12:51:56PM +0000, fracture@allusion.net wrote:
 > 
 > >Number:         25855
 > >Category:       bin
 > >Synopsis:       /bin/ps issue when output isn't to a tty
 > >Originator:     Jordan DeLong
 > >Release:        FreeBSD 4.2-RELEASE i386
 > >Organization:
 > N/A
 > >Environment:
 > 
 > 	N/A
 > 	
 > >Description:
 > 
 > 	When the output from /bin/ps is piped to another program, it limits it's output to
 > 	a width of 79 cols.  This causes problems with commands such as:
 > 	ps aux | grep httpd
 > 	because if the httpd part is past the 79 col mark, the grep wont find it.  right
 > 	now the way around this is to use
 > 	ps wwaux | grep httpd
 > 	but it doesn't make sense to have to specify terminal "width" if the output isn't to
 > 	a terminal

From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To: fracture@allusion.net
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: bin/25855: /bin/ps issue when output isn't to a tty
Date: Fri, 16 Mar 2001 15:50:47 -0500 (EST)

 <<On Fri, 16 Mar 2001 12:51:56 GMT, fracture@allusion.net said:
 
 >now the way around this is to use
 >ps wwaux | grep httpd
 >but it doesn't make sense to have to specify terminal "width" if the output isn't to
 >a terminal
 
 Your fix breaks the case of:
 
 	ps aux | more
 
 -GAWollman
 
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Wed Mar 28 11:07:46 PST 2001 
State-Changed-Why:  
I think the reason for the 'w' option in the first place is 
to disable the default window-width setting. 

As Wollman notes, breaking a very common case would hurt POLA. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=25855 
>Unformatted:
