From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Gil Pedersen <gpdev@gpost.dk>
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
Jiri Slaby <jirislaby@kernel.org>
Subject: Re: [PATCH 1/1] tty: respond to TIOCGWINSZ when hung
Date: Mon, 23 Dec 2024 18:56:59 +0100 [thread overview]
Message-ID: <2024122329-jockey-delouse-71a7@gregkh> (raw)
In-Reply-To: <20241121111506.4717-2-gpdev@gpost.dk>
On Thu, Nov 21, 2024 at 12:12:54PM +0100, Gil Pedersen wrote:
> Userspace libc implementations of the isatty() POSIX system interface
> are currently unable to reliably determine if a fd is really a tty when
> it is hung.
>
> Specifically glibc libc returns the success status of a TCGETS ioctl.
> This will return an incorrect result when the TTY is hung, since an EIO
> is unconditionally returned. Ie. an isatty() will return 0, wrongly
> indicating that something that definitely is a TTY, is not a TTY.
>
> Userspace implementations could potentially remap EIO errors to a
> success to work around this. This will likely work in 99.99% of cases,
> but there is no guarantee that a TCGETS ioctl on a non-TTY fd will not
> also return EIO, making the isatty() call return a false positive!
>
> This commit enables a specific non-driver, non-ldisc, ioctl to continue
> working after the TTY is hung. The TIOCGWINSZ ioctl was chosen since it
> is readonly, and only access tty_struct.winsize (and its mutex), and is
> already used for the isatty() implementation in musl. The glibc
> implementation will need to be updated to use the TIOCGWINSZ ioctl,
> either as a direct replacement, or more conservatively, as a fallback
> test when the TCGETS ioctl fails with EIO.
This is a fun "hack", yes, but now you are encoding an odd "side affect"
into the system that everyone is going to rely on, well, eventually rely
on. What code needs to be changed in userspace to determine this?
Why not just have a new ioctl that tells you if the tty really is hung
or not? Why does isatty() need to know this, does POSIX require it?
And if it does, what does it say the ioctl command should be?
thanks,
greg k-h
next prev parent reply other threads:[~2024-12-23 17:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-21 11:12 [PATCH 0/1] Fix to allow more correct isatty() Gil Pedersen
2024-11-21 11:12 ` [PATCH 1/1] tty: respond to TIOCGWINSZ when hung Gil Pedersen
2024-12-23 17:56 ` Greg Kroah-Hartman [this message]
2025-01-07 11:44 ` Gil Pedersen
2025-01-10 14:52 ` Greg Kroah-Hartman
2024-11-22 23:54 ` [PATCH 0/1] Fix to allow more correct isatty() nerdopolis
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=2024122329-jockey-delouse-71a7@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=gpdev@gpost.dk \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.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