diff --git a/README.md b/README.md index fffc349..fe15e29 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,6 @@ By default the application is compiled to utilize `/var/www/html` as the WEB roo - All new connections will spawn a child process which is used to deal with the request - If the process takes longer than 5 seconds to resolve the request, the child process will be killed -- php-cgi seems to randomly return empty data from scripts without throwing an error message (these are caught and a HTTP 500 response is return) - - If the request is made again it will eventually return correct data (this seems to be an issue with php-cgi and not this application) - Running `make genCerts` will generate a root authority and generate certificates to utilize for the web server - Certificate authority related files start with `ca` while the certificates which should be utilized for the web server omit the `ca` - Making a request to the web server which does not match the current protocol (e.g. making a https request when it is server http) will result in the server ignoring the request diff --git a/src/utils.c b/src/utils.c index dd3fad7..8705862 100644 --- a/src/utils.c +++ b/src/utils.c @@ -54,6 +54,7 @@ char *php_cgi(char *sPath, struct HTTPRequest *r) { size_t bufLen = 1024; buf = malloc(bufLen); + memset(buf, 0, bufLen); pipe(phpPipe); pid_t pid; @@ -100,7 +101,7 @@ char *php_cgi(char *sPath, struct HTTPRequest *r) { } else { // Parent fork close(phpPipe[1]); dup2(phpPipe2[0], STDIN_FILENO); - execlp("/usr/bin/php-cgi", "php-cgi", NULL); + execl("/usr/bin/php-cgi", "php-cgi", NULL); } } else { queryString = malloc(strlen(r->requestVars) + 24); @@ -109,11 +110,15 @@ char *php_cgi(char *sPath, struct HTTPRequest *r) { putenv("REQUEST_METHOD=GET"); execl("/usr/bin/php-cgi", "php-cgi", NULL); } + exit(EXIT_SUCCESS); } else if (pid < 0) { // Error forking printDebug("Error forking php exec"); } else { // Parent fork size_t buffCount; close(phpPipe[1]); + do { + waitpid(pid, &status, WUNTRACED); + } while (!WIFEXITED(status) && !WIFSIGNALED(status)); do { buffCount = read(phpPipe[0], buf, BUFF_READ); if (strlen(buf) == bufLen) { @@ -121,9 +126,6 @@ char *php_cgi(char *sPath, struct HTTPRequest *r) { buf = realloc(buf, bufLen); } } while (buffCount == 0); - do { - waitpid(pid, &status, WUNTRACED); - } while (!WIFEXITED(status) && !WIFSIGNALED(status)); } close(phpPipe[0]);