]> git.ipfire.org Git - people/ms/pakfire.git/blobdiff - src/libpakfire/jail.c
jail: Commit some disabled code to set up a PTY
[people/ms/pakfire.git] / src / libpakfire / jail.c
index e47fe7e8845beba8e473c4d9f6fdbd59d468253b..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) {
@@ -1451,7 +1455,17 @@ static int pakfire_jail_mount(struct pakfire_jail* jail, struct pakfire_jail_exe
                flags |= PAKFIRE_MOUNT_LOOP_DEVICES;
 
        // Mount all default stuff
-       r = pakfire_mount_all(jail->pakfire, flags);
+       r = pakfire_mount_all(jail->pakfire, PAKFIRE_MNTNS_OUTER, flags);
+       if (r)
+               return r;
+
+       // Populate /dev
+       r = pakfire_populate_dev(jail->pakfire, flags);
+       if (r)
+               return r;
+
+       // Mount the interpreter (if needed)
+       r = pakfire_mount_interpreter(jail->pakfire);
        if (r)
                return r;
 
@@ -1473,9 +1487,6 @@ static int pakfire_jail_mount(struct pakfire_jail* jail, struct pakfire_jail_exe
                        return r;
        }
 
-       // Log all mountpoints
-       pakfire_mount_list(jail->pakfire);
-
        return 0;
 }
 
@@ -1714,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...
 */
@@ -1797,6 +1833,9 @@ static int pakfire_jail_child2(struct pakfire_jail* jail,
        DEBUG(jail->pakfire, "  UID: %u (effective %u)\n", uid, euid);
        DEBUG(jail->pakfire, "  GID: %u (effective %u)\n", gid, egid);
 
+       // Log all mountpoints
+       pakfire_mount_list(jail->ctx);
+
        // Fail if we are not PID 1
        if (pid != 1) {
                CTX_ERROR(jail->ctx, "Child process is not PID 1\n");
@@ -1809,6 +1848,27 @@ static int pakfire_jail_child2(struct pakfire_jail* jail,
                return 126;
        }
 
+       // Mount all default stuff
+       r = pakfire_mount_all(jail->pakfire, PAKFIRE_MNTNS_INNER, 0);
+       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
@@ -1980,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)