fixed race condition
This commit is contained in:
@@ -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
|
- 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
|
- 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
|
- 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`
|
- 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
|
- 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
|
||||||
|
|||||||
10
src/utils.c
10
src/utils.c
@@ -54,6 +54,7 @@ char *php_cgi(char *sPath, struct HTTPRequest *r) {
|
|||||||
size_t bufLen = 1024;
|
size_t bufLen = 1024;
|
||||||
|
|
||||||
buf = malloc(bufLen);
|
buf = malloc(bufLen);
|
||||||
|
memset(buf, 0, bufLen);
|
||||||
pipe(phpPipe);
|
pipe(phpPipe);
|
||||||
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@@ -100,7 +101,7 @@ char *php_cgi(char *sPath, struct HTTPRequest *r) {
|
|||||||
} else { // Parent fork
|
} else { // Parent fork
|
||||||
close(phpPipe[1]);
|
close(phpPipe[1]);
|
||||||
dup2(phpPipe2[0], STDIN_FILENO);
|
dup2(phpPipe2[0], STDIN_FILENO);
|
||||||
execlp("/usr/bin/php-cgi", "php-cgi", NULL);
|
execl("/usr/bin/php-cgi", "php-cgi", NULL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
queryString = malloc(strlen(r->requestVars) + 24);
|
queryString = malloc(strlen(r->requestVars) + 24);
|
||||||
@@ -109,11 +110,15 @@ char *php_cgi(char *sPath, struct HTTPRequest *r) {
|
|||||||
putenv("REQUEST_METHOD=GET");
|
putenv("REQUEST_METHOD=GET");
|
||||||
execl("/usr/bin/php-cgi", "php-cgi", NULL);
|
execl("/usr/bin/php-cgi", "php-cgi", NULL);
|
||||||
}
|
}
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
} else if (pid < 0) { // Error forking
|
} else if (pid < 0) { // Error forking
|
||||||
printDebug("Error forking php exec");
|
printDebug("Error forking php exec");
|
||||||
} else { // Parent fork
|
} else { // Parent fork
|
||||||
size_t buffCount;
|
size_t buffCount;
|
||||||
close(phpPipe[1]);
|
close(phpPipe[1]);
|
||||||
|
do {
|
||||||
|
waitpid(pid, &status, WUNTRACED);
|
||||||
|
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
|
||||||
do {
|
do {
|
||||||
buffCount = read(phpPipe[0], buf, BUFF_READ);
|
buffCount = read(phpPipe[0], buf, BUFF_READ);
|
||||||
if (strlen(buf) == bufLen) {
|
if (strlen(buf) == bufLen) {
|
||||||
@@ -121,9 +126,6 @@ char *php_cgi(char *sPath, struct HTTPRequest *r) {
|
|||||||
buf = realloc(buf, bufLen);
|
buf = realloc(buf, bufLen);
|
||||||
}
|
}
|
||||||
} while (buffCount == 0);
|
} while (buffCount == 0);
|
||||||
do {
|
|
||||||
waitpid(pid, &status, WUNTRACED);
|
|
||||||
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close(phpPipe[0]);
|
close(phpPipe[0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user