From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 05105138334 for ; Sun, 14 Jul 2019 08:37:23 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1BD73E086F; Sun, 14 Jul 2019 08:37:22 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D368BE086F for ; Sun, 14 Jul 2019 08:37:21 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 2CE57346445 for ; Sun, 14 Jul 2019 08:37:20 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 8407E4D3 for ; Sun, 14 Jul 2019 08:37:17 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1563093271.339297b3247c8850194a48edf1ce03dbfdef337a.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: main.c X-VCS-Directories: / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 339297b3247c8850194a48edf1ce03dbfdef337a X-VCS-Branch: master Date: Sun, 14 Jul 2019 08:37:17 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 10735c17-d32a-44c5-b725-e842d051a40e X-Archives-Hash: 8b6f2028a1bb5350ea4de968b3c1a622 commit: 339297b3247c8850194a48edf1ce03dbfdef337a Author: Fabian Groffen gentoo org> AuthorDate: Sun Jul 14 08:34:31 2019 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Sun Jul 14 08:34:31 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=339297b3 main: rework terminal-based settings somewhat As pointed out by slyfox, the result from ioctl was ignored and its result used anyway. While at it to fix this, rework the logic somewhat, such that terminal width and colours are always disabled when we're not dealing with a TTY. Bug: https://bugs.gentoo.org/689290#c14 Signed-off-by: Fabian Groffen gentoo.org> main.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index c5cc4b4..bdbb2a7 100644 --- a/main.c +++ b/main.c @@ -780,9 +780,6 @@ int main(int argc, char **argv) struct stat st; struct winsize winsz; - ioctl(0, TIOCGWINSZ, &winsz); - twidth = winsz.ws_col > 0 ? (int)winsz.ws_col : 80; - warnout = stderr; IF_DEBUG(init_coredumps()); argv0 = argv[0]; @@ -791,13 +788,18 @@ int main(int argc, char **argv) bindtextdomain(argv0, CONFIG_EPREFIX "usr/share/locale"); textdomain(argv0); - if (fstat(fileno(stdout), &st) != -1) + twidth = 0; + if (fstat(fileno(stdout), &st) != -1) { if (!isatty(fileno(stdout))) { no_colors(); - twidth = 0; + } else { + if ((getenv("TERM") == NULL) || + (strcmp(getenv("TERM"), "dumb") == 0)) + no_colors(); + if (ioctl(0, TIOCGWINSZ, &winsz) == 0 && winsz.ws_col > 0) + twidth = (int)winsz.ws_col; } - if ((getenv("TERM") == NULL) || (strcmp(getenv("TERM"), "dumb") == 0)) - no_colors(); + } initialize_portage_env(); optind = 0;