diff options
| author | Xinchen Hui <laruence@gmail.com> | 2015-05-23 10:31:50 +0800 |
|---|---|---|
| committer | Xinchen Hui <laruence@gmail.com> | 2015-05-23 19:01:41 +0800 |
| commit | 18cf4e0a8a574034f60f4d123407c173e57e54ec (patch) | |
| tree | 08392346acfd0bc45d1a4449bcee0ebd44f101a3 /sapi/cgi/cgi_main.c | |
| parent | fef18f4bea1980a59a9283c2197bd090aaf500cb (diff) | |
| download | php-git-18cf4e0a8a574034f60f4d123407c173e57e54ec.tar.gz | |
Fixed fpm-side (tests passes)
Diffstat (limited to 'sapi/cgi/cgi_main.c')
| -rw-r--r-- | sapi/cgi/cgi_main.c | 184 |
1 files changed, 89 insertions, 95 deletions
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index a60b7c22a9..b89829f016 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -1034,12 +1034,12 @@ static int is_valid_path(const char *path) /* }}} */ #define CGI_GETENV(name) \ - ((request) ? \ + ((request->has_env) ? \ FCGI_GETENV(request, name) : \ getenv(name)) #define CGI_PUTENV(name, value) \ - ((request) ? \ + ((request->has_env) ? \ FCGI_PUTENV(request, name, value) : \ _sapi_cgi_putenv(name, sizeof(name)-1, value)) @@ -1732,7 +1732,7 @@ int main(int argc, char *argv[]) int fastcgi; char *bindpath = NULL; int fcgi_fd = 0; - fcgi_request *request = NULL; + fcgi_request request = {0}; int warmup_repeats = 0; int repeats = 1; int benchmark = 0; @@ -1967,109 +1967,109 @@ consult the installation file that came with this distribution, or visit \n\ php_import_environment_variables = cgi_php_import_environment_variables; /* library is already initialized, now init our request */ - request = fcgi_init_request(fcgi_fd); + fcgi_init_request(&request, fcgi_fd); #ifndef PHP_WIN32 - /* Pre-fork, if required */ - if (getenv("PHP_FCGI_CHILDREN")) { - char * children_str = getenv("PHP_FCGI_CHILDREN"); - children = atoi(children_str); - if (children < 0) { - fprintf(stderr, "PHP_FCGI_CHILDREN is not valid\n"); - return FAILURE; + /* Pre-fork, if required */ + if (getenv("PHP_FCGI_CHILDREN")) { + char * children_str = getenv("PHP_FCGI_CHILDREN"); + children = atoi(children_str); + if (children < 0) { + fprintf(stderr, "PHP_FCGI_CHILDREN is not valid\n"); + return FAILURE; + } + fcgi_set_mgmt_var("FCGI_MAX_CONNS", sizeof("FCGI_MAX_CONNS")-1, children_str, strlen(children_str)); + /* This is the number of concurrent requests, equals FCGI_MAX_CONNS */ + fcgi_set_mgmt_var("FCGI_MAX_REQS", sizeof("FCGI_MAX_REQS")-1, children_str, strlen(children_str)); + } else { + fcgi_set_mgmt_var("FCGI_MAX_CONNS", sizeof("FCGI_MAX_CONNS")-1, "1", sizeof("1")-1); + fcgi_set_mgmt_var("FCGI_MAX_REQS", sizeof("FCGI_MAX_REQS")-1, "1", sizeof("1")-1); } - fcgi_set_mgmt_var("FCGI_MAX_CONNS", sizeof("FCGI_MAX_CONNS")-1, children_str, strlen(children_str)); - /* This is the number of concurrent requests, equals FCGI_MAX_CONNS */ - fcgi_set_mgmt_var("FCGI_MAX_REQS", sizeof("FCGI_MAX_REQS")-1, children_str, strlen(children_str)); - } else { - fcgi_set_mgmt_var("FCGI_MAX_CONNS", sizeof("FCGI_MAX_CONNS")-1, "1", sizeof("1")-1); - fcgi_set_mgmt_var("FCGI_MAX_REQS", sizeof("FCGI_MAX_REQS")-1, "1", sizeof("1")-1); - } - if (children) { - int running = 0; - pid_t pid; + if (children) { + int running = 0; + pid_t pid; - /* Create a process group for ourself & children */ - setsid(); - pgroup = getpgrp(); + /* Create a process group for ourself & children */ + setsid(); + pgroup = getpgrp(); #ifdef DEBUG_FASTCGI - fprintf(stderr, "Process group %d\n", pgroup); + fprintf(stderr, "Process group %d\n", pgroup); #endif - /* Set up handler to kill children upon exit */ - act.sa_flags = 0; - act.sa_handler = fastcgi_cleanup; - if (sigaction(SIGTERM, &act, &old_term) || - sigaction(SIGINT, &act, &old_int) || - sigaction(SIGQUIT, &act, &old_quit) - ) { - perror("Can't set signals"); - exit(1); - } + /* Set up handler to kill children upon exit */ + act.sa_flags = 0; + act.sa_handler = fastcgi_cleanup; + if (sigaction(SIGTERM, &act, &old_term) || + sigaction(SIGINT, &act, &old_int) || + sigaction(SIGQUIT, &act, &old_quit) + ) { + perror("Can't set signals"); + exit(1); + } - if (fcgi_in_shutdown()) { - goto parent_out; - } + if (fcgi_in_shutdown()) { + goto parent_out; + } - while (parent) { - do { + while (parent) { + do { #ifdef DEBUG_FASTCGI - fprintf(stderr, "Forking, %d running\n", running); -#endif - pid = fork(); - switch (pid) { - case 0: - /* One of the children. - * Make sure we don't go round the - * fork loop any more - */ - parent = 0; + fprintf(stderr, "Forking, %d running\n", running); +#endif + pid = fork(); + switch (pid) { + case 0: + /* One of the children. + * Make sure we don't go round the + * fork loop any more + */ + parent = 0; - /* don't catch our signals */ - sigaction(SIGTERM, &old_term, 0); - sigaction(SIGQUIT, &old_quit, 0); - sigaction(SIGINT, &old_int, 0); - break; - case -1: - perror("php (pre-forking)"); - exit(1); - break; - default: - /* Fine */ - running++; - break; - } - } while (parent && (running < children)); + /* don't catch our signals */ + sigaction(SIGTERM, &old_term, 0); + sigaction(SIGQUIT, &old_quit, 0); + sigaction(SIGINT, &old_int, 0); + break; + case -1: + perror("php (pre-forking)"); + exit(1); + break; + default: + /* Fine */ + running++; + break; + } + } while (parent && (running < children)); - if (parent) { + if (parent) { #ifdef DEBUG_FASTCGI - fprintf(stderr, "Wait for kids, pid %d\n", getpid()); + fprintf(stderr, "Wait for kids, pid %d\n", getpid()); #endif - parent_waiting = 1; - while (1) { - if (wait(&status) >= 0) { - running--; - break; - } else if (exit_signal) { - break; + parent_waiting = 1; + while (1) { + if (wait(&status) >= 0) { + running--; + break; + } else if (exit_signal) { + break; + } } - } - if (exit_signal) { + if (exit_signal) { #if 0 - while (running > 0) { - while (wait(&status) < 0) { + while (running > 0) { + while (wait(&status) < 0) { + } + running--; } - running--; - } #endif - goto parent_out; + goto parent_out; + } } } + } else { + parent = 0; } - } else { - parent = 0; - } #endif /* WIN32 */ } @@ -2096,9 +2096,6 @@ consult the installation file that came with this distribution, or visit \n\ break; case 'h': case '?': - if (request) { - fcgi_destroy_request(request); - } fcgi_shutdown(); no_headers = 1; SG(headers_sent) = 1; @@ -2120,9 +2117,9 @@ consult the installation file that came with this distribution, or visit \n\ fcgi_impersonate(); } #endif - while (!fastcgi || fcgi_accept_request(request) >= 0) { - SG(server_context) = fastcgi ? (void *) request : (void *) 1; - init_request_info(request); + while (!fastcgi || fcgi_accept_request(&request) >= 0) { + SG(server_context) = fastcgi ? (void *)&request : (void *) 1; + init_request_info(&request); if (!cgi && !fastcgi) { while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { @@ -2307,7 +2304,7 @@ consult the installation file that came with this distribution, or visit \n\ * get path_translated */ if (php_request_startup() == FAILURE) { if (fastcgi) { - fcgi_finish_request(request, 1); + fcgi_finish_request(&request, 1); } SG(server_context) = NULL; php_module_shutdown(); @@ -2518,7 +2515,7 @@ fastcgi_request_done: /* only fastcgi will get here */ requests++; if (max_requests && (requests == max_requests)) { - fcgi_finish_request(request, 1); + fcgi_finish_request(&request, 1); if (bindpath) { free(bindpath); } @@ -2530,9 +2527,6 @@ fastcgi_request_done: } /* end of fastcgi loop */ } - if (request) { - fcgi_destroy_request(request); - } fcgi_shutdown(); if (cgi_sapi_module.php_ini_path_override) { |
