@@ -1034,12 +1034,12 @@ static int is_valid_path(const char *path)
1034
1034
/* }}} */
1035
1035
1036
1036
#define CGI_GETENV (name ) \
1037
- ((request) ? \
1037
+ ((request->has_env ) ? \
1038
1038
FCGI_GETENV(request, name) : \
1039
1039
getenv(name))
1040
1040
1041
1041
#define CGI_PUTENV (name , value ) \
1042
- ((request) ? \
1042
+ ((request->has_env ) ? \
1043
1043
FCGI_PUTENV(request, name, value) : \
1044
1044
_sapi_cgi_putenv(name, sizeof(name)-1, value))
1045
1045
@@ -1732,7 +1732,7 @@ int main(int argc, char *argv[])
1732
1732
int fastcgi ;
1733
1733
char * bindpath = NULL ;
1734
1734
int fcgi_fd = 0 ;
1735
- fcgi_request * request = NULL ;
1735
+ fcgi_request request = { 0 } ;
1736
1736
int warmup_repeats = 0 ;
1737
1737
int repeats = 1 ;
1738
1738
int benchmark = 0 ;
@@ -1967,109 +1967,109 @@ consult the installation file that came with this distribution, or visit \n\
1967
1967
php_import_environment_variables = cgi_php_import_environment_variables ;
1968
1968
1969
1969
/* library is already initialized, now init our request */
1970
- request = fcgi_init_request (fcgi_fd );
1970
+ fcgi_init_request (& request , fcgi_fd );
1971
1971
1972
1972
#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 );
1980
1987
}
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
- }
1988
1988
1989
- if (children ) {
1990
- int running = 0 ;
1991
- pid_t pid ;
1989
+ if (children ) {
1990
+ int running = 0 ;
1991
+ pid_t pid ;
1992
1992
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 ();
1996
1996
#ifdef DEBUG_FASTCGI
1997
- fprintf (stderr , "Process group %d\n" , pgroup );
1997
+ fprintf (stderr , "Process group %d\n" , pgroup );
1998
1998
#endif
1999
1999
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
+ }
2010
2010
2011
- if (fcgi_in_shutdown ()) {
2012
- goto parent_out ;
2013
- }
2011
+ if (fcgi_in_shutdown ()) {
2012
+ goto parent_out ;
2013
+ }
2014
2014
2015
- while (parent ) {
2016
- do {
2015
+ while (parent ) {
2016
+ do {
2017
2017
#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 ;
2028
2028
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 ));
2044
2044
2045
- if (parent ) {
2045
+ if (parent ) {
2046
2046
#ifdef DEBUG_FASTCGI
2047
- fprintf (stderr , "Wait for kids, pid %d\n" , getpid ());
2047
+ fprintf (stderr , "Wait for kids, pid %d\n" , getpid ());
2048
2048
#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
+ }
2056
2057
}
2057
- }
2058
- if (exit_signal ) {
2058
+ if (exit_signal ) {
2059
2059
#if 0
2060
- while (running > 0 ) {
2061
- while (wait (& status ) < 0 ) {
2060
+ while (running > 0 ) {
2061
+ while (wait (& status ) < 0 ) {
2062
+ }
2063
+ running -- ;
2062
2064
}
2063
- running -- ;
2064
- }
2065
2065
#endif
2066
- goto parent_out ;
2066
+ goto parent_out ;
2067
+ }
2067
2068
}
2068
2069
}
2070
+ } else {
2071
+ parent = 0 ;
2069
2072
}
2070
- } else {
2071
- parent = 0 ;
2072
- }
2073
2073
2074
2074
#endif /* WIN32 */
2075
2075
}
@@ -2096,9 +2096,6 @@ consult the installation file that came with this distribution, or visit \n\
2096
2096
break ;
2097
2097
case 'h' :
2098
2098
case '?' :
2099
- if (request ) {
2100
- fcgi_destroy_request (request );
2101
- }
2102
2099
fcgi_shutdown ();
2103
2100
no_headers = 1 ;
2104
2101
SG (headers_sent ) = 1 ;
@@ -2120,9 +2117,9 @@ consult the installation file that came with this distribution, or visit \n\
2120
2117
fcgi_impersonate ();
2121
2118
}
2122
2119
#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 );
2126
2123
2127
2124
if (!cgi && !fastcgi ) {
2128
2125
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\
2307
2304
* get path_translated */
2308
2305
if (php_request_startup () == FAILURE ) {
2309
2306
if (fastcgi ) {
2310
- fcgi_finish_request (request , 1 );
2307
+ fcgi_finish_request (& request , 1 );
2311
2308
}
2312
2309
SG (server_context ) = NULL ;
2313
2310
php_module_shutdown ();
@@ -2518,7 +2515,7 @@ consult the installation file that came with this distribution, or visit \n\
2518
2515
/* only fastcgi will get here */
2519
2516
requests ++ ;
2520
2517
if (max_requests && (requests == max_requests )) {
2521
- fcgi_finish_request (request , 1 );
2518
+ fcgi_finish_request (& request , 1 );
2522
2519
if (bindpath ) {
2523
2520
free (bindpath );
2524
2521
}
@@ -2530,9 +2527,6 @@ consult the installation file that came with this distribution, or visit \n\
2530
2527
}
2531
2528
/* end of fastcgi loop */
2532
2529
}
2533
- if (request ) {
2534
- fcgi_destroy_request (request );
2535
- }
2536
2530
fcgi_shutdown ();
2537
2531
2538
2532
if (cgi_sapi_module .php_ini_path_override ) {
0 commit comments