From owner-svn-src-head@freebsd.org Sat Mar 4 23:08:43 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 18CDBCF8796; Sat, 4 Mar 2017 23:08:43 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) (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 AD921185D; Sat, 4 Mar 2017 23:08:42 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-wm0-f46.google.com with SMTP id n11so39092554wma.1; Sat, 04 Mar 2017 15:08:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc; bh=Yuq1AbRU4eLZThOCaKgG57PAsJa4D/MGkytWHC9q94M=; b=rZyOwzi4rKR43V6f9id4ZXfdrJ8U5XnYdLxoIwP5zSlvFMG2br2UQscY9L9zk6GEi8 TNNB8jmgWweikDjX5/NI3dM1jzhdKNnKRFe+6u1mRQldFE/zw7D5/kZRpX84eHDFYIJ4 UglpXBFDG6kwZz79q2dhKh4xiSocX5UVMIXFvEkP5+Tw8B2zjD1bHcadQGtbcvJXucIc /IBdxSjsc2fTGCjz08oLMalJXtdpktLBciuUH4MICNAWYpwJa0ApcLjk+HYKUGYZEEKF U7TO9bV/1RRO7wr2mQ4kjYzgOyJNO7M/4wDCn+qHKAt6uFOxCifmPFR0qlJ2eagH78Z9 XKwA== X-Gm-Message-State: AMke39nOEJhYafaYP4dakF5jYtyUWpwwTJeUWNcgtDL/KIazDdPRwJBCetbNORJuL+x0qQ== X-Received: by 10.28.158.193 with SMTP id h184mr8075010wme.59.1488668915259; Sat, 04 Mar 2017 15:08:35 -0800 (PST) Received: from mail-wr0-f182.google.com (mail-wr0-f182.google.com. [209.85.128.182]) by smtp.gmail.com with ESMTPSA id 10sm8652553wmi.23.2017.03.04.15.08.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Mar 2017 15:08:35 -0800 (PST) Received: by mail-wr0-f182.google.com with SMTP id l37so94602049wrc.1; Sat, 04 Mar 2017 15:08:35 -0800 (PST) X-Received: by 10.223.162.211 with SMTP id t19mr8340433wra.57.1488668914966; Sat, 04 Mar 2017 15:08:34 -0800 (PST) MIME-Version: 1.0 Reply-To: cem@freebsd.org Received: by 10.80.169.4 with HTTP; Sat, 4 Mar 2017 15:08:34 -0800 (PST) In-Reply-To: References: <201703042238.v24McAD8008837@repo.freebsd.org> From: Conrad Meyer Date: Sat, 4 Mar 2017 15:08:34 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r314685 - head/bin/ps To: Ed Schouten Cc: src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 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: Sat, 04 Mar 2017 23:08:43 -0000 Hi Ed, On Sat, Mar 4, 2017 at 2:58 PM, Ed Schouten wrote: >> @@ -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) || >> > > I think you can actually go ahead and simplify this a bit: > > - If something is a TTY, then our implementation of the TTY layer > guarantees that TIOCGWINSZ always works. Do you know if it did in 1990 too? It's hard to tell why Marc@ made this change way back then. I wasn't sure so I left it alone. > - If we're only interested in testing stdout whether it's a TTY, I > think it makes little sense to check TIOCGWINSZ on stdin, stderr. > > I think there would therefore be very little harm to use something like this: > > | if ((cols = getenv("COLUMNS")) != NULL && *cols != '\0') > | termwidth = atoi(cols); > | else if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == > -1 && ws.ws_row == 0) Shouldn't this remain || ws.ws_row == 0? > | termwidth = UNLIMITED; > | else > | termwidth = ws.ws_col - 1; I had a very similar cleanup in mind (|| instead of &&). But I wasn't sure if there was any reason TIOCGWINSZ might fail on stdout (and why that change was added originally). Best, Conrad