]> git.ipfire.org Git - pakfire.git/commitdiff
jail: Add struct to pass more stuff to commands
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Dec 2024 13:02:27 +0000 (13:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Dec 2024 13:02:27 +0000 (13:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index 073436fc016fd3dad7580eb63dcae0ace8988711..ff620e2e22eea31cbbd319061ebdf273e9fa88ec 100644 (file)
@@ -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);
 }