Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed incorrect wrap for process's stdio container #317

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
31 changes: 6 additions & 25 deletions src/uvw/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,8 @@ UVW_INLINE int process_handle::spawn(const char *file, char **args, char **env)
po.uid = po_uid;
po.gid = po_gid;

std::vector<uv_stdio_container_t> poStdio;
poStdio.reserve(po_fd_stdio.size() + po_stream_stdio.size());
poStdio.insert(poStdio.begin(), po_fd_stdio.cbegin(), po_fd_stdio.cend());
poStdio.insert(poStdio.end(), po_stream_stdio.cbegin(), po_stream_stdio.cend());

po.stdio_count = static_cast<decltype(po.stdio_count)>(poStdio.size());
po.stdio = poStdio.data();
po.stdio_count = static_cast<decltype(po.stdio_count)>(po_stdio.size());
po.stdio = po_stdio.data();

// see init member function for more details
leak_if(0);
Expand All @@ -77,24 +72,10 @@ UVW_INLINE process_handle &process_handle::flags(process_flags flags) noexcept {
}

UVW_INLINE process_handle &process_handle::stdio(file_handle fd, stdio_flags flags) {
auto fgs = static_cast<uv_stdio_flags>(flags);

auto actual = uvw::file_handle{fd};

auto it = std::find_if(po_fd_stdio.begin(), po_fd_stdio.end(), [actual](auto &&container) {
return static_cast<const uvw::details::uv_type_wrapper<int>>(container.data.fd) == static_cast<const uvw::details::uv_type_wrapper<int>>(actual);
});

if(it == po_fd_stdio.cend()) {
uv_stdio_container_t container;
container.flags = fgs;
container.data.fd = actual;
po_fd_stdio.push_back(std::move(container));
} else {
it->flags = fgs;
it->data.fd = actual;
}

uv_stdio_container_t container;
container.flags = static_cast<uv_stdio_flags>(flags);
container.data.fd = fd;
po_stdio.push_back(std::move(container));
return *this;
}

Expand Down
5 changes: 2 additions & 3 deletions src/uvw/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class process_handle final: public handle<process_handle, uv_process_t, exit_eve
uv_stdio_container_t container;
container.flags = static_cast<uv_stdio_flags>(flags);
container.data.stream = reinterpret_cast<uv_stream_t *>(stream.raw());
po_stream_stdio.push_back(std::move(container));
po_stdio.push_back(std::move(container));
return *this;
}

Expand Down Expand Up @@ -230,8 +230,7 @@ class process_handle final: public handle<process_handle, uv_process_t, exit_eve
private:
std::string po_cwd;
process_flags po_flags;
std::vector<uv_stdio_container_t> po_fd_stdio;
std::vector<uv_stdio_container_t> po_stream_stdio;
std::vector<uv_stdio_container_t> po_stdio;
uid_type po_uid;
gid_type po_gid;
};
Expand Down
Loading