From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13247 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] return EBADF from ttyname_r Date: Wed, 12 Sep 2018 22:07:34 -0400 Message-ID: <20180913020734.GG1878@brightrain.aerifal.cx> References: <20180913003424.12234-1-benjamin@python.org> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1536804345 14244 195.159.176.226 (13 Sep 2018 02:05:45 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 13 Sep 2018 02:05:45 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-13263-gllmg-musl=m.gmane.org@lists.openwall.com Thu Sep 13 04:05:40 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 1g0H0l-0003cO-8h for gllmg-musl@m.gmane.org; Thu, 13 Sep 2018 04:05:39 +0200 Original-Received: (qmail 9371 invoked by uid 550); 13 Sep 2018 02:07:48 -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 9352 invoked from network); 13 Sep 2018 02:07:47 -0000 Content-Disposition: inline In-Reply-To: <20180913003424.12234-1-benjamin@python.org> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:13247 Archived-At: On Wed, Sep 12, 2018 at 05:34:24PM -0700, Benjamin Peterson wrote: > POSIX allows ttyname(_r) to return EBADF if passed file descriptor is invalid. > --- > src/unistd/ttyname_r.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/src/unistd/ttyname_r.c b/src/unistd/ttyname_r.c > index 33aa4ae1..e208b3c3 100644 > --- a/src/unistd/ttyname_r.c > +++ b/src/unistd/ttyname_r.c > @@ -10,7 +10,10 @@ int ttyname_r(int fd, char *name, size_t size) > char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2]; > ssize_t l; > > - if (!isatty(fd)) return ENOTTY; > + if (!isatty(fd)) { > + if (errno == EBADF) return EBADF; > + return ENOTTY; > + } > > __procfdname(procname, fd); > l = readlink(procname, name, size); > -- > 2.17.1 The EBADF error for isatty is optional and musl's does not set it, so this patch does not work as-is. I think returning ENOTTY for cases for which it does not apply in ttyname_r is non-conforming though, so some change similar to this is probably needed. If isatty were modified to set errno, I think we could just return errno here. Rich