Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Mar 2017 20:26:14 -0800
From:      Bryan Drewery <bdrewery@FreeBSD.org>
To:        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:  <52877752-ab4b-45ea-05f4-ef050e1a2983@FreeBSD.org>
In-Reply-To: <01dddec8-89c0-e18a-a481-e802643f9e0e@FreeBSD.org>
References:  <201703042238.v24McAD8008837@repo.freebsd.org> <01dddec8-89c0-e18a-a481-e802643f9e0e@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--gTltGfjTpF8TIjHLg0sX0GM4Qr512rC7f
Content-Type: multipart/mixed; boundary="iCNvVh0AeaLkKqtwAFqavhhXGPHmuODwi";
 protected-headers="v1"
From: Bryan Drewery <bdrewery@FreeBSD.org>
To: Conrad Meyer <cem@FreeBSD.org>, src-committers@freebsd.org,
 svn-src-all@freebsd.org, svn-src-head@freebsd.org
Message-ID: <52877752-ab4b-45ea-05f4-ef050e1a2983@FreeBSD.org>
Subject: Re: svn commit: r314685 - head/bin/ps
References: <201703042238.v24McAD8008837@repo.freebsd.org>
 <01dddec8-89c0-e18a-a481-e802643f9e0e@FreeBSD.org>
In-Reply-To: <01dddec8-89c0-e18a-a481-e802643f9e0e@FreeBSD.org>

--iCNvVh0AeaLkKqtwAFqavhhXGPHmuODwi
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

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
>>  =20
>>   If stdout isn't a tty, use unlimited width output rather than trunca=
ting to
>>   79 characters.  This is helpful for shell scripts or e.g., 'ps | gre=
p foo'.
>=20
> This change actually makes things worse for me for 'ps uaxwd|less'
>=20
> Before:
>> nobody  83979    0.0  0.0        9016   1364  3  I+J  20:03       0:00=
=2E06 | |         `-- /usr/bin/make -C /usr/ports/lang/perl5.24 build
>=20
> After:
>> nobody  89743    0.0  0.0        9016   1368  3  S+J  20:07       0:00=
=2E05 | |         `-- /usr/bin/make -C /usr/ports/lang/perl5.24
>=20
>=20
> I now have to specify -ww to not cut things off, but that's far more
> than I want to see.
>=20

The problem is that -w is parsed *after* termwidth =3D UNLIMITED is set
(which is 0).  This patch fixes it, but I haven't tested it extensively:

> Index: ps.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> --- ps.c        (revision 314708)
> +++ ps.c        (working copy)
> @@ -401,7 +401,7 @@ main(int argc, char *argv[])
>                 case 'w':
>                         if (wflag)
>                                 termwidth =3D UNLIMITED;
> -                       else if (termwidth < 131)
> +                       else if (termwidth < 131 && termwidth !=3D UNLI=
MITED)
>                                 termwidth =3D 131;
>                         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.

>=20
>>  =20
>>   This hardcoded width has some history: In The Beginning of History[0=
], the
>>   width of ps was hardcoded as 80 bytes.  In 1985, Bloom@ added detect=
ion
>>   using TIOCGWINSZ on stdin.[1]  In 1986, Kirk merged a change to chec=
k
>>   stdout's window size instead.  In 1990, the fallback checks to stder=
r and
>>   stdin's TIOCGWINSZ were added by Marc@, with the commit message "new=

>>   version."[2]
>>  =20
>>   OS X Darwin has a very similar modification to ps(1), which simply s=
ets
>>   UNLIMITED for all non-tty outputs.[3]  I've chosen to respect COLUMN=
S
>>   instead of behaving identically to Darwin here, but I don't feel str=
ongly
>>   about that.  We could match OS X for parity if that is desired.
>>  =20
>>   [0]: https://svnweb.freebsd.org/csrg/bin/ps/ps.c?annotate=3D1065
>>   [1]: https://svnweb.freebsd.org/csrg/bin/ps/ps.c?r1=3D18105&r2=3D181=
06
>>   [2]:
>>   https://svnweb.freebsd.org/csrg/bin/ps/ps.c?r1=3D40675&r2=3D40674&pa=
threv=3D40675
>>   [3]:
>>   https://opensource.apple.com/source/adv_cmds/adv_cmds-168/ps/ps.c.au=
to.html
>>  =20
>>   PR:		217159
>>   Reported by:	Deepak Nagaraj <n.deepak at gmail.com>
>>
>> Modified:
>>   head/bin/ps/ps.c
>>
>> Modified: head/bin/ps/ps.c
>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
>> --- head/bin/ps/ps.c	Sat Mar  4 22:23:59 2017	(r314684)
>> +++ head/bin/ps/ps.c	Sat Mar  4 22:38:10 2017	(r314685)
>> @@ -194,6 +194,8 @@ main(int argc, char *argv[])
>> =20
>>  	if ((cols =3D getenv("COLUMNS")) !=3D NULL && *cols !=3D '\0')
>>  		termwidth =3D atoi(cols);
>> +	else if (!isatty(STDOUT_FILENO))
>> +		termwidth =3D UNLIMITED;
>>  	else if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) =3D=3D -1 &&=

>>  	     ioctl(STDERR_FILENO, TIOCGWINSZ, (char *)&ws) =3D=3D -1 &&
>>  	     ioctl(STDIN_FILENO,  TIOCGWINSZ, (char *)&ws) =3D=3D -1) ||
>>
>=20
>=20


--=20
Regards,
Bryan Drewery


--iCNvVh0AeaLkKqtwAFqavhhXGPHmuODwi--

--gTltGfjTpF8TIjHLg0sX0GM4Qr512rC7f
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - https://gpgtools.org

iQEcBAEBCgAGBQJYvjZnAAoJEDXXcbtuRpfPmy4IAI/QQ221scyCn/YVDRrGIqlo
de6gbWzK9PX7ARLFUQHbvhTVX9jrsKFlxvagPq3iVdUOKDejgimzDafXl3w4Ya5W
bZB0+uK/Laz1OeLeoS34k6kV1dEhlMhBT9ZFU0hGasA+hcWiSNAZWMoGFJAPzHqs
Qj1JI+DHP7zHi8vwguXkgOorSxVvE044vXGys1w1O/HQwCEZWWa/LUA04Kp9mu6k
u7GUXN4dBmpZ920vd1qX8ELSUbq+OdQV9V2LxUy1EMQvBEiK+l2ntPnhuEVrm6U1
0cK/6pMtw9lU7S6YbyGJ22lquLybbCGw3Hf+3Po7/Xxbc0o6Bo+pNamA1pXPFyM=
=291A
-----END PGP SIGNATURE-----

--gTltGfjTpF8TIjHLg0sX0GM4Qr512rC7f--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?52877752-ab4b-45ea-05f4-ef050e1a2983>