littles adjustements but still no solution to the main problem

This commit is contained in:
lperrey
2022-08-18 10:48:57 +02:00
parent dda0103fb8
commit 9b0fcc1520
8 changed files with 88 additions and 33 deletions

View File

@@ -9,7 +9,7 @@ bool Webserv::_is_cgi(Client *client, std::string path)
{
std::string script_path;
size_t file_type;
size_t file_mode = client->status;
size_t file_access = client->status;
size_t pos = 0;
while (pos != NPOS)
@@ -24,13 +24,13 @@ bool Webserv::_is_cgi(Client *client, std::string path)
continue;
if (file_type == IS_FILE)
{
file_mode = ::eval_file_access( script_path, X_OK );
if (!file_mode)
file_access = ::eval_file_access( script_path, X_OK );
if (!file_access)
return true;
}
}
client->clear_script();
client->status = file_mode; // 404 not_found OR 403 forbidden
client->status = file_access; // 404 not_found OR 403 forbidden
return false;
}
@@ -99,6 +99,22 @@ void Webserv::_cgi_open_pipes(Client *client)
client->cgi_state = CGI_WAIT_TO_EXEC;
}
void Webserv::_write_body_to_cgi(Client *client)
{
std::cerr << "_write_body_to_cgi()"; // DEBUG
ssize_t ret;
std::string body = client->get_rq_body();
ret = ::write(client->cgi_pipe_w_to_child, body.c_str(), body.size());
if (ret == -1)
{
std::perror("err write()");
_close_client_cgi_pipes(client);
client->status = 500;
client->cgi_state = CGI_NO_CGI;
}
}
void Webserv::_exec_cgi(Client *client)
{
char* env_cstr[19] = {NULL};
@@ -187,9 +203,11 @@ void Webserv::_exec_script(Client *client, char *env[])
{
pid_t pid;
char * const nll[1] = {NULL};
std::string script_output;
std::string path;
std::cerr << "_exec_script() client " << client->get_cl_fd() << "\n";
// pid = 1; // DEBUG, if no fork, no problem
pid = fork();
if (pid == -1)
{
@@ -216,8 +234,6 @@ void Webserv::_exec_script(Client *client, char *env[])
}
_close_all_clients_fd();
if (::close(_epfd) == -1)
std::perror("err close");
path = client->get_rq_script_path();
std::cerr << "execve:[" << path << "]\n"; // DEBUG