]> git.ipfire.org Git - pakfire.git/commitdiff
jail: Move completed_fd into ctx
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Aug 2022 08:47:17 +0000 (08:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Aug 2022 08:47:17 +0000 (08:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index 0de80e197ff02dabf37ca0f032c0f57ec6d40c99..208e2ffc1feaff3b26f329af9c59afaaa9feb8cc 100644 (file)
@@ -85,6 +85,9 @@ struct pakfire_jail_exec {
        // Process status (from waitpid)
        int status;
 
+       // FD to notify the client that the parent has finished initialization
+       int completed_fd;
+
        // Log pipes
        union {
                int stdout[2];
@@ -822,8 +825,7 @@ static int pakfire_jail_wait_for_signal(struct pakfire_jail* jail, int fd) {
 /*
        Performs the initialisation that needs to happen in the parent part
 */
-static int pakfire_jail_parent(struct pakfire_jail* jail, struct pakfire_jail_exec* ctx,
-               int completed_fd) {
+static int pakfire_jail_parent(struct pakfire_jail* jail, struct pakfire_jail_exec* ctx) {
        int r;
 
        // Setup UID mapping
@@ -845,7 +847,7 @@ static int pakfire_jail_parent(struct pakfire_jail* jail, struct pakfire_jail_ex
        DEBUG(jail->pakfire, "Parent has finished initialization\n");
 
        // Send signal to client
-       r = pakfire_jail_send_signal(jail, completed_fd);
+       r = pakfire_jail_send_signal(jail, ctx->completed_fd);
        if (r)
                return r;
 
@@ -853,7 +855,7 @@ static int pakfire_jail_parent(struct pakfire_jail* jail, struct pakfire_jail_ex
 }
 
 static int pakfire_jail_child(struct pakfire_jail* jail, struct pakfire_jail_exec* ctx,
-               const char* argv[], int completed_fd) {
+               const char* argv[]) {
        int r;
 
        // XXX do we have to reconfigure logging here?
@@ -861,7 +863,7 @@ static int pakfire_jail_child(struct pakfire_jail* jail, struct pakfire_jail_exe
        DEBUG(jail->pakfire, "Launched child process in jail with PID %d\n", getpid());
 
        // Wait for the parent to finish initialization
-       r = pakfire_jail_wait_for_signal(jail, completed_fd);
+       r = pakfire_jail_wait_for_signal(jail, ctx->completed_fd);
        if (r)
                return r;
 
@@ -982,8 +984,8 @@ int pakfire_jail_exec(struct pakfire_jail* jail, const char* argv[]) {
                Setup a file descriptor which can be used to notify the client that the parent
                has completed configuration.
        */
-       int completed_fd = eventfd(0, EFD_CLOEXEC);
-       if (completed_fd < 0) {
+       ctx.completed_fd = eventfd(0, EFD_CLOEXEC);
+       if (ctx.completed_fd < 0) {
                ERROR(jail->pakfire, "eventfd() failed: %m\n");
                return -1;
        }
@@ -1025,12 +1027,12 @@ int pakfire_jail_exec(struct pakfire_jail* jail, const char* argv[]) {
 
        // Child process
        } else if (ctx.pid == 0) {
-               r = pakfire_jail_child(jail, &ctx, argv, completed_fd);
+               r = pakfire_jail_child(jail, &ctx, argv);
                _exit(r);
        }
 
        // Parent process
-       r = pakfire_jail_parent(jail, &ctx, completed_fd);
+       r = pakfire_jail_parent(jail, &ctx);
        if (r)
                goto ERROR;