Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Mar 2001 12:51:56 GMT
From:      fracture@allusion.net
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/25855: /bin/ps issue when output isn't to a tty
Message-ID:  <200103161251.f2GCpuk22673@cx420564-b.tucson1.az.home.com>

next in thread | raw e-mail | index | archive | help

>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:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 16 12:10:01 PST 2001
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200103161251.f2GCpuk22673>