in cgi exec add save stdin and out

This commit is contained in:
hugogogo
2022-08-10 16:24:24 +02:00
parent 86f7740984
commit 17230ccc42

View File

@@ -89,6 +89,8 @@ std::string Webserv::_exec_script(Client *client, char **env)
std::string body = client->get_rq_body(); std::string body = client->get_rq_body();
int fd_in[2]; int fd_in[2];
int fd_out[2]; int fd_out[2];
int save_in = dup(STDIN_FILENO);
int save_out = dup(STDOUT_FILENO);
pipe(fd_in); pipe(fd_in);
pipe(fd_out); pipe(fd_out);
@@ -104,9 +106,9 @@ std::string Webserv::_exec_script(Client *client, char **env)
dup2(FD_WR_TO_PRNT, STDOUT_FILENO); dup2(FD_WR_TO_PRNT, STDOUT_FILENO);
// DEBUG // DEBUG
std::cerr << "execve:\n"; std::cerr << "execve:\n";
execve(client->get_rq_script_path().c_str(), nll, env); //execve(client->get_rq_script_path().c_str(), nll, env);
// for tests execve crash : // for tests execve crash :
//execve("wrong", nll, env); execve("wrong", nll, env);
std::cerr << "execve crashed.\n"; std::cerr << "execve crashed.\n";
} }
else else
@@ -127,6 +129,9 @@ std::string Webserv::_exec_script(Client *client, char **env)
} }
if (script_output.empty()) if (script_output.empty())
script_output = "Status: 500\r\n\r\n"; script_output = "Status: 500\r\n\r\n";
dup2(save_in, STDIN_FILENO);
dup2(save_out, STDOUT_FILENO);
return script_output; return script_output;
} }