Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions include/boost/process/v2/stdio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,18 @@ struct process_io_binding
bool fd_needs_closing{false};
error_code ec;

~process_io_binding()
void close()
{
if (fd_needs_closing)
{
::close(fd);
fd = target;
fd_needs_closing = false;
}
}
~process_io_binding()
{
close();
}

process_io_binding() = default;
Expand All @@ -193,8 +201,7 @@ struct process_io_binding

process_io_binding & operator=(process_io_binding && other) noexcept
{
if (fd_needs_closing)
::close(fd);
close();

fd = other.fd;
fd_needs_closing = other.fd_needs_closing;
Expand Down Expand Up @@ -358,6 +365,22 @@ struct process_stdio

return error_code {};
};

// weather fork succeeded or not, we should close the pipe properly in the parent
void close_pipes()
{
in.close();
out.close();
err.close();
};
void on_success(posix::default_launcher & /*launcher*/, const filesystem::path &, const char * const *)
{
close_pipes();
};
void on_error(posix::default_launcher & /*launcher*/, const filesystem::path &, const char * const *)
{
close_pipes();
};
#endif

};
Expand Down
Loading