aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorFabian Groffen <grobian@gentoo.org>2019-07-14 10:34:31 +0200
committerFabian Groffen <grobian@gentoo.org>2019-07-14 10:34:31 +0200
commit339297b3247c8850194a48edf1ce03dbfdef337a (patch)
tree45c1ff625b1a322378ceba7276c6c63ef047f6ff /main.c
parentlibq/tree: ensure we don't work on garbage on sorted pkg trees (diff)
downloadportage-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.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/main.c b/main.c
index c5cc4b4c..bdbb2a7b 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;