From: Michael Tremer Date: Tue, 19 Dec 2023 12:45:46 +0000 (+0000) Subject: jail: Do not try to attempt any TTY operations if we don't have a TTY X-Git-Tag: 0.9.30~1275 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6d1853b57fc3628af830a1b209c0bcd15319501;p=pakfire.git jail: Do not try to attempt any TTY operations if we don't have a TTY Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index 29b0198a8..a14899584 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -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