]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tty: fix exit code with EINVAL
authorPádraig Brady <P@draigBrady.com>
Wed, 30 Aug 2017 07:55:34 +0000 (00:55 -0700)
committerPádraig Brady <P@draigBrady.com>
Wed, 30 Aug 2017 08:29:53 +0000 (01:29 -0700)
* src/tty.c (main): All systems mention that isatty()
man return EINVAL as well as (the POSIX compliant) ENOTTY.
Also Centos 6 was seen to return EINVAL from ttyname().
* tests/misc/tty.sh: Fix a test issue where we assume
standard input is always a valid tty.
Reported by Assaf Gordon on OpenSolaris 5.10 and 5.11,
and Centos 6.5

src/tty.c
tests/misc/tty.sh

index e84c35367eaa21556574a5de53efebec72490293..994b3561104a12e0952d6ffd04196a7583c2a0ae 100644 (file)
--- a/src/tty.c
+++ b/src/tty.c
@@ -119,7 +119,7 @@ main (int argc, char **argv)
 
   if (silent)
     return (isatty (STDIN_FILENO) ? EXIT_SUCCESS
-            : errno == ENOTTY ? TTY_STDIN_NOTTY
+            : (errno == ENOTTY || errno == EINVAL) ? TTY_STDIN_NOTTY
             : TTY_STDIN_ERROR);
 
   int status = EXIT_SUCCESS;
@@ -127,7 +127,7 @@ main (int argc, char **argv)
 
   if (! tty)
     {
-      if (errno != ENOTTY)
+      if (errno != ENOTTY && errno != EINVAL)
         error (TTY_STDIN_ERROR, errno, _("standard input"));
       tty = _("not a tty");
       status = TTY_STDIN_NOTTY;
index 5931350ef383f5053bfe34149e00a74d148e0133..904b5d6a29cf659bd1a04f674b526a63882bfbc1 100755 (executable)
@@ -32,7 +32,9 @@ returns_ 2 tty a || fail=1
 returns_ 2 tty -s a || fail=1
 
 if test -w /dev/full && test -c /dev/full; then
-  returns_ 3 tty >/dev/full || fail=1
+  if test -t 0; then
+    returns_ 3 tty >/dev/full || fail=1
+  fi
   returns_ 3 tty </dev/null >/dev/full || fail=1
 fi