From: Michael Tremer Date: Tue, 19 Dec 2023 17:30:03 +0000 (+0000) Subject: jail: Rename PTY forwarding flags X-Git-Tag: 0.9.30~1263 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ce285a188864b9f71acae1e070f1a394f34251d;p=pakfire.git jail: Rename PTY forwarding flags The term flags is slightly overused and makes things confusing. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index 2cb4fd562..b29ff13e7 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -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);