Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Mar 2017 16:53:46 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Bryan Drewery <bdrewery@freebsd.org>
Cc:        Conrad Meyer <cem@freebsd.org>, src-committers@freebsd.org,  svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r314685 - head/bin/ps
Message-ID:  <20170307161527.X10112@besplex.bde.org>
In-Reply-To: <52877752-ab4b-45ea-05f4-ef050e1a2983@FreeBSD.org>
References:  <201703042238.v24McAD8008837@repo.freebsd.org> <01dddec8-89c0-e18a-a481-e802643f9e0e@FreeBSD.org> <52877752-ab4b-45ea-05f4-ef050e1a2983@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 6 Mar 2017, Bryan Drewery wrote:

> On 3/6/17 8:11 PM, Bryan Drewery wrote:
>> On 3/4/17 2:38 PM, Conrad Meyer wrote:
>>> Author: cem
>>> Date: Sat Mar  4 22:38:10 2017
>>> New Revision: 314685
>>> URL: https://svnweb.freebsd.org/changeset/base/314685
>>>
>>> Log:
>>>   ps(1): Only detect terminal width if stdout is a tty
>>>
>>>   If stdout isn't a tty, use unlimited width output rather than truncating to
>>>   79 characters.  This is helpful for shell scripts or e.g., 'ps | grep foo'.
>>
>> This change actually makes things worse for me for 'ps uaxwd|less'

No surprise.

>> Before:
>>> nobody  83979    0.0  0.0        9016   1364  3  I+J  20:03       0:00.06 | |         `-- /usr/bin/make -C /usr/ports/lang/perl5.24 build
>>
>> After:
>>> nobody  89743    0.0  0.0        9016   1368  3  S+J  20:07       0:00.05 | |         `-- /usr/bin/make -C /usr/ports/lang/perl5.24
>>
>> I now have to specify -ww to not cut things off, but that's far more
>> than I want to see.
>
> The problem is that -w is parsed *after* termwidth = UNLIMITED is set
> (which is 0).  This patch fixes it, but I haven't tested it extensively:
>
>> Index: ps.c
>> ===================================================================
>> --- ps.c        (revision 314708)
>> +++ ps.c        (working copy)
>> @@ -401,7 +401,7 @@ main(int argc, char *argv[])
>>                 case 'w':
>>                         if (wflag)
>>                                 termwidth = UNLIMITED;
>> -                       else if (termwidth < 131)
>> +                       else if (termwidth < 131 && termwidth != UNLIMITED)
>>                                 termwidth = 131;

I pointed out many nearby bugs, but missed this one.  0 is a fail-unsafe
value for UNLIMITED.  0 for the default width of 79 unless modified by
-w and INT_MAX for UNLIMITED would be less magic.

ps now has complications using xo.  It now uses the POSIX mistake
_POSIX2_LINE_MAX for at least xo output, so UNLIMITED no longer means
unlimited.  _POSIX2_LINE_MAX is only 2048.  Probably good enough for
ps.  So UNLIMITED should be unobfuscated by spelling it
(_POSIX2_LINE_MAX - 1).  The user's COLUMNS is not honored when it is
larger than this, and the user can do foot shooting by setting COLUMNS
to the current internal magic value for UNLIMIT or exercise sign extension
and overflow bugs by setting it to negative.  'COLUMNS=-1 ps' actually
gives normal output except for messing up the COMAMND column (e.g.,
"-bash (bash)" becomes "[bash]".  I forget what the brackets mean, and
this is not documented in ps.1.

>>                         wflag++;
>>                         break;
>
> -1 for the original commit. If I wanted -ww I would specify it.  The
> original commit causes some text to wrap on my terminal even with some
> extending right.

Bruce



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