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;
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
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);
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;
}