diff options
author | Fabian Groffen <grobian@gentoo.org> | 2019-07-14 10:34:31 +0200 |
---|---|---|
committer | Fabian Groffen <grobian@gentoo.org> | 2019-07-14 10:34:31 +0200 |
commit | 339297b3247c8850194a48edf1ce03dbfdef337a (patch) | |
tree | 45c1ff625b1a322378ceba7276c6c63ef047f6ff /main.c | |
parent | libq/tree: ensure we don't work on garbage on sorted pkg trees (diff) | |
download | portage-utils-339297b3247c8850194a48edf1ce03dbfdef337a.tar.gz portage-utils-339297b3247c8850194a48edf1ce03dbfdef337a.tar.bz2 portage-utils-339297b3247c8850194a48edf1ce03dbfdef337a.zip |
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 <grobian@gentoo.org>
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -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; |