]> git.ipfire.org Git - pakfire.git/commitdiff
pty: Don't fail if standard input/output are not TTYs
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Oct 2024 18:07:35 +0000 (18:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Oct 2024 18:07:35 +0000 (18:07 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pty.c

index 9e986f76bc0c73c60c086b6fdcd3f9bef6d88d89..a9cff21383825b8d956b68b9fbdc981362a45575 100644 (file)
@@ -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