Re: isatty: EINVAL or ENOTTY?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Jakub,

On 2/19/19 10:08 PM, Jakub Wilk wrote:
> The isatty(3) man page says the function fails with EINVAL when "fd 
> refers to a file other than a terminal. POSIX.1 specifies the error 
> ENOTTY for this case."
> 
> But I couldn't reproduce this bug. For me, it fails with ENOTTY, as 
> prescribed by POSIX.
> 
> I've tested this on the following systems:
> * Debian unstable (Linux 4.19, glibc 2.28)
> * CentOS 5.0 (Linux 2.6.16, glibc 2.5)
> 
> The source code for the test program I used is attached.

Thanks for the test program and the report.

So, I'm the one that added that text to the page originally.
I don't remember which kinds of files/devices gave EINVAL
back then, and unfortunately, I did not record info about
the testing I did. But, in the meantime, things seem to
have changed.

As things stand, every non-tty that I test on a recent 
4.x kernel fails with ENOTTY. Back when I wrote the
manual page text 10 years ago, it's less clear.
I went away now and tested a 2.6.32 kernel. FIFOs and pipes
fail with EINVAL, but plain text files and directories
(for example) fail with ENOTTY.

I've applied the patch below.

Cheers,

Michael

diff --git a/man3/isatty.3 b/man3/isatty.3
index 60639c617..ffb0ff24c 100644
--- a/man3/isatty.3
+++ b/man3/isatty.3
@@ -52,13 +52,15 @@ is set to indicate the error.
 .I fd
 is not a valid file descriptor.
 .TP
-.B EINVAL
+.B ENOTTY
 .I fd
 refers to a file other than a terminal.
-POSIX.1 specifies the error
-.BR ENOTTY
-.\" FIXME . File a bug for this?
-for this case.
+On some older kernels, some types of files
+.\" e.g., FIFOs and pipes on 2.6.32)
+resulted in the error
+.B EINVAL
+in this case (which is a violation of POSIX, which specifies the error
+.BR ENOTTY ).
 .SH ATTRIBUTES
 For an explanation of the terms used in this section, see
 .BR attributes (7).

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux