]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: fix isatty_safe() on hung-up TTYs
authorLennart Poettering <lennart@poettering.net>
Tue, 20 Aug 2024 08:30:19 +0000 (10:30 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 20 Aug 2024 08:57:49 +0000 (10:57 +0200)
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

index 60883201869a5b288d0b9dbf76b1b65e2c2515b2..4219ac5ee9fa2c9ffaeb39df546fb661388bca0a 100644 (file)
@@ -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));