From: Michael Tremer Date: Sat, 2 Dec 2023 12:41:02 +0000 (+0000) Subject: jail: Commit some disabled code to set up a PTY X-Git-Tag: 0.9.30~1293 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=374e62685744291e45484b02333928da3236a8b0;p=pakfire.git jail: Commit some disabled code to set up a PTY Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index d67686cd7..472fcb2ac 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -175,6 +175,10 @@ struct pakfire_jail_exec { struct pakfire_cgroup* cgroup; struct pakfire_cgroup_stats cgroup_stats; + + // Console + char console[PATH_MAX]; + int consolefd; }; static int clone3(struct clone_args* args, size_t size) { @@ -1721,6 +1725,31 @@ static int pakfire_jail_switch_root(struct pakfire_jail* jail, const char* root) return 0; } +#if 0 +static int pakfire_jail_open_pty(struct pakfire_jail* jail, struct pakfire_jail_exec* ctx) { + int r; + + // Allocate a new PTY + ctx->consolefd = posix_openpt(O_RDWR|O_NONBLOCK|O_NOCTTY|O_CLOEXEC); + if (ctx->consolefd < 0) + return -errno; + + // Fetch the path + r = ptsname_r(ctx->consolefd, ctx->console, sizeof(ctx->console)); + if (r) + return -r; + + CTX_DEBUG(jail->ctx, "Allocated console at %s (%d)\n", ctx->console, ctx->consolefd); + + // Create a symlink + r = pakfire_symlink(jail->ctx, "/dev/console", ctx->console); + if (r) + return r; + + return r; +} +#endif + /* Called by the parent that sets up the second child process... */ @@ -1824,6 +1853,22 @@ static int pakfire_jail_child2(struct pakfire_jail* jail, if (r) return 126; +#if 0 + // Create a new session + r = setsid(); + if (r < 0) { + CTX_ERROR(jail->ctx, "Could not create a new session: %s\n", strerror(errno)); + return 126; + } + + // Allocate a new PTY + r = pakfire_jail_open_pty(jail, ctx); + if (r) { + CTX_ERROR(jail->ctx, "Could not allocate a new PTY: %s\n", strerror(-r)); + return 126; + } +#endif + const char* arch = pakfire_get_effective_arch(jail->pakfire); // Set personality @@ -1995,6 +2040,10 @@ static int pakfire_jail_child1(struct pakfire_jail* jail, if (r) goto ERROR; + // XXX setup keyring + + + // chroot() r = pakfire_jail_switch_root(jail, root); if (r)