6868#include "ap_config.h"
6969#include "ap_listen.h"
7070#include "mpm_default.h"
71- //#include "service.h"
7271#include "iol_socket.h"
7372#include "winnt.h"
7473
75-
7674/*
7775 * Definitions of WINNT MPM specific config globals
7876 */
@@ -105,9 +103,8 @@ int ap_daemons_to_start=0;
105103static event * exit_event ;
106104HANDLE maintenance_event ;
107105ap_lock_t * start_mutex ;
108- int my_pid ;
109- int parent_pid ;
110- typedef void (CALLBACK * ap_completion_t )();
106+ DWORD my_pid ;
107+ DWORD parent_pid ;
111108API_VAR_EXPORT ap_completion_t ap_mpm_init_complete = NULL ;
112109
113110static ap_status_t socket_cleanup (void * sock )
@@ -299,15 +296,19 @@ static void signal_parent(int type)
299296 }
300297 CloseHandle (e );
301298}
299+
302300static int volatile is_graceful = 0 ;
301+
303302API_EXPORT (int ) ap_graceful_stop_signalled (void )
304303{
305304 return is_graceful ;
306305}
307- void ap_start_shutdown (void )
306+
307+ API_EXPORT (void ) ap_start_shutdown (void )
308308{
309309 signal_parent (0 );
310310}
311+
311312/*
312313 * Initialise the signal names, in the global variables signal_name_prefix,
313314 * signal_restart_name and signal_shutdown_name.
@@ -354,6 +355,7 @@ static void sock_disable_nagle(int s)
354355 * Routines to deal with managing the list of listening sockets.
355356 */
356357static ap_listen_rec * head_listener ;
358+
357359static ap_inline ap_listen_rec * find_ready_listener (fd_set * main_fds )
358360{
359361 ap_listen_rec * lr ;
@@ -371,6 +373,7 @@ static ap_inline ap_listen_rec *find_ready_listener(fd_set * main_fds)
371373 }
372374 return NULL ;
373375}
376+
374377static int setup_listeners (server_rec * s )
375378{
376379 ap_listen_rec * lr ;
@@ -1390,7 +1393,10 @@ static int create_process(ap_pool_t *p, HANDLE *handles, HANDLE *events, int *pr
13901393 int rv ;
13911394 char buf [1024 ];
13921395 char * pCommand ;
1396+ char * pEnvVar ;
1397+ char * pEnvBlock ;
13931398 int i ;
1399+ int iEnvBlockLen ;
13941400 STARTUPINFO si ; /* Filled in prior to call to CreateProcess */
13951401 PROCESS_INFORMATION pi ; /* filled in on call to CreateProces */
13961402
@@ -1425,15 +1431,39 @@ static int create_process(ap_pool_t *p, HANDLE *handles, HANDLE *events, int *pr
14251431 pCommand = ap_pstrcat (p , pCommand , " \"" , server_conf -> process -> argv [i ], "\"" , NULL );
14261432 }
14271433
1434+ /* Build the environment, since Win9x disrespects the active env */
1435+ // SetEnvironmentVariable("AP_PARENT_PID",ap_psprintf(p,"%l",parent_pid));
1436+ pEnvVar = ap_psprintf (p , "AP_PARENT_PID=%i" , parent_pid );
1437+ /*
1438+ * Win32's CreateProcess call requires that the environment
1439+ * be passed in an environment block, a null terminated block of
1440+ * null terminated strings.
1441+ */
1442+ i = 0 ;
1443+ iEnvBlockLen = 1 ;
1444+ while (_environ [i ]) {
1445+ iEnvBlockLen += strlen (_environ [i ]) + 1 ;
1446+ i ++ ;
1447+ }
1448+
1449+ pEnvBlock = (char * )ap_pcalloc (p , iEnvBlockLen + strlen (pEnvVar ) + 1 );
1450+ strcpy (pEnvBlock , pEnvVar );
1451+ pEnvVar = strchr (pEnvBlock , '\0' ) + 1 ;
1452+
1453+ i = 0 ;
1454+ while (_environ [i ]) {
1455+ strcpy (pEnvVar , _environ [i ]);
1456+ pEnvVar = strchr (pEnvVar , '\0' ) + 1 ;
1457+ i ++ ;
1458+ }
1459+ pEnvVar = '\0' ;
14281460 /* Create a pipe to send socket info to the child */
14291461 if (!CreatePipe (& hPipeRead , & hPipeWrite , & sa , 0 )) {
14301462 ap_log_error (APLOG_MARK , APLOG_CRIT , GetLastError (), server_conf ,
14311463 "Parent: Unable to create pipe to child process.\n" );
14321464 return -1 ;
14331465 }
14341466
1435- SetEnvironmentVariable ("AP_PARENT_PID" ,ap_psprintf (p ,"%d" ,parent_pid ));
1436-
14371467 /* Give the read end of the pipe (hPipeRead) to the child as stdin. The
14381468 * parent will write the socket data to the child on this pipe.
14391469 */
@@ -1447,7 +1477,7 @@ static int create_process(ap_pool_t *p, HANDLE *handles, HANDLE *events, int *pr
14471477 if (!CreateProcess (NULL , pCommand , NULL , NULL ,
14481478 TRUE, /* Inherit handles */
14491479 CREATE_SUSPENDED , /* Creation flags */
1450- NULL , /* Environment block */
1480+ pEnvBlock , /* Environment block */
14511481 NULL ,
14521482 & si , & pi )) {
14531483 ap_log_error (APLOG_MARK , APLOG_CRIT , GetLastError (), server_conf ,
@@ -1694,12 +1724,12 @@ static void winnt_pre_config(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptemp
16941724 pid = getenv ("AP_PARENT_PID" );
16951725 if (pid ) {
16961726 /* This is the child */
1697- parent_pid = atoi (pid );
1698- my_pid = getpid ();
1727+ parent_pid = ( DWORD ) atol (pid );
1728+ my_pid = GetCurrentProcessId ();
16991729 }
17001730 else {
17011731 /* This is the parent */
1702- parent_pid = my_pid = getpid ();
1732+ parent_pid = my_pid = GetCurrentProcessId ();
17031733 }
17041734
17051735 ap_listen_pre_config ();
@@ -1806,7 +1836,7 @@ API_EXPORT(int) ap_mpm_run(ap_pool_t *_pconf, ap_pool_t *plog, server_rec *s )
18061836 if (pidfile != NULL && unlink (pidfile ) == 0 ) {
18071837 ap_log_error (APLOG_MARK , APLOG_NOERRNO |APLOG_INFO ,APR_SUCCESS ,
18081838 server_conf , "removed PID file %s (pid=%ld)" ,
1809- pidfile , ( long ) getpid ());
1839+ pidfile , GetCurrentProcessId ());
18101840 }
18111841 ap_destroy_lock (start_mutex );
18121842
0 commit comments