From: Michael Tremer Date: Wed, 3 Aug 2022 08:47:17 +0000 (+0000) Subject: jail: Move completed_fd into ctx X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f7d240a7079ec6cc76fb0b7734f514855ea64185;p=people%2Fstevee%2Fpakfire.git jail: Move completed_fd into ctx Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index 0de80e19..208e2ffc 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -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;