From owner-svn-src-head@freebsd.org Sun Jan 28 17:25:50 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E0CE0ED3D74 for ; Sun, 28 Jan 2018 17:25:49 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-it0-x231.google.com (mail-it0-x231.google.com [IPv6:2607:f8b0:4001:c0b::231]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6565B86872 for ; Sun, 28 Jan 2018 17:25:49 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-it0-x231.google.com with SMTP id x128so5658197ite.0 for ; Sun, 28 Jan 2018 09:25:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=TEwx8lRNXCvYsIMNgS6MKDCyZ6rYNB9T/XLMguMK4eY=; b=XedTGo80jkYGIb3oAHke9QidE7ZZKX8WB4U62VfimxzFdoslhA6o6E7JAHRoJeX29j h564ysXFocrikk9vGLMAg6IMQpgA6b5Iz02k9zmahyi6mqbIBIC65CQVdd+ChC7rZdoc kt4wJImkx4yjhjNg1Zx/K8Q+kfsyW1JPNxC3SyaDgeqYmOMYHeGS6pQpWCeQlJ1zwk6j vDrqT6NsFULbrjE4Bp9eCmi6Rz7XxrTJx/rD1+OF6yA7ZtHb0Mcfmy+D836OTRb44Wzl U1goIBJxmiP/6Xwo32xQt6m8D/1k8tunYDHVZChrZsV2jo0RuruHgaAACN7s+EoCrmCZ aVnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=TEwx8lRNXCvYsIMNgS6MKDCyZ6rYNB9T/XLMguMK4eY=; b=mpiInzooAXHuYDVcsZD3pzlwC6AaGnOyWXMZnwDVQkFdZyIJvAxJ92zoknf1KUEWF2 HPiEw64Xa77UUA4tCVZJMuk9MRyg3UI89sYM9bKl6M8KRnZCyOnNgbOK/Zd1ljadt/vK HMxnQwf98MhZrfUlvOzzzg1WuMWmNvOI14Q7QO6opEtpflc2zHMmFFEL1p4BnlB3Yfah CC8jHmnB728MCrL0cFo3EFAdb8qv8Exjs/34P1jt2s9IsYTZk1V1JR0DOstTo8nlPRho 6UsVYETz+au7pWcCsAcq588QNcHhOA8DaQTcLPGRPcV263HaC3o4UMMyjJsXi/o/wbf6 VflQ== X-Gm-Message-State: AKwxytftSqbmuz7qHCeFzU25KobYHfOTb90hIHj1n8WMJnwB945l9lQE cgNr2CnJyTuQbZkyliugggRnUfBvn+uB6SSuZYbAgA== X-Google-Smtp-Source: AH8x225ULEzwa+2xxcXjM3Xvbx3zvxI++boPD9Fg8+Kodm9fS/cLpSPTpmGJYNo3rZR3DA0d3LIoJiHqPZnsowxbSrE= X-Received: by 10.36.146.196 with SMTP id l187mr25102316itd.115.1517160348597; Sun, 28 Jan 2018 09:25:48 -0800 (PST) MIME-Version: 1.0 Sender: wlosh@bsdimp.com Received: by 10.79.201.67 with HTTP; Sun, 28 Jan 2018 09:25:47 -0800 (PST) X-Originating-IP: [2607:fb90:6ec9:766c:fdd8:b127:f55c:b56a] Received: by 10.79.201.67 with HTTP; Sun, 28 Jan 2018 09:25:47 -0800 (PST) In-Reply-To: <201801281622.w0SGMupF055172@mail.karels.net> References: <201703042238.v24McAD8008837@repo.freebsd.org> <201801281622.w0SGMupF055172@mail.karels.net> From: Warner Losh Date: Sun, 28 Jan 2018 10:25:47 -0700 X-Google-Sender-Auth: yz80A7AinFKxBpTHpN63lrYDBfA Message-ID: Subject: Re: ps output line length (was: svn commit: r314685 - head/bin/ps) To: Mike Karels Cc: "Conrad E. Meyer" , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.25 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Jan 2018 17:25:50 -0000 On Jan 28, 2018 9:51 AM, "Mike Karels" wrote: Recently, I was investigating an issue with top on -current while doing a "make buildworld", and ran "ps axu|more" for comparison. To my surprise, I got only a few very long lines of output, containing full command lines for compiler runs. This quickly led me to the following commit, which I unfortunately missed at the time, along with the following discussion: > 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 hardcoded width has some history: In The Beginning of History[0], the > width of ps was hardcoded as 80 bytes. In 1985, Bloom@ added detection > using TIOCGWINSZ on stdin.[1] In 1986, Kirk merged a change to check > stdout's window size instead. In 1990, the fallback checks to stderr and > stdin's TIOCGWINSZ were added by Marc@, with the commit message "new > version."[2] > > OS X Darwin has a very similar modification to ps(1), which simply sets > UNLIMITED for all non-tty outputs.[3] I've chosen to respect COLUMNS > instead of behaving identically to Darwin here, but I don't feel strongly > about that. We could match OS X for parity if that is desired. > > [0]: https://svnweb.freebsd.org/csrg/bin/ps/ps.c?annotate=1065 > [1]: https://svnweb.freebsd.org/csrg/bin/ps/ps.c?r1=18105&r2=18106 > [2]: > https://svnweb.freebsd.org/csrg/bin/ps/ps.c?r1=40675&r2= 40674&pathrev=40675 > [3]: > https://opensource.apple.com/source/adv_cmds/adv_cmds-168/ ps/ps.c.auto.html > > PR: 217159 > Reported by: Deepak Nagaraj > Modified: > head/bin/ps/ps.c > Modified: head/bin/ps/ps.c > ============================================================ ================== > --- 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[]) > > if ((cols = getenv("COLUMNS")) != NULL && *cols != '\0') > termwidth = atoi(cols); > + else if (!isatty(STDOUT_FILENO)) > + termwidth = UNLIMITED; > else if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 && > ioctl(STDERR_FILENO, TIOCGWINSZ, (char *)&ws) == -1 && > ioctl(STDIN_FILENO, TIOCGWINSZ, (char *)&ws) == -1) || There were several following messages discussing this change, most notably one by Bruce Evans (https://docs.freebsd.org/cgi/getmsg.cgi?fetch=55022+0+ archive/2017/svn-src-head/20170312.svn-src-head). I agree with his rational, and disagree with the change. It seems to me that the consensus was that the change was incorrect, although that might just be my opinion. However, I really think that the change needs to be reverted. The rationale for the original code was that, for interactive uses, the output line length should be the same for "ps ...", "ps ...|more", and "ps ... |grep". The -w option exists to make the line longer; there is no option to use the terminal size even if the output is redirected. Hence, the tests for stderr or stdin being a tty. This behavior has been in place since 1990, as noted, and no substantial rationale has been given for changing it other than "it doesn't matter if you use less with side-to-side scrolling." fwiw, I'm sure I discussed that code with Marc at the time. As was stated, scripts that want to use the full line should use -ww. Interactive users have long been used to using -w when they need longer output lines, e.g. to match patterns that don't occur within a screen's width. I propose reverting this change. I tend to agree, but auxww is hard coded into my fingers. Warner