From: Michael Tremer Date: Sun, 29 Dec 2024 13:02:27 +0000 (+0000) Subject: jail: Add struct to pass more stuff to commands X-Git-Tag: 0.9.30~680 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8194f4b47416a3eda93f2ffc4da3edccfabafc1;p=pakfire.git jail: Add struct to pass more stuff to commands Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index 073436fc0..ff620e2e2 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -1067,22 +1067,27 @@ static int pakfire_jail_exited(sd_event_source* source, const siginfo_t* si, voi return sd_event_exit(sd_event_source_get_event(source), 0); } +struct pakfire_jail_command { + const char** argv; + const char** envp; +}; + static int pakfire_jail_launch_command(struct pakfire_jail* jail, void* data) { - char** argv = data; + struct pakfire_jail_command* command = data; int r; // Check if argv is valid - if (!argv || !argv[0]) + if (!command->argv || !command->argv[0]) return -EINVAL; DEBUG(jail->ctx, "Launching command:\n"); // Log argv - for (unsigned int i = 0; argv[i]; i++) - DEBUG(jail->ctx, " argv[%u] = %s\n", i, argv[i]); + for (unsigned int i = 0; command->argv[i]; i++) + DEBUG(jail->ctx, " argv[%u] = %s\n", i, command->argv[i]); // exec() command - r = execvpe(argv[0], argv, jail->env); + r = execvpe(command->argv[0], (char**)command->argv, (char**)command->envp); if (r < 0) { // Translate errno into regular exit code switch (errno) { @@ -1101,7 +1106,7 @@ static int pakfire_jail_launch_command(struct pakfire_jail* jail, void* data) { r = 1; } - ERROR(jail->ctx, "Could not execve(%s): %m\n", argv[0]); + ERROR(jail->ctx, "Could not execve(%s): %m\n", command->argv[0]); } // We should not get here @@ -1620,13 +1625,21 @@ ERROR: } int pakfire_jail_exec(struct pakfire_jail* jail, const char* argv[], int flags) { - return __pakfire_jail_exec(jail, pakfire_jail_launch_command, argv, flags, + struct pakfire_jail_command command = { + .argv = argv, + }; + + return __pakfire_jail_exec(jail, pakfire_jail_launch_command, &command, flags, NULL, NULL, NULL, NULL, NULL, NULL); } int pakfire_jail_exec_capture_output(struct pakfire_jail* jail, const char* argv[], int flags, char** output, size_t* length) { - return __pakfire_jail_exec(jail, pakfire_jail_launch_command, argv, flags, + struct pakfire_jail_command command = { + .argv = argv, + }; + + return __pakfire_jail_exec(jail, pakfire_jail_launch_command, &command, flags, NULL, NULL, NULL, NULL, output, length); } @@ -1634,7 +1647,11 @@ int pakfire_jail_communicate( struct pakfire_jail* jail, const char* argv[], int flags, pakfire_pty_stdin_callback stdin_callback, void* stdin_data, pakfire_pty_stdout_callback stdout_callback, void* stdout_data) { - return __pakfire_jail_exec(jail, pakfire_jail_launch_command, argv, flags, + struct pakfire_jail_command command = { + .argv = argv, + }; + + return __pakfire_jail_exec(jail, pakfire_jail_launch_command, &command, flags, stdin_callback, stdin_data, stdout_callback, stdout_data, NULL, NULL); }