From: Lennart Poettering Date: Tue, 20 Aug 2024 08:30:19 +0000 (+0200) Subject: terminal-util: fix isatty_safe() on hung-up TTYs X-Git-Tag: v257-rc1~674^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b24357c4176047cc9b450888bb54b52df83afdd;p=thirdparty%2Fsystemd.git 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 --- diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 60883201869..4219ac5ee9f 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));