int fd;
char buffer[LINE_MAX];
struct termios attrs;
+ int fdflags;
enum pakfire_jail_pty_flags flags;
} stdin;
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) {
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,