]> git.ipfire.org Git - pakfire.git/commitdiff
jail: Commit some disabled code to set up a PTY
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 2 Dec 2023 12:41:02 +0000 (12:41 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 2 Dec 2023 12:41:02 +0000 (12:41 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index d67686cd7f718fe4b539e9b5da387b3ed30136c8..472fcb2ac33f31e98cdb38ded3b51258cf98bbc4 100644 (file)
@@ -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)