From: Michael Tremer Date: Sun, 6 Oct 2024 18:07:35 +0000 (+0000) Subject: pty: Don't fail if standard input/output are not TTYs X-Git-Tag: 0.9.30~1124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=734e83bd66cdd2c6e09db3d5effc49c4dc50a5c3;p=pakfire.git pty: Don't fail if standard input/output are not TTYs Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pty.c b/src/libpakfire/pty.c index 9e986f76b..a9cff2138 100644 --- a/src/libpakfire/pty.c +++ b/src/libpakfire/pty.c @@ -131,14 +131,6 @@ static int pakfire_pty_restore_attrs(struct pakfire_pty* pty, if (stdio->fd < 0) return 0; - // Don't restore anything if we didn't save things before - if (!stdio->attrs_saved) - return 0; - - // Skip everything if fd is not a TTY - if (!isatty(stdio->fd)) - return 0; - // Fetch the flags flags = fcntl(stdio->fd, F_GETFL, 0); if (flags < 0) { @@ -156,11 +148,13 @@ static int pakfire_pty_restore_attrs(struct pakfire_pty* pty, } // Restore the attributes - r = tcsetattr(stdio->fd, TCSANOW, &stdio->attrs); - if (r) { - CTX_ERROR(pty->ctx, "Could not restore terminal attributes for %d, ignoring: %s\n", - stdio->fd, strerror(errno)); - return -errno; + if (stdio->attrs_saved) { + r = tcsetattr(stdio->fd, TCSANOW, &stdio->attrs); + if (r) { + CTX_ERROR(pty->ctx, "Could not restore terminal attributes for %d, ignoring: %s\n", + stdio->fd, strerror(errno)); + return -errno; + } } // Close the file descriptor @@ -179,9 +173,16 @@ static int pakfire_pty_store_attrs(struct pakfire_pty* pty, // Store all attributes r = tcgetattr(stdio->fd, &stdio->attrs); if (r) { - CTX_ERROR(pty->ctx, "Could not fetch terminal attributes from fd %d: %s\n", - stdio->fd, strerror(errno)); - return -errno; + switch (errno) { + case ENOTTY: + return 0; + + default: + CTX_ERROR(pty->ctx, "Could not fetch terminal attributes from fd %d: %s\n", + stdio->fd, strerror(errno)); + + return -errno; + } } // Mark the attributes as saved