]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
jail: Merge the basic environment with the custom environment
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Dec 2024 15:15:37 +0000 (15:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Dec 2024 15:15:37 +0000 (15:15 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index 9f551bd62f8897bd3fd0f8d4bc3f834d39126f71..409cae44ab3c833a581febd61282abd1d8513a1f 100644 (file)
@@ -977,6 +977,7 @@ struct pakfire_jail_command {
 
 static int pakfire_jail_launch_command(struct pakfire_jail* jail, void* data) {
        struct pakfire_jail_command* command = data;
+       struct pakfire_env* env = NULL;
        char** envp = NULL;
        int r;
 
@@ -984,6 +985,23 @@ static int pakfire_jail_launch_command(struct pakfire_jail* jail, void* data) {
        if (!command->argv || !command->argv[0])
                return -EINVAL;
 
+       // Create a new environment
+       r = pakfire_env_create(&env, jail->ctx);
+       if (r < 0)
+               goto ERROR;
+
+       // Merge the basic environment
+       r = pakfire_env_merge(env, jail->env);
+       if (r < 0)
+               goto ERROR;
+
+       // Merge the custom environment
+       if (command->env) {
+               r = pakfire_env_merge(env, command->env);
+               if (r < 0)
+                       goto ERROR;
+       }
+
        DEBUG(jail->ctx, "Launching command:\n");
 
        // Log argv
@@ -991,11 +1009,7 @@ static int pakfire_jail_launch_command(struct pakfire_jail* jail, void* data) {
                DEBUG(jail->ctx, "  argv[%u] = %s\n", i, command->argv[i]);
 
        // Fetch the environment
-       if (command->env) {
-               envp = pakfire_env_get_envp(command->env);
-               if (!envp)
-                       return -ENOTSUP;
-       }
+       envp = pakfire_env_get_envp(env);
 
        // exec() command
        r = execvpe(command->argv[0], (char**)command->argv, envp);
@@ -1020,6 +1034,10 @@ static int pakfire_jail_launch_command(struct pakfire_jail* jail, void* data) {
                ERROR(jail->ctx, "Could not execve(%s): %m\n", command->argv[0]);
        }
 
+ERROR:
+       if (env)
+               pakfire_env_unref(env);
+
        // We should not get here
        return r;
 }