|
Message-ID: <20180913152916.GI1878@brightrain.aerifal.cx> Date: Thu, 13 Sep 2018 11:29:16 -0400 From: Rich Felker <dalias@...c.org> To: musl@...ts.openwall.com Cc: Benjamin Peterson <benjamin@...hon.org> Subject: Re: [PATCH] return EBADF from ttyname_r On Thu, Sep 13, 2018 at 10:53:14AM +0200, Szabolcs Nagy wrote: > * Benjamin Peterson <benjamin@...hon.org> [2018-09-12 17:34:24 -0700]: > > POSIX allows ttyname(_r) to return EBADF if passed file descriptor is invalid. > > i think EBADF is always a 'may fail' in posix, so not strictly required. > > > - if (!isatty(fd)) return ENOTTY; > > + if (!isatty(fd)) { > > + if (errno == EBADF) return EBADF; > > + return ENOTTY; > > + } > > musl isatty uses __syscall which does not set errno so this is wrong. > > note that on glibc isatty sets errno according what the kernel returns > however linux has different code paths in ioctl for different type of > fds and in some cases it can fail in interesting ways (iirc on a socket > fd it will fail with EINVAL or EFAULT at least on some linux versions > and it can even spuriously succeed on non-tty fds because the TCGETS > ioctl command was reused on some audio device to do different things) That's why we no longer use TCGETS but rather TIOCGWINSZ. > this means users cannot rely on errno value being sane, > so there is not much point trying to do something fancy here. I'm not sure this is actually an issue anymore, but if it is, we should simply translate anything other than EBADF to ENOTTY. There is no other meaningful error. Either the fd is valid or it's not, and if it is valid, either it is a tty or it's not. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.