]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
jail: Store flags of stdin/stdout
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 16 Dec 2023 13:05:08 +0000 (13:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 16 Dec 2023 13:05:08 +0000 (13:05 +0000)
We will need to restore them after we are finish the PTY forwarding.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index bdf3f320d545b57b264a183a497dcf698108ec72..ec3363de6303d2ec8b35243df644d8e187826864 100644 (file)
@@ -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,