Soumendra Ganguly <soumen...@tamu.edu> wrote:

> based on the fact that tty operations should not be performed on stdin
> if it is not a tty [ maybe it is a regular file ]. This observation
> was made by bl...@openbsd.org. I claim that only
> 
>               if (tcgetattr(STDIN_FILENO, &tt) == 0 &&
>                   ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == 0)
>                       istty = 1;
> 
> would have been sufficient because tcgetattr will fail with errno ==
> ENOTTY if stdin is not a tty. Am I wrong? This claim is true on
> NetBSD/FreeBSD because their versions of isatty simply make a call to
> tcgetattr to see it it succeeds. However, the OpenBSD version [
> /lib/libc/gen/isatty.c ] calls fcntl with F_ISATTY, which also, like
> tcgetattr, sets errno to ENOTTY if the fd is not a tty [ sys_fcntl()
> from /sys/kern/kern_descrip.c ].
> 
> Additional note: tcgetattr calls ioctl with TIOCGETA [
> /lib/libc/termios/tcgetattr.c  and ttioctl() from /sys/kern/tty.c ].

isatty() using fcntl+F_ISATTY rather than ioctl was to permit
pledge-heavy programs to eliminate all ioctl use.  isatty() was the most
significant hidden ioctl() system call use in some important programs,
so I changed introduced F_ISATTY, changed libc isatty(), and then those
specific programs could be avoid ioctl() usage and become simpler.

But if I undestand correctly this program always does ioctl afterwards,
and when those ioctl indicate ENOTTY, it does the right thing, so why
bother calling isatty()?  I doubt it can be pledged further, to entirely
avoid ioctl, without increasing the complexity excessively, so why
bother adding additional conditions?

I've given up trying to follow all your proposals, because there are so
many, and they are so mixed up.  I have completely lost track of what
problem you are trying to solve (you may see one real problem, but you
keep jumping around with small nits which others don't see).  I am
started wondering if you are only doing this to leave your mark. Sorry,
that's my take on it.  I'm done.

Reply via email to