fix(CgiHandler, CgiProcess): improve socket management by adding stderr socket handling

This commit is contained in:
whaffman 2025-10-21 19:03:40 +02:00
parent 7eba0b38a2
commit c148636b1e
2 changed files with 5 additions and 1 deletions

View File

@ -102,7 +102,7 @@ void CgiHandler::error()
else if (bytesRead == 0) else if (bytesRead == 0)
{ {
Log::info("CGI process closed stderr, fd: " + std::to_string(cgiStdErr_->getFd())); Log::info("CGI process closed stderr, fd: " + std::to_string(cgiStdErr_->getFd()));
request_.getClient().removeCgiSocket(cgiStdErr_.get()); request_.getClient().removeSocket(cgiStdErr_.get());
cgiStdErr_ = nullptr; cgiStdErr_ = nullptr;
return; return;
} }
@ -126,6 +126,7 @@ void CgiHandler::setCgiSockets(std::unique_ptr<CgiSocket> cgiStdIn, std::unique_
request_.getClient().addSocket(cgiStdIn_.get()); request_.getClient().addSocket(cgiStdIn_.get());
request_.getClient().addSocket(cgiStdOut_.get()); request_.getClient().addSocket(cgiStdOut_.get());
request_.getClient().addSocket(cgiStdErr_.get());
} }
void CgiHandler::wait() noexcept void CgiHandler::wait() noexcept

View File

@ -84,6 +84,8 @@ void CgiProcess::spawn()
// Parent process // Parent process
auto cgiStdIn = std::make_unique<CgiSocket>(pipeStdin[1], ASocket::IOState::WRITE); auto cgiStdIn = std::make_unique<CgiSocket>(pipeStdin[1], ASocket::IOState::WRITE);
auto cgiStdOut = std::make_unique<CgiSocket>(pipeStdout[0], ASocket::IOState::READ); auto cgiStdOut = std::make_unique<CgiSocket>(pipeStdout[0], ASocket::IOState::READ);
auto cgiStdErr = std::make_unique<CgiSocket>(pipeStderr[0], ASocket::IOState::READ);
close(pipeStdin[0]); close(pipeStdin[0]);
close(pipeStdout[1]); close(pipeStdout[1]);
close(pipeStderr[1]); close(pipeStderr[1]);
@ -93,6 +95,7 @@ void CgiProcess::spawn()
// request_.getClient().setCgiSockets(std::move(cgiStdIn), std::move(cgiStdOut)); // move the sockets to the // request_.getClient().setCgiSockets(std::move(cgiStdIn), std::move(cgiStdOut)); // move the sockets to the
// client // client
handler_.setCgiSockets(std::move(cgiStdIn), std::move(cgiStdOut), std::move(cgiStdErr)); handler_.setCgiSockets(std::move(cgiStdIn), std::move(cgiStdOut), std::move(cgiStdErr));
handler_.setPid(_pid); handler_.setPid(_pid);
} }
} }