From bb5ec5c9b484770e0b0f470da723bdce442a090b Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Fri, 2 Jun 2023 10:56:48 -0400 Subject: cmUVProcessChain: Do some internal refactoring Move most of cmUVProcessChain::InternalData::Finish() to Prepare() so that error codes can be checked before attepting to spawn any processes. Check some error codes that weren't being checked before. Change return type of Finish() to void as it can't fail. --- Source/cmUVProcessChain.cxx | 46 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/Source/cmUVProcessChain.cxx b/Source/cmUVProcessChain.cxx index ed5f38b..436ada2 100644 --- a/Source/cmUVProcessChain.cxx +++ b/Source/cmUVProcessChain.cxx @@ -66,6 +66,7 @@ struct cmUVProcessChain::InternalData StreamData OutputStreamData; StreamData ErrorStreamData; + cm::uv_pipe_ptr TempErrorPipe; unsigned int ProcessesCompleted = 0; std::vector> Processes; @@ -73,7 +74,7 @@ struct cmUVProcessChain::InternalData bool Prepare(const cmUVProcessChainBuilder* builder); bool AddCommand(const cmUVProcessChainBuilder::ProcessConfiguration& config, bool first, bool last); - bool Finish(); + void Finish(); static const Status* GetStatus(const ProcessData& data); }; @@ -207,12 +208,23 @@ bool cmUVProcessChain::InternalData::Prepare( return false; } - errorData.BuiltinStream.init(*this->Loop, 0); + if (errorData.BuiltinStream.init(*this->Loop, 0) < 0) { + return false; + } if (uv_pipe_open(errorData.BuiltinStream, pipeFd[0]) < 0) { return false; } errorData.Stdio.flags = UV_INHERIT_FD; errorData.Stdio.data.fd = pipeFd[1]; + + if (this->TempErrorPipe.init(*this->Loop, 0) < 0) { + return false; + } + if (uv_pipe_open(this->TempErrorPipe, errorData.Stdio.data.fd) < 0) { + return false; + } + + errorData.Streambuf.open(errorData.BuiltinStream); break; } @@ -235,10 +247,13 @@ bool cmUVProcessChain::InternalData::Prepare( outputData.Stdio.flags = UV_INHERIT_FD; outputData.Stdio.data.fd = errorData.Stdio.data.fd; } else { - outputData.BuiltinStream.init(*this->Loop, 0); + if (outputData.BuiltinStream.init(*this->Loop, 0) < 0) { + return false; + } outputData.Stdio.flags = static_cast(UV_CREATE_PIPE | UV_WRITABLE_PIPE); outputData.Stdio.data.stream = outputData.BuiltinStream; + outputData.Streambuf.open(outputData.BuiltinStream); } break; @@ -313,31 +328,10 @@ bool cmUVProcessChain::InternalData::AddCommand( return process.Process.spawn(*this->Loop, options, &process) >= 0; } -bool cmUVProcessChain::InternalData::Finish() +void cmUVProcessChain::InternalData::Finish() { - if (this->Builder->Stdio[cmUVProcessChainBuilder::Stream_OUTPUT].Type == - cmUVProcessChainBuilder::Builtin && - !this->Builder->MergedBuiltinStreams) { - this->OutputStreamData.Streambuf.open( - this->OutputStreamData.BuiltinStream); - } - - if (this->Builder->Stdio[cmUVProcessChainBuilder::Stream_ERROR].Type == - cmUVProcessChainBuilder::Builtin) { - cm::uv_pipe_ptr tmpPipe; - if (tmpPipe.init(*this->Loop, 0) < 0) { - return false; - } - if (uv_pipe_open(tmpPipe, this->ErrorStreamData.Stdio.data.fd) < 0) { - return false; - } - tmpPipe.reset(); - - this->ErrorStreamData.Streambuf.open(this->ErrorStreamData.BuiltinStream); - } - + this->TempErrorPipe.reset(); this->Valid = true; - return true; } cmUVProcessChain::cmUVProcessChain() -- cgit v0.12