mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
LibCore/Process: Add DupFd
file action
This commit provides a new file action allowing callers to provide a `write_fd` that Process will "redirect" the child's stdin/stdout to.
This commit is contained in:
parent
cddbe7d10f
commit
aa4dcca0b2
Notes:
github-actions[bot]
2024-12-06 00:09:34 +00:00
Author: https://github.com/rmg-x Commit: https://github.com/LadybirdBrowser/ladybird/commit/aa4dcca0b21 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2553 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/shannonbooth
2 changed files with 9 additions and 3 deletions
|
@ -121,6 +121,10 @@ ErrorOr<Process> Process::spawn(ProcessSpawnOptions const& options)
|
|||
[&](FileAction::CloseFile const& action) -> ErrorOr<void> {
|
||||
CHECK(posix_spawn_file_actions_addclose(&spawn_actions, action.fd));
|
||||
return {};
|
||||
},
|
||||
[&](FileAction::DupFd const& action) -> ErrorOr<void> {
|
||||
CHECK(posix_spawn_file_actions_adddup2(&spawn_actions, action.write_fd, action.fd));
|
||||
return {};
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include <AK/ByteString.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Span.h>
|
||||
#include <LibCore/File.h>
|
||||
|
||||
namespace Core {
|
||||
|
@ -29,7 +28,10 @@ struct CloseFile {
|
|||
int fd { -1 };
|
||||
};
|
||||
|
||||
// FIXME: Implement other file actions
|
||||
struct DupFd {
|
||||
int write_fd { -1 };
|
||||
int fd { -1 };
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -40,7 +42,7 @@ struct ProcessSpawnOptions {
|
|||
Vector<ByteString> const& arguments {};
|
||||
Optional<ByteString> working_directory {};
|
||||
|
||||
using FileActionType = Variant<FileAction::OpenFile, FileAction::CloseFile>;
|
||||
using FileActionType = Variant<FileAction::OpenFile, FileAction::CloseFile, FileAction::DupFd>;
|
||||
Vector<FileActionType> file_actions {};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue