From: Torbjorn SVENSSON <torbjorn.svensson@foss.st.com>
To: <newlib@sourceware.org>
Subject: Re: [PATCH] Fix getlogin() to check only stdin to get a valid tty
Date: Thu, 13 Jul 2023 18:25:16 +0200 [thread overview]
Message-ID: <9ad091f5-4ca9-6410-e990-0cd4f1ece86e@foss.st.com> (raw)
In-Reply-To: <d9e4c327-e623-2a5b-6910-9dfaaea1b7c6@fibranet.cat>
On 2023-07-13 10:06, Jordi Sanfeliu via Newlib wrote:
> Hello Torbjörn,
>
> Thanks for you reply.
>
> It seems to me that this code returns 0 as soon as one of the 3 fds is
> 0, regardless if the rest are valid tty names.
>
> I think that what you meant is this:
>
> if ((tty = ttyname (0)) == 0)
> if ((tty = ttyname (1)) == 0)
> if ((tty = ttyname (2)) == 0)
> return 0;
>
> which IMO would be even a better patch.
>
> What do you think?
Actually, you're right. Sorry for the confusion.
I took a sneak peak at how glibc does this and there is this comment:
/* Get name of tty connected to fd 0. Return NULL if not a tty or
if fd 0 isn't open. Note that a lot of documentation says that
getlogin() is based on the controlling terminal---what they
really mean is "the terminal connected to standard input". The
getlogin() implementation of DEC Unix, SunOS, Solaris, HP-UX all
return NULL if fd 0 has been closed, so this is the compatible
thing to do. Note that ttyname(open("/dev/tty")) on those
systems returns /dev/tty, so that is not a possible solution for
getlogin(). */
Based on this comment, I guess it would be sane to drop the check on
stdout and stderr, but it would have the consequence that you are not
able to pipe some data on stdin to the application that calls getlogin
as it would fail in that scenario.
I'm not a maintainer of newlib so I don't really have anything to say
about what path you decide to go.
next prev parent reply other threads:[~2023-07-13 16:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-12 17:33 Jordi Sanfeliu
2023-07-12 18:50 ` Torbjorn SVENSSON
2023-07-12 20:06 ` Brian Inglis
2023-07-13 16:26 ` Torbjorn SVENSSON
2023-07-13 8:06 ` Jordi Sanfeliu
2023-07-13 16:25 ` Torbjorn SVENSSON [this message]
2023-07-13 16:57 ` Jordi Sanfeliu
2023-07-13 19:01 ` Jeff Johnston
2023-07-17 7:54 ` Corinna Vinschen
2023-07-13 21:12 ` Stefan Tauner
2023-07-17 19:06 ` Jeff Johnston
2023-07-18 5:57 ` Jordi Sanfeliu
2023-07-18 7:08 ` Jordi Sanfeliu
2023-07-18 17:44 ` Jeff Johnston
2023-07-18 18:59 ` Jordi Sanfeliu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9ad091f5-4ca9-6410-e990-0cd4f1ece86e@foss.st.com \
--to=torbjorn.svensson@foss.st.com \
--cc=newlib@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).