]> git.ipfire.org Git - pakfire.git/commitdiff
jail: Do not try to attempt any TTY operations if we don't have a TTY
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 Dec 2023 12:45:46 +0000 (12:45 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 Dec 2023 12:45:46 +0000 (12:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index 29b0198a8a09c0bfc8846b1a2699d3f03c13709d..a14899584616273716a731ad117de03a0f47ddd1 100644 (file)
@@ -926,6 +926,10 @@ static int pakfire_jail_enable_raw_mode(struct pakfire_jail* jail,
        struct termios raw_attrs;
        int r;
 
+       // Skip everything if fd is not a TTY
+       if (!isatty(stdio->fd))
+               return 0;
+
        // Store flags
        stdio->fdflags = fcntl(stdio->fd, F_GETFL);
        if (stdio->fdflags < 0) {
@@ -974,6 +978,10 @@ static int pakfire_jail_restore_attrs(struct pakfire_jail* jail,
                const struct pakfire_jail_pty_stdio* stdio) {
        int r;
 
+       // Skip everything if fd is not a TTY
+       if (!isatty(stdio->fd))
+               return 0;
+
        // Restore the flags
        r = fcntl(stdio->fd, F_SETFL, stdio->fdflags);
        if (r < 0) {
@@ -1008,17 +1016,19 @@ static int pakfire_jail_setup_pty_forwarding(struct pakfire_jail* jail,
        ctx->pty.stdout.fd = STDOUT_FILENO;
 
        // Fetch dimensions
-       r = ioctl(ctx->pty.stdout.fd, TIOCGWINSZ, &size);
-       if (r) {
-               CTX_ERROR(jail->ctx, "Failed to determine terminal dimensions: %s\n", strerror(errno));
-               return -errno;
-       }
+       if (isatty(ctx->pty.stdout.fd)) {
+               r = ioctl(ctx->pty.stdout.fd, TIOCGWINSZ, &size);
+               if (r) {
+                       CTX_ERROR(jail->ctx, "Failed to determine terminal dimensions: %s\n", strerror(errno));
+                       return -errno;
+               }
 
-       // Set dimensions
-       r = ioctl(ctx->pty.master.fd, TIOCSWINSZ, &size);
-       if (r) {
-               CTX_ERROR(jail->ctx, "Failed setting dimensions: %s\n", strerror(errno));
-               return -errno;
+               // Set dimensions
+               r = ioctl(ctx->pty.master.fd, TIOCSWINSZ, &size);
+               if (r) {
+                       CTX_ERROR(jail->ctx, "Failed setting dimensions: %s\n", strerror(errno));
+                       return -errno;
+               }
        }
 
        // Enable RAW mode on standard input