mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 23:09:08 +00:00
parent
0dac7af6c5
commit
c589625418
Notes:
sideshowbarker
2024-07-19 03:36:12 +09:00
Author: https://github.com/alimpfard
Commit: c589625418
Pull-request: https://github.com/SerenityOS/serenity/pull/3144
Issue: https://github.com/SerenityOS/serenity/issues/3072
Reviewed-by: https://github.com/awesomekling
6 changed files with 81 additions and 13 deletions
|
@ -56,6 +56,38 @@ void FileDescriptionCollector::add(int fd)
|
|||
m_fds.append(fd);
|
||||
}
|
||||
|
||||
SavedFileDescriptors::SavedFileDescriptors(const NonnullRefPtrVector<AST::Rewiring>& intended_rewirings)
|
||||
{
|
||||
for (auto& rewiring : intended_rewirings) {
|
||||
int new_fd = dup(rewiring.source_fd);
|
||||
if (new_fd < 0) {
|
||||
if (errno != EBADF)
|
||||
perror("dup");
|
||||
// The fd that will be overwritten isn't open right now,
|
||||
// it will be cleaned up by the exec()-side collector
|
||||
// and we have nothing to do here, so just ignore this error.
|
||||
continue;
|
||||
}
|
||||
|
||||
auto flags = fcntl(new_fd, F_GETFL);
|
||||
auto rc = fcntl(new_fd, F_SETFL, flags | FD_CLOEXEC);
|
||||
ASSERT(rc == 0);
|
||||
|
||||
m_saves.append({ rewiring.source_fd, new_fd });
|
||||
m_collector.add(new_fd);
|
||||
}
|
||||
}
|
||||
|
||||
SavedFileDescriptors::~SavedFileDescriptors()
|
||||
{
|
||||
for (auto& save : m_saves) {
|
||||
if (dup2(save.saved, save.original) < 0) {
|
||||
perror("dup2(~SavedFileDescriptors)");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Core::EventLoop loop;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue