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),
};
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 {
// 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
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;
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));
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));
}
// 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)
}
// 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));
}
// 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
}
// 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;
}
}
// 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);
// 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);
// 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);