From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13257 Path: news.gmane.org!.POSTED!not-for-mail From: Benjamin Peterson Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] return EBADF from ttyname_r Date: Thu, 13 Sep 2018 09:25:40 -0700 Message-ID: <1536855940.1011892.1507091216.5EC78F32@webmail.messagingengine.com> References: <20180913003424.12234-1-benjamin@python.org> <20180913085314.GR4418@port70.net> <20180913152916.GI1878@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1536855829 14924 195.159.176.226 (13 Sep 2018 16:23:49 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 13 Sep 2018 16:23:49 +0000 (UTC) To: Rich Felker , musl@lists.openwall.com Original-X-From: musl-return-13273-gllmg-musl=m.gmane.org@lists.openwall.com Thu Sep 13 18:23:45 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1g0UPB-0003nR-Bf for gllmg-musl@m.gmane.org; Thu, 13 Sep 2018 18:23:45 +0200 Original-Received: (qmail 23583 invoked by uid 550); 13 Sep 2018 16:25:54 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 23560 invoked from network); 13 Sep 2018 16:25:53 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=python.org; s=200901; t=1536855942; bh=6HUjpB8Oq8ccLiS/XyGxGJYa1uUrSwFUFx/VGUQG/P0=; h=From:To:References:Subject:In-Reply-To:Date:From; b=ijVQPg5DV+ZKH3SWEClqSbZ3MbWhoExJSbHa/2vb7nREQ0ztNgxm/oiIMmF/TnfH2 fJfUbcE0Tm960DgQ6MEP0ifeEvLSnMRCXyCq4/khtwoCfGTj/nkd+Ph8gZk3CisBSt Y5tOGN+LITK9oV6Q8rHEia5cnUtTqfXa9y2REwN4= X-ME-Proxy: X-ME-Sender: X-Mailer: MessagingEngine.com Webmail Interface - ajax-e556cd15 In-Reply-To: <20180913152916.GI1878@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:13257 Archived-At: Thank you for the feedback. On Thu, Sep 13, 2018, at 08:29, Rich Felker wrote: > On Thu, Sep 13, 2018 at 10:53:14AM +0200, Szabolcs Nagy wrote: > > * Benjamin Peterson [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. Right, I don't claim this patch fixes a bug; just makes the error reporting more precise. > > > > > - 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. Good point. > > > > 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. I will send another patch to this effect. > > Rich