in cgi exec add save stdin and out
This commit is contained in:
@@ -89,6 +89,8 @@ std::string Webserv::_exec_script(Client *client, char **env)
|
||||
std::string body = client->get_rq_body();
|
||||
int fd_in[2];
|
||||
int fd_out[2];
|
||||
int save_in = dup(STDIN_FILENO);
|
||||
int save_out = dup(STDOUT_FILENO);
|
||||
|
||||
pipe(fd_in);
|
||||
pipe(fd_out);
|
||||
@@ -104,9 +106,9 @@ std::string Webserv::_exec_script(Client *client, char **env)
|
||||
dup2(FD_WR_TO_PRNT, STDOUT_FILENO);
|
||||
// DEBUG
|
||||
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 :
|
||||
//execve("wrong", nll, env);
|
||||
execve("wrong", nll, env);
|
||||
std::cerr << "execve crashed.\n";
|
||||
}
|
||||
else
|
||||
@@ -127,6 +129,9 @@ std::string Webserv::_exec_script(Client *client, char **env)
|
||||
}
|
||||
if (script_output.empty())
|
||||
script_output = "Status: 500\r\n\r\n";
|
||||
|
||||
dup2(save_in, STDIN_FILENO);
|
||||
dup2(save_out, STDOUT_FILENO);
|
||||
return script_output;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user