libos: Allow passing environment to Process::exec
This commit is contained in:
parent
5d56638851
commit
e654ed6415
@ -11,5 +11,6 @@ namespace os
|
||||
static Result<pid_t> fork();
|
||||
|
||||
static Result<void> exec(StringView path, Slice<String> args, bool search_in_path = true);
|
||||
static Result<void> exec(StringView path, Slice<String> args, Slice<String> env, bool search_in_path = true);
|
||||
};
|
||||
}
|
||||
|
@ -24,4 +24,21 @@ namespace os
|
||||
|
||||
return err(errno);
|
||||
}
|
||||
|
||||
Result<void> Process::exec(StringView path, Slice<String> args, Slice<String> env, bool search_in_path)
|
||||
{
|
||||
Vector<const char*> argv;
|
||||
for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); }
|
||||
TRY(argv.try_append(nullptr));
|
||||
|
||||
Vector<const char*> envp;
|
||||
for (const auto& arg : env) { TRY(envp.try_append(arg.chars())); }
|
||||
TRY(envp.try_append(nullptr));
|
||||
|
||||
if (search_in_path) execvpe(path.chars(), const_cast<char**>(argv.data()), const_cast<char**>(envp.data()));
|
||||
else
|
||||
execve(path.chars(), const_cast<char**>(argv.data()), const_cast<char**>(envp.data()));
|
||||
|
||||
return err(errno);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user