From: Michael Tremer Date: Sat, 16 Dec 2023 13:05:08 +0000 (+0000) Subject: jail: Store flags of stdin/stdout X-Git-Tag: 0.9.30~1283 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a12a3659983e5687915c6685a2c3cd7c2cc18857;p=pakfire.git jail: Store flags of stdin/stdout We will need to restore them after we are finish the PTY forwarding. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index bdf3f320d..ec3363de6 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -199,6 +199,7 @@ struct pakfire_jail_exec { int fd; char buffer[LINE_MAX]; struct termios attrs; + int fdflags; enum pakfire_jail_pty_flags flags; } stdin; @@ -869,6 +870,14 @@ static int pakfire_jail_enable_raw_mode(struct pakfire_jail* jail, struct termios raw_attrs; int r; + // Store flags + stdio->fdflags = fcntl(stdio->fd, F_GETFL); + if (stdio->fdflags < 0) { + CTX_ERROR(jail->ctx, "Could not fetch flags from fd %d: %s\n", + stdio->fd, strerror(errno)); + return -errno; + } + // Fetch all attributes r = tcgetattr(stdio->fd, &stdio->attrs); if (r) { @@ -894,16 +903,27 @@ static int pakfire_jail_enable_raw_mode(struct pakfire_jail* jail, return 0; } -static void pakfire_jail_restore_attrs(struct pakfire_jail* jail, +static int pakfire_jail_restore_attrs(struct pakfire_jail* jail, const struct pakfire_jail_pty_stdio* stdio) { int r; + // Restore the flags + r = fcntl(stdio->fd, F_SETFL, stdio->fdflags); + if (r < 0) { + CTX_ERROR(jail->ctx, "Could not set flags for file descriptor %d: %s\n", + stdio->fd, strerror(errno)); + return -errno; + } + // Restore the attributes r = tcsetattr(stdio->fd, TCSANOW, &stdio->attrs); if (r) { - CTX_DEBUG(jail->ctx, "Could not restore terminal attributes for %d, ignoring: %s\n", + CTX_ERROR(jail->ctx, "Could not restore terminal attributes for %d, ignoring: %s\n", stdio->fd, strerror(errno)); + return -errno; } + + return 0; } static int pakfire_jail_setup_pty_forwarding(struct pakfire_jail* jail,