#include #include #include #include namespace os { Result Process::fork() { long rc = syscall(SYS_fork); return Result::from_syscall(rc); } Result Process::exec(StringView path, Slice args, bool search_in_path) { Vector argv; for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); } TRY(argv.try_append(nullptr)); if (search_in_path) execvp(path.chars(), const_cast(argv.data())); else execv(path.chars(), const_cast(argv.data())); return err(errno); } Result Process::exec(StringView path, Slice args, bool search_in_path) { Vector argv; for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); } TRY(argv.try_append(nullptr)); if (search_in_path) execvp(path.chars(), const_cast(argv.data())); else execv(path.chars(), const_cast(argv.data())); return err(errno); } Result Process::exec(StringView path, Slice args, Slice env, bool search_in_path) { Vector argv; for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); } TRY(argv.try_append(nullptr)); Vector 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(argv.data()), const_cast(envp.data())); else execve(path.chars(), const_cast(argv.data()), const_cast(envp.data())); return err(errno); } }