#include <sys/timerfd.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <termios.h>
// libnl3
#include <net/if.h>
struct pakfire_cgroup* cgroup;
struct pakfire_cgroup_stats cgroup_stats;
- // Console
- char console[PATH_MAX];
- int consolefd;
+ // PTY
+ struct pakfire_jail_pty {
+ // The path to the console
+ char console[PATH_MAX];
+
+ // The master fd
+ struct pakfire_jail_pty_master {
+ int fd;
+
+ enum pakfire_jail_pty_flags {
+ PAKFIRE_JAIL_PTY_READY_TO_READ = (1 << 0),
+ PAKFIRE_JAIL_PTY_READY_TO_WRITE = (1 << 1),
+ } flags;
+ } master;
+
+ // Standard Input
+ struct pakfire_jail_pty_stdio {
+ int fd;
+ char buffer[LINE_MAX];
+ struct termios attrs;
+ enum pakfire_jail_pty_flags flags;
+ } stdin;
+
+ // Standard Output
+ struct pakfire_jail_pty_stdio stdout;
+ } pty;
};
static int clone3(struct clone_args* args, size_t size) {
goto ERROR;
// Setup PTY forwarding
- if (ctx->consolefd < 0) {
+ if (ctx->pty.master.fd < 0) {
r = pakfire_jail_setup_pty_forwarding(jail, ctx, epollfd, fd);
if (r) {
CTX_ERROR(jail->ctx, "Failed setting up PTY forwarding: %s\n", strerror(-r));
int r;
// Allocate a new PTY
- ctx->consolefd = posix_openpt(O_RDWR|O_NONBLOCK|O_NOCTTY|O_CLOEXEC);
- if (ctx->consolefd < 0)
+ ctx->pty.master.fd = posix_openpt(O_RDWR|O_NONBLOCK|O_NOCTTY|O_CLOEXEC);
+ if (ctx->pty.master.fd < 0)
return -errno;
// Fetch the path
- r = ptsname_r(ctx->consolefd, ctx->console, sizeof(ctx->console));
+ r = ptsname_r(ctx->pty.master.fd, ctx->pty.console, sizeof(ctx->pty.console));
if (r)
return -r;
- CTX_DEBUG(jail->ctx, "Allocated console at %s (%d)\n", ctx->console, ctx->consolefd);
+ CTX_DEBUG(jail->ctx, "Allocated console at %s (%d)\n", ctx->pty.console, ctx->pty.master.fd);
#if 0
// Create a symlink
- r = pakfire_symlink(jail->ctx, "/dev/console", ctx->console);
+ r = pakfire_symlink(jail->ctx, "/dev/console", ctx->pty.console);
if (r)
return r;
#endif
}
// Send the PTY master to the parent process
- r = pakfire_jail_send_fd(jail, socket_send, ctx->consolefd);
+ r = pakfire_jail_send_fd(jail, socket_send, ctx->pty.master.fd);
if (r) {
CTX_ERROR(jail->ctx, "Failed sending the PTY master to the parent: %s\n", strerror(-r));
return r;
}
// Close the master of the PTY
- close(ctx->consolefd);
- ctx->consolefd = -1;
+ close(ctx->pty.master.fd);
+ ctx->pty.master.fd = -1;
// Close the socket
close(socket_send);
.pidfd = -1,
- .consolefd = -1,
+ // PTY
+ .pty = {
+ .master = {
+ .fd = -1,
+ },
+ .stdin = {
+ .fd = -1,
+ },
+ .stdout = {
+ .fd = -1,
+ },
+ },
};
DEBUG(jail->pakfire, "Executing jail...\n");
pakfire_jail_close_pipe(jail, ctx.pipes.stderr);
if (ctx.pidfd >= 0)
close(ctx.pidfd);
- if (ctx.consolefd >= 0)
- close(ctx.consolefd);
+ if (ctx.pty.master.fd >= 0)
+ close(ctx.pty.master.fd);
pakfire_jail_close_pipe(jail, ctx.pipes.log_INFO);
pakfire_jail_close_pipe(jail, ctx.pipes.log_ERROR);
#ifdef ENABLE_DEBUG