diff --git a/Userland/Libraries/LibCore/Process.cpp b/Userland/Libraries/LibCore/Process.cpp index 915af3c213d..2c845683800 100644 --- a/Userland/Libraries/LibCore/Process.cpp +++ b/Userland/Libraries/LibCore/Process.cpp @@ -90,6 +90,10 @@ ErrorOr Process::spawn(ProcessSpawnOptions const& options) File::open_mode_to_options(action.mode | Core::File::OpenMode::KeepOnExec), action.permissions)); return {}; + }, + [&](FileAction::CloseFile const& action) -> ErrorOr { + CHECK(posix_spawn_file_actions_addclose(&spawn_actions, action.fd)); + return {}; })); } diff --git a/Userland/Libraries/LibCore/Process.h b/Userland/Libraries/LibCore/Process.h index ba7bef16d68..deca16ac403 100644 --- a/Userland/Libraries/LibCore/Process.h +++ b/Userland/Libraries/LibCore/Process.h @@ -24,6 +24,10 @@ struct OpenFile { mode_t permissions = 0600; }; +struct CloseFile { + int fd { -1 }; +}; + // FIXME: Implement other file actions } @@ -31,9 +35,9 @@ struct OpenFile { struct ProcessSpawnOptions { ByteString executable; bool search_for_executable_in_path { false }; - Vector const& arguments = {}; - Optional working_directory = {}; - Vector> const& file_actions = {}; + Vector const& arguments {}; + Optional working_directory {}; + Vector> const& file_actions {}; }; class Process {