LibCore: Add a Core::Process action to close a file after spawning

This commit is contained in:
Timothy Flynn 2024-04-23 15:31:07 -04:00 committed by Andrew Kaster
parent fecd08ce64
commit dc52404aec
Notes: sideshowbarker 2024-07-17 09:39:38 +09:00
2 changed files with 11 additions and 3 deletions

View file

@ -90,6 +90,10 @@ ErrorOr<Process> Process::spawn(ProcessSpawnOptions const& options)
File::open_mode_to_options(action.mode | Core::File::OpenMode::KeepOnExec),
action.permissions));
return {};
},
[&](FileAction::CloseFile const& action) -> ErrorOr<void> {
CHECK(posix_spawn_file_actions_addclose(&spawn_actions, action.fd));
return {};
}));
}

View file

@ -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<ByteString> const& arguments = {};
Optional<ByteString> working_directory = {};
Vector<Variant<FileAction::OpenFile>> const& file_actions = {};
Vector<ByteString> const& arguments {};
Optional<ByteString> working_directory {};
Vector<Variant<FileAction::OpenFile, FileAction::CloseFile>> const& file_actions {};
};
class Process {