]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
jail: Rename PTY forwarding flags
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 Dec 2023 17:30:03 +0000 (17:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 Dec 2023 17:30:03 +0000 (17:30 +0000)
The term flags is slightly overused and makes things confusing.

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

index 2cb4fd562ed50afaf7d91ddb2f2ebbf6c6f3f83b..b29ff13e759d120708835b08a50db9d8ccb5ce5a 100644 (file)
@@ -87,7 +87,7 @@ struct pakfire_log_buffer {
        size_t used;
 };
 
-enum pakfire_jail_pty_flags {
+enum pakfire_jail_pty_io {
        PAKFIRE_JAIL_PTY_READY_TO_READ  = (1 << 0),
        PAKFIRE_JAIL_PTY_READY_TO_WRITE = (1 << 1),
 };
@@ -103,10 +103,10 @@ struct pakfire_jail_pty_stdio {
        struct termios attrs;
 
        // File Descriptor Flags
-       int fdflags;
+       int flags;
 
        // IO Flags
-       enum pakfire_jail_pty_flags flags;
+       enum pakfire_jail_pty_io io;
 };
 
 struct pakfire_jail_mountpoint {
@@ -195,7 +195,7 @@ struct pakfire_jail_exec {
                // The master device
                struct pakfire_jail_pty_master {
                        int fd;
-                       enum pakfire_jail_pty_flags flags;
+                       enum pakfire_jail_pty_io io;
                } master;
 
                // Standard Input/Output
@@ -916,8 +916,8 @@ static int pakfire_jail_enable_raw_mode(struct pakfire_jail* jail,
                return 0;
 
        // Store flags
-       stdio->fdflags = fcntl(stdio->fd, F_GETFL);
-       if (stdio->fdflags < 0) {
+       stdio->flags = fcntl(stdio->fd, F_GETFL);
+       if (stdio->flags < 0) {
                CTX_ERROR(jail->ctx, "Could not fetch flags from fd %d: %s\n",
                        stdio->fd, strerror(errno));
                return -errno;
@@ -972,7 +972,7 @@ static int pakfire_jail_restore_attrs(struct pakfire_jail* jail,
                return 0;
 
        // Restore the flags
-       r = fcntl(stdio->fd, F_SETFL, stdio->fdflags);
+       r = fcntl(stdio->fd, F_SETFL, stdio->flags);
        if (r < 0) {
                CTX_ERROR(jail->ctx, "Could not set flags for file descriptor %d: %s\n",
                        stdio->fd, strerror(errno));
@@ -1053,9 +1053,9 @@ static int pakfire_jail_setup_pty_forwarding(struct pakfire_jail* jail,
 static int pakfire_jail_forward_pty(struct pakfire_jail* jail, struct pakfire_jail_exec* ctx) {
        int r;
 
-       while (ctx->pty.master.flags || ctx->pty.stdin.flags || ctx->pty.stdout.flags) {
+       while (ctx->pty.master.io || ctx->pty.stdin.io || ctx->pty.stdout.io) {
                // Read from standard input
-               if (ctx->pty.stdin.flags & PAKFIRE_JAIL_PTY_READY_TO_READ) {
+               if (ctx->pty.stdin.io & PAKFIRE_JAIL_PTY_READY_TO_READ) {
                        r = pakfire_jail_fill_buffer(jail, ctx->pty.stdin.fd, &ctx->pty.stdin.buffer);
                        if (r) {
                                CTX_ERROR(jail->ctx, "Failed reading from standard input: %s\n", strerror(-r));
@@ -1063,15 +1063,15 @@ static int pakfire_jail_forward_pty(struct pakfire_jail* jail, struct pakfire_ja
                        }
 
                        // We are done reading for now
-                       ctx->pty.stdin.flags &= ~PAKFIRE_JAIL_PTY_READY_TO_READ;
+                       ctx->pty.stdin.io &= ~PAKFIRE_JAIL_PTY_READY_TO_READ;
 
                        // But we may have data to write
                        if (ctx->pty.stdin.buffer.used)
-                               ctx->pty.master.flags |= PAKFIRE_JAIL_PTY_READY_TO_WRITE;
+                               ctx->pty.master.io |= PAKFIRE_JAIL_PTY_READY_TO_WRITE;
                }
 
                // Write to the master
-               if (ctx->pty.master.flags & PAKFIRE_JAIL_PTY_READY_TO_WRITE) {
+               if (ctx->pty.master.io & PAKFIRE_JAIL_PTY_READY_TO_WRITE) {
                        if (ctx->communicate.in) {
                                r = pakfire_jail_stream_stdin(jail, ctx, ctx->pty.master.fd);
                                if (r)
@@ -1086,11 +1086,11 @@ static int pakfire_jail_forward_pty(struct pakfire_jail* jail, struct pakfire_ja
                        }
 
                        // We are done writing for now
-                       ctx->pty.master.flags &= ~PAKFIRE_JAIL_PTY_READY_TO_WRITE;
+                       ctx->pty.master.io &= ~PAKFIRE_JAIL_PTY_READY_TO_WRITE;
                }
 
                // Read from the master
-               if (ctx->pty.master.flags & PAKFIRE_JAIL_PTY_READY_TO_READ) {
+               if (ctx->pty.master.io & PAKFIRE_JAIL_PTY_READY_TO_READ) {
                        r = pakfire_jail_fill_buffer(jail, ctx->pty.master.fd, &ctx->pty.stdout.buffer);
                        if (r) {
                                CTX_ERROR(jail->ctx, "Failed reading from the PTY: %s\n", strerror(-r));
@@ -1098,11 +1098,11 @@ static int pakfire_jail_forward_pty(struct pakfire_jail* jail, struct pakfire_ja
                        }
 
                        // We are done reading for now
-                       ctx->pty.master.flags &= ~PAKFIRE_JAIL_PTY_READY_TO_READ;
+                       ctx->pty.master.io &= ~PAKFIRE_JAIL_PTY_READY_TO_READ;
 
                        // But we may have data to write
                        if (ctx->pty.stdout.buffer.used)
-                               ctx->pty.stdout.flags |= PAKFIRE_JAIL_PTY_READY_TO_WRITE;
+                               ctx->pty.stdout.io |= PAKFIRE_JAIL_PTY_READY_TO_WRITE;
                }
 
                // Write to standard output
@@ -1131,7 +1131,7 @@ static int pakfire_jail_forward_pty(struct pakfire_jail* jail, struct pakfire_ja
                        }
 
                        // We are done writing for now
-                       ctx->pty.stdout.flags &= ~PAKFIRE_JAIL_PTY_READY_TO_WRITE;
+                       ctx->pty.stdout.io &= ~PAKFIRE_JAIL_PTY_READY_TO_WRITE;
                }
        }
 
@@ -1228,10 +1228,10 @@ static int pakfire_jail_wait(struct pakfire_jail* jail, struct pakfire_jail_exec
                        // Handle PTY forwarding events
                        if (ctx->pty.master.fd == fd) {
                                if (e & (EPOLLIN|EPOLLHUP))
-                                       ctx->pty.master.flags |= PAKFIRE_JAIL_PTY_READY_TO_READ;
+                                       ctx->pty.master.io |= PAKFIRE_JAIL_PTY_READY_TO_READ;
 
                                if (e & (EPOLLOUT|EPOLLHUP))
-                                       ctx->pty.master.flags |= PAKFIRE_JAIL_PTY_READY_TO_WRITE;
+                                       ctx->pty.master.io |= PAKFIRE_JAIL_PTY_READY_TO_WRITE;
 
                                // Perform the work
                                r = pakfire_jail_forward_pty(jail, ctx);
@@ -1243,7 +1243,7 @@ static int pakfire_jail_wait(struct pakfire_jail* jail, struct pakfire_jail_exec
                        // Handle standard input
                        } else if (ctx->pty.stdin.fd == fd) {
                                if (e & (EPOLLIN|EPOLLHUP))
-                                       ctx->pty.stdin.flags |= PAKFIRE_JAIL_PTY_READY_TO_READ;
+                                       ctx->pty.stdin.io |= PAKFIRE_JAIL_PTY_READY_TO_READ;
 
                                // Perform the work
                                r = pakfire_jail_forward_pty(jail, ctx);
@@ -1255,7 +1255,7 @@ static int pakfire_jail_wait(struct pakfire_jail* jail, struct pakfire_jail_exec
                        // Handle standard output
                        } else if (ctx->pty.stdout.fd == fd) {
                                if (e & (EPOLLOUT|EPOLLHUP))
-                                       ctx->pty.stdout.flags |= PAKFIRE_JAIL_PTY_READY_TO_WRITE;
+                                       ctx->pty.stdout.io |= PAKFIRE_JAIL_PTY_READY_TO_WRITE;
 
                                // Perform the work
                                r = pakfire_jail_forward_pty(jail, ctx);