From 1b24357c4176047cc9b450888bb54b52df83afdd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 20 Aug 2024 10:30:19 +0200 Subject: [PATCH] terminal-util: fix isatty_safe() on hung-up TTYs glibc returs EIO on ttys that are hung up. That's not really correct, POSIX seems to disagree. Work around this in our code, and turn this into a clean "1", since a hung up tty doesn't stop being a tty just because it is hung up. Background: https://github.com/systemd/systemd/pull/34039 --- src/basic/terminal-util.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 6088320186..4219ac5ee9 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -65,6 +65,12 @@ bool isatty_safe(int fd) { if (isatty(fd)) return true; + /* Linux/glibc returns EIO for hung up TTY on isatty(). Which is wrong, the thing doesn't stop being + * a TTY after all, just because it is temporarily hung up. Let's work around this here, until this + * is fixed in glibc. See: https://sourceware.org/bugzilla/show_bug.cgi?id=32103 */ + if (errno == EIO) + return true; + /* Be resilient if we're working on stdio, since they're set up by parent process. */ assert(errno != EBADF || IN_SET(fd, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO));