]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/colors: care about colors only on tty()
authorKarel Zak <kzak@redhat.com>
Wed, 12 Mar 2014 08:27:10 +0000 (09:27 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 12 Mar 2014 08:27:10 +0000 (09:27 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/colors.c

index 03ac7118f30b559d85d0a40377f34c10a5a95a05..8b6f089e1a225c4f56d69fe4d99c78123b3bc6e8 100644 (file)
@@ -16,7 +16,9 @@ static int ul_color_term_ok;
 
 int colors_init(int mode, const char *name)
 {
-       if (mode == UL_COLORMODE_UNDEF) {
+       int atty = -1;
+
+       if (mode == UL_COLORMODE_UNDEF && (atty = isatty(STDOUT_FILENO))) {
                char path[PATH_MAX];
 
                snprintf(path, sizeof(path), "%s%s%s",
@@ -38,7 +40,7 @@ int colors_init(int mode, const char *name)
 
        switch (mode) {
        case UL_COLORMODE_AUTO:
-               ul_color_term_ok = isatty(STDOUT_FILENO);
+               ul_color_term_ok = atty == -1 ? isatty(STDOUT_FILENO) : atty;
                break;
        case UL_COLORMODE_ALWAYS:
                ul_color_term_ok = 1;