From owner-svn-src-head@freebsd.org Sat Mar 4 22:59:08 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 091FFCF848B for ; Sat, 4 Mar 2017 22:59:08 +0000 (UTC) (envelope-from ed@nuxi.nl) Received: from mail-yw0-x22f.google.com (mail-yw0-x22f.google.com [IPv6:2607:f8b0:4002:c05::22f]) (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 BE5F310D7 for ; Sat, 4 Mar 2017 22:59:07 +0000 (UTC) (envelope-from ed@nuxi.nl) Received: by mail-yw0-x22f.google.com with SMTP id v76so971668ywg.0 for ; Sat, 04 Mar 2017 14:59:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuxi-nl.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=HhFjUEOK95n8DkzZ4ePef0GGKz7SrT27yUDCiYQJ1Rc=; b=qwf9VlTRXMh5nOam4mh4vOyZBOZuQ5H6P3sq/w/Ev3dhfBTV6gx2y+8OteYQnjhzCZ UauTbdJIwqOAaCfEbq1bN4427pEfgVocmDukqg6+J5eRl4QHKB2Pawx5fN+Q8Eq/TSp9 g4viW4Pi94tZXc8LK6CQGemgc5cpQ0kfZSAWVgUC+DVSHxd8KMe7SGGs5l9KrTlYz/Bo 9RKT8SbULC7+essz9pM5VYqQQCt6irMise4ygxsTaaxul4simLHVirXoPwQEFesWNk0t P81URj57rJIW7Nb5STqud714jZSgiixu0PZbixjkywcMa/ztqkGtCxIl0zwj6qYMP9nt qO9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=HhFjUEOK95n8DkzZ4ePef0GGKz7SrT27yUDCiYQJ1Rc=; b=Nd9Q4HEss6g5KFW9sbRHFw2SWiwdOaDKUI+aamafN8F9qOy6XEprVqQF1qhqxJ5h78 U23PZGAJc+HYn84arJi3MZv6RNCMnytbP3KM/ZptocBsAza5tDtu2eJKk0qIrQCgB+YH H3fvJIKxbJQgnjgvOHjrSKCCwo+GNj2dYdsIxa3L9C16aNMl1h7CAFQBFGXsQ28/WcC2 RdSdpY6FYhb0BxrCekUZv1Lg/mopf4ndKRSAb5NDh93jBOeSYS8/vUfPJ3njnwcvO82f UqR0kpKnD87Rl6JqxlJvdjnnhbpbg7ypMCab2yku8kfW2HS7aNY0qTt4mEZN20HRzkZQ 3Ulg== X-Gm-Message-State: AMke39l/uo8iZT3+hHgx5PzWL6Qx4rsoZ8CvOhOO3DTmgRbSp8lyn4rPhGqUuDej9D4uIk9gv+s6VH/7No+lVQ== X-Received: by 10.37.224.138 with SMTP id x132mr6496234ybg.168.1488668346559; Sat, 04 Mar 2017 14:59:06 -0800 (PST) MIME-Version: 1.0 Received: by 10.129.51.198 with HTTP; Sat, 4 Mar 2017 14:58:36 -0800 (PST) In-Reply-To: <201703042238.v24McAD8008837@repo.freebsd.org> References: <201703042238.v24McAD8008837@repo.freebsd.org> From: Ed Schouten Date: Sat, 4 Mar 2017 23:58:36 +0100 Message-ID: Subject: Re: svn commit: r314685 - head/bin/ps To: Conrad Meyer 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 22:59:08 -0000 Hi Conrad, 2017-03-04 23:38 GMT+01:00 Conrad Meyer : > Log: > ps(1): Only detect terminal width if stdout is a tty Nice! > 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) || > 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. - 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) | termwidth = UNLIMITED; | else | termwidth = ws.ws_col - 1; -- Ed Schouten Nuxi, 's-Hertogenbosch, the Netherlands KvK-nr.: 62051717