@@ -1034,12 +1034,12 @@ static int is_valid_path(const char *path)
10341034/* }}} */
10351035
10361036#define CGI_GETENV (name ) \
1037- ((request) ? \
1037+ ((request->has_env ) ? \
10381038 FCGI_GETENV(request, name) : \
10391039 getenv(name))
10401040
10411041#define CGI_PUTENV (name , value ) \
1042- ((request) ? \
1042+ ((request->has_env ) ? \
10431043 FCGI_PUTENV(request, name, value) : \
10441044 _sapi_cgi_putenv(name, sizeof(name)-1, value))
10451045
@@ -1732,7 +1732,7 @@ int main(int argc, char *argv[])
17321732 int fastcgi ;
17331733 char * bindpath = NULL ;
17341734 int fcgi_fd = 0 ;
1735- fcgi_request * request = NULL ;
1735+ fcgi_request request = { 0 } ;
17361736 int warmup_repeats = 0 ;
17371737 int repeats = 1 ;
17381738 int benchmark = 0 ;
@@ -1967,109 +1967,109 @@ consult the installation file that came with this distribution, or visit \n\
19671967 php_import_environment_variables = cgi_php_import_environment_variables ;
19681968
19691969 /* library is already initialized, now init our request */
1970- request = fcgi_init_request (fcgi_fd );
1970+ fcgi_init_request (& request , fcgi_fd );
19711971
19721972#ifndef PHP_WIN32
1973- /* Pre-fork, if required */
1974- if (getenv ("PHP_FCGI_CHILDREN" )) {
1975- char * children_str = getenv ("PHP_FCGI_CHILDREN" );
1976- children = atoi (children_str );
1977- if (children < 0 ) {
1978- fprintf (stderr , "PHP_FCGI_CHILDREN is not valid\n" );
1979- return FAILURE ;
1973+ /* Pre-fork, if required */
1974+ if (getenv ("PHP_FCGI_CHILDREN" )) {
1975+ char * children_str = getenv ("PHP_FCGI_CHILDREN" );
1976+ children = atoi (children_str );
1977+ if (children < 0 ) {
1978+ fprintf (stderr , "PHP_FCGI_CHILDREN is not valid\n" );
1979+ return FAILURE ;
1980+ }
1981+ fcgi_set_mgmt_var ("FCGI_MAX_CONNS" , sizeof ("FCGI_MAX_CONNS" )- 1 , children_str , strlen (children_str ));
1982+ /* This is the number of concurrent requests, equals FCGI_MAX_CONNS */
1983+ fcgi_set_mgmt_var ("FCGI_MAX_REQS" , sizeof ("FCGI_MAX_REQS" )- 1 , children_str , strlen (children_str ));
1984+ } else {
1985+ fcgi_set_mgmt_var ("FCGI_MAX_CONNS" , sizeof ("FCGI_MAX_CONNS" )- 1 , "1" , sizeof ("1" )- 1 );
1986+ fcgi_set_mgmt_var ("FCGI_MAX_REQS" , sizeof ("FCGI_MAX_REQS" )- 1 , "1" , sizeof ("1" )- 1 );
19801987 }
1981- fcgi_set_mgmt_var ("FCGI_MAX_CONNS" , sizeof ("FCGI_MAX_CONNS" )- 1 , children_str , strlen (children_str ));
1982- /* This is the number of concurrent requests, equals FCGI_MAX_CONNS */
1983- fcgi_set_mgmt_var ("FCGI_MAX_REQS" , sizeof ("FCGI_MAX_REQS" )- 1 , children_str , strlen (children_str ));
1984- } else {
1985- fcgi_set_mgmt_var ("FCGI_MAX_CONNS" , sizeof ("FCGI_MAX_CONNS" )- 1 , "1" , sizeof ("1" )- 1 );
1986- fcgi_set_mgmt_var ("FCGI_MAX_REQS" , sizeof ("FCGI_MAX_REQS" )- 1 , "1" , sizeof ("1" )- 1 );
1987- }
19881988
1989- if (children ) {
1990- int running = 0 ;
1991- pid_t pid ;
1989+ if (children ) {
1990+ int running = 0 ;
1991+ pid_t pid ;
19921992
1993- /* Create a process group for ourself & children */
1994- setsid ();
1995- pgroup = getpgrp ();
1993+ /* Create a process group for ourself & children */
1994+ setsid ();
1995+ pgroup = getpgrp ();
19961996#ifdef DEBUG_FASTCGI
1997- fprintf (stderr , "Process group %d\n" , pgroup );
1997+ fprintf (stderr , "Process group %d\n" , pgroup );
19981998#endif
19991999
2000- /* Set up handler to kill children upon exit */
2001- act .sa_flags = 0 ;
2002- act .sa_handler = fastcgi_cleanup ;
2003- if (sigaction (SIGTERM , & act , & old_term ) ||
2004- sigaction (SIGINT , & act , & old_int ) ||
2005- sigaction (SIGQUIT , & act , & old_quit )
2006- ) {
2007- perror ("Can't set signals" );
2008- exit (1 );
2009- }
2000+ /* Set up handler to kill children upon exit */
2001+ act .sa_flags = 0 ;
2002+ act .sa_handler = fastcgi_cleanup ;
2003+ if (sigaction (SIGTERM , & act , & old_term ) ||
2004+ sigaction (SIGINT , & act , & old_int ) ||
2005+ sigaction (SIGQUIT , & act , & old_quit )
2006+ ) {
2007+ perror ("Can't set signals" );
2008+ exit (1 );
2009+ }
20102010
2011- if (fcgi_in_shutdown ()) {
2012- goto parent_out ;
2013- }
2011+ if (fcgi_in_shutdown ()) {
2012+ goto parent_out ;
2013+ }
20142014
2015- while (parent ) {
2016- do {
2015+ while (parent ) {
2016+ do {
20172017#ifdef DEBUG_FASTCGI
2018- fprintf (stderr , "Forking, %d running\n" , running );
2019- #endif
2020- pid = fork ();
2021- switch (pid ) {
2022- case 0 :
2023- /* One of the children.
2024- * Make sure we don't go round the
2025- * fork loop any more
2026- */
2027- parent = 0 ;
2018+ fprintf (stderr , "Forking, %d running\n" , running );
2019+ #endif
2020+ pid = fork ();
2021+ switch (pid ) {
2022+ case 0 :
2023+ /* One of the children.
2024+ * Make sure we don't go round the
2025+ * fork loop any more
2026+ */
2027+ parent = 0 ;
20282028
2029- /* don't catch our signals */
2030- sigaction (SIGTERM , & old_term , 0 );
2031- sigaction (SIGQUIT , & old_quit , 0 );
2032- sigaction (SIGINT , & old_int , 0 );
2033- break ;
2034- case -1 :
2035- perror ("php (pre-forking)" );
2036- exit (1 );
2037- break ;
2038- default :
2039- /* Fine */
2040- running ++ ;
2041- break ;
2042- }
2043- } while (parent && (running < children ));
2029+ /* don't catch our signals */
2030+ sigaction (SIGTERM , & old_term , 0 );
2031+ sigaction (SIGQUIT , & old_quit , 0 );
2032+ sigaction (SIGINT , & old_int , 0 );
2033+ break ;
2034+ case -1 :
2035+ perror ("php (pre-forking)" );
2036+ exit (1 );
2037+ break ;
2038+ default :
2039+ /* Fine */
2040+ running ++ ;
2041+ break ;
2042+ }
2043+ } while (parent && (running < children ));
20442044
2045- if (parent ) {
2045+ if (parent ) {
20462046#ifdef DEBUG_FASTCGI
2047- fprintf (stderr , "Wait for kids, pid %d\n" , getpid ());
2047+ fprintf (stderr , "Wait for kids, pid %d\n" , getpid ());
20482048#endif
2049- parent_waiting = 1 ;
2050- while (1 ) {
2051- if (wait (& status ) >= 0 ) {
2052- running -- ;
2053- break ;
2054- } else if (exit_signal ) {
2055- break ;
2049+ parent_waiting = 1 ;
2050+ while (1 ) {
2051+ if (wait (& status ) >= 0 ) {
2052+ running -- ;
2053+ break ;
2054+ } else if (exit_signal ) {
2055+ break ;
2056+ }
20562057 }
2057- }
2058- if (exit_signal ) {
2058+ if (exit_signal ) {
20592059#if 0
2060- while (running > 0 ) {
2061- while (wait (& status ) < 0 ) {
2060+ while (running > 0 ) {
2061+ while (wait (& status ) < 0 ) {
2062+ }
2063+ running -- ;
20622064 }
2063- running -- ;
2064- }
20652065#endif
2066- goto parent_out ;
2066+ goto parent_out ;
2067+ }
20672068 }
20682069 }
2070+ } else {
2071+ parent = 0 ;
20692072 }
2070- } else {
2071- parent = 0 ;
2072- }
20732073
20742074#endif /* WIN32 */
20752075 }
@@ -2096,9 +2096,6 @@ consult the installation file that came with this distribution, or visit \n\
20962096 break ;
20972097 case 'h' :
20982098 case '?' :
2099- if (request ) {
2100- fcgi_destroy_request (request );
2101- }
21022099 fcgi_shutdown ();
21032100 no_headers = 1 ;
21042101 SG (headers_sent ) = 1 ;
@@ -2120,9 +2117,9 @@ consult the installation file that came with this distribution, or visit \n\
21202117 fcgi_impersonate ();
21212118 }
21222119#endif
2123- while (!fastcgi || fcgi_accept_request (request ) >= 0 ) {
2124- SG (server_context ) = fastcgi ? (void * ) request : (void * ) 1 ;
2125- init_request_info (request );
2120+ while (!fastcgi || fcgi_accept_request (& request ) >= 0 ) {
2121+ SG (server_context ) = fastcgi ? (void * )& request : (void * ) 1 ;
2122+ init_request_info (& request );
21262123
21272124 if (!cgi && !fastcgi ) {
21282125 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\
23072304 * get path_translated */
23082305 if (php_request_startup () == FAILURE ) {
23092306 if (fastcgi ) {
2310- fcgi_finish_request (request , 1 );
2307+ fcgi_finish_request (& request , 1 );
23112308 }
23122309 SG (server_context ) = NULL ;
23132310 php_module_shutdown ();
@@ -2518,7 +2515,7 @@ consult the installation file that came with this distribution, or visit \n\
25182515 /* only fastcgi will get here */
25192516 requests ++ ;
25202517 if (max_requests && (requests == max_requests )) {
2521- fcgi_finish_request (request , 1 );
2518+ fcgi_finish_request (& request , 1 );
25222519 if (bindpath ) {
25232520 free (bindpath );
25242521 }
@@ -2530,9 +2527,6 @@ consult the installation file that came with this distribution, or visit \n\
25302527 }
25312528 /* end of fastcgi loop */
25322529 }
2533- if (request ) {
2534- fcgi_destroy_request (request );
2535- }
25362530 fcgi_shutdown ();
25372531
25382532 if (cgi_sapi_module .php_ini_path_override ) {
0 commit comments