diff options
| author | Stefan Fritsch <sf@sfritsch.de> | 2011-12-27 19:43:09 +0100 |
|---|---|---|
| committer | Stefan Fritsch <sf@sfritsch.de> | 2011-12-27 19:43:09 +0100 |
| commit | 5b56d06a01a150fc9685e6f913774be3f9deb49f (patch) | |
| tree | 9fbfbe0313b782941f1c2c4d3cb5203817144108 /server/mpm | |
| parent | 498ea95018b369e62646a98c7d7d5413b56e170c (diff) | |
| download | apache2-5b56d06a01a150fc9685e6f913774be3f9deb49f.tar.gz | |
Upstream tarball 2.2.19upstream/2.2.19
Diffstat (limited to 'server/mpm')
| -rw-r--r-- | server/mpm/config.m4 | 4 | ||||
| -rw-r--r-- | server/mpm/prefork/prefork.c | 9 | ||||
| -rw-r--r-- | server/mpm/winnt/Makefile.in | 5 | ||||
| -rw-r--r-- | server/mpm/winnt/child.c | 58 | ||||
| -rw-r--r-- | server/mpm/winnt/config.m4 | 3 | ||||
| -rw-r--r-- | server/mpm/winnt/mpm_winnt.c | 115 | ||||
| -rw-r--r-- | server/mpm/winnt/mpm_winnt.h | 6 | ||||
| -rw-r--r-- | server/mpm/winnt/nt_eventlog.c | 8 | ||||
| -rw-r--r-- | server/mpm/winnt/service.c | 47 |
9 files changed, 121 insertions, 134 deletions
diff --git a/server/mpm/config.m4 b/server/mpm/config.m4 index 6ea447d1..b0907769 100644 --- a/server/mpm/config.m4 +++ b/server/mpm/config.m4 @@ -1,7 +1,7 @@ AC_MSG_CHECKING(which MPM to use) AC_ARG_WITH(mpm, APACHE_HELP_STRING(--with-mpm=MPM,Choose the process model for Apache to use. - MPM={beos|event|worker|prefork|mpmt_os2}),[ + MPM={beos|event|worker|prefork|mpmt_os2|winnt}),[ APACHE_MPM=$withval ],[ if test "x$APACHE_MPM" = "x"; then @@ -14,7 +14,7 @@ apache_cv_mpm=$APACHE_MPM ap_mpm_is_threaded () { - if test "$apache_cv_mpm" = "worker" -o "$apache_cv_mpm" = "event" ; then + if test "$apache_cv_mpm" = "worker" -o "$apache_cv_mpm" = "event" -o "$apache_cv_mpm" = "winnt" ; then return 0 else return 1 diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index f5a72057..108f961a 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -330,6 +330,7 @@ static void just_die(int sig) static void stop_listening(int sig) { + mpm_state = AP_MPMQ_STOPPING; ap_close_listeners(); /* For a graceful stop, we want the child to exit when done */ @@ -350,6 +351,7 @@ static void sig_term(int sig) */ return; } + mpm_state = AP_MPMQ_STOPPING; shutdown_pending = 1; is_graceful = (sig == AP_SIG_GRACEFUL_STOP); } @@ -363,6 +365,7 @@ static void restart(int sig) /* Probably not an error - don't bother reporting it */ return; } + mpm_state = AP_MPMQ_STOPPING; restart_pending = 1; is_graceful = (sig == AP_SIG_GRACEFUL); } @@ -458,8 +461,10 @@ static int num_listensocks = 0; int ap_graceful_stop_signalled(void) { - /* not ever called anymore... */ - return 0; + /* Return true if the server is stopping for whatever reason; the + * function is used to initiate a fast exit from the connection + * processing loop. */ + return mpm_state == AP_MPMQ_STOPPING; } diff --git a/server/mpm/winnt/Makefile.in b/server/mpm/winnt/Makefile.in new file mode 100644 index 00000000..38957c87 --- /dev/null +++ b/server/mpm/winnt/Makefile.in @@ -0,0 +1,5 @@ + +LTLIBRARY_NAME = libwinnt.la +LTLIBRARY_SOURCES = mpm_winnt.c child.c nt_eventlog.c service.c + +include $(top_srcdir)/build/ltlib.mk diff --git a/server/mpm/winnt/child.c b/server/mpm/winnt/child.c index d918e47a..82cec95f 100644 --- a/server/mpm/winnt/child.c +++ b/server/mpm/winnt/child.c @@ -39,6 +39,12 @@ #include <malloc.h> #include "apr_atomic.h" +#include <process.h> + +#ifdef __MINGW32__ +#include <mswsock.h> +#endif + /* shared with mpm_winnt.c */ extern DWORD my_pid; @@ -63,8 +69,8 @@ static apr_thread_mutex_t *child_lock; static apr_thread_mutex_t *qlock; static PCOMP_CONTEXT qhead = NULL; static PCOMP_CONTEXT qtail = NULL; -static int num_completion_contexts = 0; -static int max_num_completion_contexts = 0; +static apr_uint32_t num_completion_contexts = 0; +static apr_uint32_t max_num_completion_contexts = 0; static HANDLE ThreadDispatchIOCP = NULL; static HANDLE qwait_event = NULL; @@ -350,7 +356,7 @@ static unsigned int __stdcall win9x_accept(void * dummy) apr_os_sock_get(&nsd, lr->sd); FD_SET(nsd, &listenfds); ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, - "Child %d: Listening on port %d.", my_pid, lr->bind_addr->port); + "Child %lu: Listening on port %d.", my_pid, lr->bind_addr->port); } } @@ -510,7 +516,7 @@ static unsigned int __stdcall winnt_accept(void *lr_) #endif ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, - "Child %d: Starting thread to listen on port %d.", my_pid, lr->bind_addr->port); + "Child %lu: Starting thread to listen on port %d.", my_pid, lr->bind_addr->port); while (!shutdown_in_progress) { if (!context) { context = mpm_get_completion_context(); @@ -578,7 +584,7 @@ static unsigned int __stdcall winnt_accept(void *lr_) context->accept_socket = INVALID_SOCKET; if (err_count > MAX_ACCEPTEX_ERR_COUNT) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, - "Child %d: Encountered too many errors accepting client connections. " + "Child %lu: Encountered too many errors accepting client connections. " "Possible causes: dynamic address renewal, or incompatible VPN or firewall software. " "Try using the Win32DisableAcceptEx directive.", my_pid); err_count = 0; @@ -590,7 +596,7 @@ static unsigned int __stdcall winnt_accept(void *lr_) ++err_count; if (err_count > MAX_ACCEPTEX_ERR_COUNT) { ap_log_error(APLOG_MARK,APLOG_ERR, rv, ap_server_conf, - "Child %d: Encountered too many errors accepting client connections. " + "Child %lu: Encountered too many errors accepting client connections. " "Possible causes: Unknown. " "Try using the Win32DisableAcceptEx directive.", my_pid); err_count = 0; @@ -676,7 +682,7 @@ static unsigned int __stdcall winnt_accept(void *lr_) SetEvent(exit_event); } ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, ap_server_conf, - "Child %d: Accept thread exiting.", my_pid); + "Child %lu: Accept thread exiting.", my_pid); return 0; } @@ -705,7 +711,7 @@ static PCOMP_CONTEXT winnt_get_connection(PCOMP_CONTEXT context) if (!rc) { rc = apr_get_os_error(); ap_log_error(APLOG_MARK,APLOG_DEBUG, rc, ap_server_conf, - "Child %d: GetQueuedComplationStatus returned %d", my_pid, rc); + "Child %lu: GetQueuedComplationStatus returned %d", my_pid, rc); continue; } @@ -822,9 +828,9 @@ static void cleanup_thread(HANDLE *handles, int *thread_cnt, int thread_to_clean * monitors the child process for maintenance and shutdown * events. */ -static void create_listener_thread() +static void create_listener_thread(void) { - int tid; + unsigned tid; int num_listeners = 0; if (!use_acceptex) { _beginthreadex(NULL, 0, win9x_accept, @@ -870,7 +876,7 @@ void child_main(apr_pool_t *pconf) int watch_thread; int time_remains; int cld; - int tid; + unsigned tid; int rv; int i; @@ -884,7 +890,7 @@ void child_main(apr_pool_t *pconf) max_requests_per_child_event = CreateEvent(NULL, TRUE, FALSE, NULL); if (!max_requests_per_child_event) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, - "Child %d: Failed to create a max_requests event.", my_pid); + "Child %lu: Failed to create a max_requests event.", my_pid); exit(APEXIT_CHILDINIT); } child_events[0] = exit_event; @@ -902,11 +908,11 @@ void child_main(apr_pool_t *pconf) status = apr_proc_mutex_lock(start_mutex); if (status != APR_SUCCESS) { ap_log_error(APLOG_MARK,APLOG_ERR, status, ap_server_conf, - "Child %d: Failed to acquire the start_mutex. Process will exit.", my_pid); + "Child %lu: Failed to acquire the start_mutex. Process will exit.", my_pid); exit(APEXIT_CHILDINIT); } ap_log_error(APLOG_MARK,APLOG_NOTICE, APR_SUCCESS, ap_server_conf, - "Child %d: Acquired the start mutex.", my_pid); + "Child %lu: Acquired the start mutex.", my_pid); /* * Create the worker thread dispatch IOCompletionPort @@ -922,7 +928,7 @@ void child_main(apr_pool_t *pconf) qwait_event = CreateEvent(NULL, TRUE, FALSE, NULL); if (!qwait_event) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, - "Child %d: Failed to create a qwait event.", my_pid); + "Child %lu: Failed to create a qwait event.", my_pid); exit(APEXIT_CHILDINIT); } } @@ -931,7 +937,7 @@ void child_main(apr_pool_t *pconf) * Create the pool of worker threads */ ap_log_error(APLOG_MARK,APLOG_NOTICE, APR_SUCCESS, ap_server_conf, - "Child %d: Starting %d worker threads.", my_pid, ap_threads_per_child); + "Child %lu: Starting %d worker threads.", my_pid, ap_threads_per_child); child_handles = (HANDLE) apr_pcalloc(pchild, ap_threads_per_child * sizeof(HANDLE)); apr_thread_mutex_create(&child_lock, APR_THREAD_MUTEX_DEFAULT, pchild); @@ -947,7 +953,7 @@ void child_main(apr_pool_t *pconf) worker_main, (void *) i, 0, &tid); if (child_handles[i] == 0) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, - "Child %d: _beginthreadex failed. Unable to create all worker threads. " + "Child %lu: _beginthreadex failed. Unable to create all worker threads. " "Created %d of the %d threads requested with the ThreadsPerChild configuration directive.", my_pid, threads_created, ap_threads_per_child); ap_signal_parent(SIGNAL_PARENT_SHUTDOWN); @@ -1019,13 +1025,13 @@ void child_main(apr_pool_t *pconf) if (rv == WAIT_FAILED) { /* Something serious is wrong */ ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, - "Child %d: WAIT_FAILED -- shutting down server", my_pid); + "Child %lu: WAIT_FAILED -- shutting down server", my_pid); break; } else if (cld == 0) { /* Exit event was signaled */ ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf, - "Child %d: Exit event signaled. Child process is ending.", my_pid); + "Child %lu: Exit event signaled. Child process is ending.", my_pid); break; } else { @@ -1033,7 +1039,7 @@ void child_main(apr_pool_t *pconf) * Signal the parent to restart */ ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf, - "Child %d: Process exiting because it reached " + "Child %lu: Process exiting because it reached " "MaxRequestsPerChild. Signaling the parent to " "restart a new child process.", my_pid); ap_signal_parent(SIGNAL_PARENT_RESTART); @@ -1078,11 +1084,11 @@ void child_main(apr_pool_t *pconf) rv = apr_proc_mutex_unlock(start_mutex); if (rv == APR_SUCCESS) { ap_log_error(APLOG_MARK,APLOG_NOTICE, rv, ap_server_conf, - "Child %d: Released the start mutex", my_pid); + "Child %lu: Released the start mutex", my_pid); } else { ap_log_error(APLOG_MARK,APLOG_ERR, rv, ap_server_conf, - "Child %d: Failure releasing the start mutex", my_pid); + "Child %lu: Failure releasing the start mutex", my_pid); } /* Shutdown the worker threads */ @@ -1095,7 +1101,7 @@ void child_main(apr_pool_t *pconf) /* Post worker threads blocked on the ThreadDispatch IOCompletion port */ while (g_blocked_threads > 0) { ap_log_error(APLOG_MARK,APLOG_INFO, APR_SUCCESS, ap_server_conf, - "Child %d: %d threads blocked on the completion port", my_pid, g_blocked_threads); + "Child %lu: %d threads blocked on the completion port", my_pid, g_blocked_threads); for (i=g_blocked_threads; i > 0; i--) { PostQueuedCompletionStatus(ThreadDispatchIOCP, 0, IOCP_SHUTDOWN, NULL); } @@ -1135,7 +1141,7 @@ void child_main(apr_pool_t *pconf) if ((time_remains % 30000) == 0) { ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf, - "Child %d: Waiting %d more seconds " + "Child %lu: Waiting %d more seconds " "for %d worker threads to finish.", my_pid, time_remains / 1000, threads_created); } @@ -1179,7 +1185,7 @@ void child_main(apr_pool_t *pconf) /* Kill remaining threads off the hard way */ if (threads_created) { ap_log_error(APLOG_MARK,APLOG_NOTICE, APR_SUCCESS, ap_server_conf, - "Child %d: Terminating %d threads that failed to exit.", + "Child %lu: Terminating %d threads that failed to exit.", my_pid, threads_created); } for (i = 0; i < threads_created; i++) { @@ -1194,7 +1200,7 @@ void child_main(apr_pool_t *pconf) } } ap_log_error(APLOG_MARK,APLOG_NOTICE, APR_SUCCESS, ap_server_conf, - "Child %d: All worker threads have exited.", my_pid); + "Child %lu: All worker threads have exited.", my_pid); CloseHandle(allowed_globals.jobsemaphore); apr_thread_mutex_destroy(allowed_globals.jobmutex); diff --git a/server/mpm/winnt/config.m4 b/server/mpm/winnt/config.m4 new file mode 100644 index 00000000..93209588 --- /dev/null +++ b/server/mpm/winnt/config.m4 @@ -0,0 +1,3 @@ +if test "$MPM_NAME" = "winnt" ; then
+ APACHE_FAST_OUTPUT(server/mpm/$MPM_NAME/Makefile)
+fi
diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 52c4ff9c..d9513175 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -39,6 +39,15 @@ #include <malloc.h> #include "apr_atomic.h" +/* Because ap_setup_listeners() is skipped in the child, any merging + * of [::]:80 and 0.0.0.0:80 for AP_ENABLE_V4_MAPPED in the parent + * won't have taken place in the child, so the child will expect to + * read two sockets for "Listen 80" but the parent will send only + * one. + */ +#ifdef AP_ENABLE_V4_MAPPED +#error The WinNT MPM does not currently support AP_ENABLE_V4_MAPPED +#endif /* scoreboard.c does the heavy lifting; all we do is create the child * score by moving a handle down the pipe into the child's stdin. @@ -50,7 +59,7 @@ server_rec *ap_server_conf; static HANDLE shutdown_event; /* used to signal the parent to shutdown */ static HANDLE restart_event; /* used to signal the parent to restart */ -static char ap_coredump_dir[MAX_STRING_LEN]; +char ap_coredump_dir[MAX_STRING_LEN]; static int one_process = 0; static char const* signal_arg = NULL; @@ -93,30 +102,11 @@ extern HANDLE exit_event; */ static HANDLE pipe; -/* Stub functions until this MPM supports the connection status API */ - -AP_DECLARE(void) ap_update_connection_status(long conn_id, const char *key, \ - const char *value) -{ - /* NOP */ -} - -AP_DECLARE(void) ap_reset_connection_status(long conn_id) -{ - /* NOP */ -} - -AP_DECLARE(apr_array_header_t *) ap_get_status_table(apr_pool_t *p) -{ - /* NOP */ - return NULL; -} - /* * Command processors */ -static const char *set_threads_per_child (cmd_parms *cmd, void *dummy, char *arg) +static const char *set_threads_per_child (cmd_parms *cmd, void *dummy, const char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); if (err != NULL) { @@ -182,7 +172,7 @@ static const char *set_thread_limit (cmd_parms *cmd, void *dummy, const char *ar } return NULL; } -static const char *set_disable_acceptex(cmd_parms *cmd, void *dummy, char *arg) +static const char *set_disable_acceptex(cmd_parms *cmd, void *dummy) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); if (err != NULL) { @@ -331,9 +321,9 @@ AP_DECLARE(void) ap_signal_parent(ap_signal_parent_e type) * start mutex [signal from the parent to begin accept()] * scoreboard shm handle [to recreate the ap_scoreboard] */ -void get_handles_from_parent(server_rec *s, HANDLE *child_exit_event, - apr_proc_mutex_t **child_start_mutex, - apr_shm_t **scoreboard_shm) +static void get_handles_from_parent(server_rec *s, HANDLE *child_exit_event, + apr_proc_mutex_t **child_start_mutex, + apr_shm_t **scoreboard_shm) { HANDLE hScore; HANDLE ready_event; @@ -349,7 +339,7 @@ void get_handles_from_parent(server_rec *s, HANDLE *child_exit_event, &BytesRead, (LPOVERLAPPED) NULL) || (BytesRead != sizeof(HANDLE))) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, - "Child %d: Unable to retrieve the ready event from the parent", my_pid); + "Child %lu: Unable to retrieve the ready event from the parent", my_pid); exit(APEXIT_CHILDINIT); } @@ -360,7 +350,7 @@ void get_handles_from_parent(server_rec *s, HANDLE *child_exit_event, &BytesRead, (LPOVERLAPPED) NULL) || (BytesRead != sizeof(HANDLE))) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, - "Child %d: Unable to retrieve the exit event from the parent", my_pid); + "Child %lu: Unable to retrieve the exit event from the parent", my_pid); exit(APEXIT_CHILDINIT); } @@ -368,14 +358,14 @@ void get_handles_from_parent(server_rec *s, HANDLE *child_exit_event, &BytesRead, (LPOVERLAPPED) NULL) || (BytesRead != sizeof(os_start))) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, - "Child %d: Unable to retrieve the start_mutex from the parent", my_pid); + "Child %lu: Unable to retrieve the start_mutex from the parent", my_pid); exit(APEXIT_CHILDINIT); } *child_start_mutex = NULL; if ((rv = apr_os_proc_mutex_put(child_start_mutex, &os_start, s->process->pool)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, - "Child %d: Unable to access the start_mutex from the parent", my_pid); + "Child %lu: Unable to access the start_mutex from the parent", my_pid); exit(APEXIT_CHILDINIT); } @@ -383,21 +373,21 @@ void get_handles_from_parent(server_rec *s, HANDLE *child_exit_event, &BytesRead, (LPOVERLAPPED) NULL) || (BytesRead != sizeof(hScore))) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, - "Child %d: Unable to retrieve the scoreboard from the parent", my_pid); + "Child %lu: Unable to retrieve the scoreboard from the parent", my_pid); exit(APEXIT_CHILDINIT); } *scoreboard_shm = NULL; if ((rv = apr_os_shm_put(scoreboard_shm, &hScore, s->process->pool)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, - "Child %d: Unable to access the scoreboard from the parent", my_pid); + "Child %lu: Unable to access the scoreboard from the parent", my_pid); exit(APEXIT_CHILDINIT); } rv = ap_reopen_scoreboard(s->process->pool, scoreboard_shm, 1); if (rv || !(sb_shared = apr_shm_baseaddr_get(*scoreboard_shm))) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "Child %d: Unable to reopen the scoreboard from the parent", my_pid); + "Child %lu: Unable to reopen the scoreboard from the parent", my_pid); exit(APEXIT_CHILDINIT); } /* We must 'initialize' the scoreboard to relink all the @@ -406,7 +396,7 @@ void get_handles_from_parent(server_rec *s, HANDLE *child_exit_event, ap_init_scoreboard(sb_shared); ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, - "Child %d: Retrieved our scoreboard from the parent.", my_pid); + "Child %lu: Retrieved our scoreboard from the parent.", my_pid); } @@ -496,7 +486,7 @@ static int send_handles_to_child(apr_pool_t *p, * exclusively in the child process, receives them from the parent and * makes them availeble in the child. */ -void get_listeners_from_parent(server_rec *s) +static void get_listeners_from_parent(server_rec *s) { WSAPROTOCOL_INFO WSAProtocolInfo; ap_listen_rec *lr; @@ -530,7 +520,7 @@ void get_listeners_from_parent(server_rec *s) &WSAProtocolInfo, 0, 0); if (nsd == INVALID_SOCKET) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_netos_error(), ap_server_conf, - "Child %d: setup_inherited_listeners(), WSASocket failed to open the inherited socket.", my_pid); + "Child %lu: setup_inherited_listeners(), WSASocket failed to open the inherited socket.", my_pid); exit(APEXIT_CHILDINIT); } @@ -562,7 +552,7 @@ void get_listeners_from_parent(server_rec *s) } ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, - "Child %d: retrieved %d listeners from parent", my_pid, lcnt); + "Child %lu: retrieved %d listeners from parent", my_pid, lcnt); } @@ -582,14 +572,14 @@ static int send_listeners_to_child(apr_pool_t *p, DWORD dwProcessId, for (lr = ap_listeners; lr; lr = lr->next, ++lcnt) { apr_os_sock_t nsd; lpWSAProtocolInfo = apr_pcalloc(p, sizeof(WSAPROTOCOL_INFO)); - apr_os_sock_get(&nsd,lr->sd); + apr_os_sock_get(&nsd, lr->sd); ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, ap_server_conf, - "Parent: Duplicating socket %d and sending it to child process %d", + "Parent: Duplicating socket %d and sending it to child process %lu", nsd, dwProcessId); if (WSADuplicateSocket(nsd, dwProcessId, lpWSAProtocolInfo) == SOCKET_ERROR) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_netos_error(), ap_server_conf, - "Parent: WSADuplicateSocket failed for socket %d. Check the FAQ.", lr->sd ); + "Parent: WSADuplicateSocket failed for socket %d. Check the FAQ.", nsd); return -1; } @@ -597,13 +587,13 @@ static int send_listeners_to_child(apr_pool_t *p, DWORD dwProcessId, sizeof(WSAPROTOCOL_INFO), &BytesWritten)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, - "Parent: Unable to write duplicated socket %d to the child.", lr->sd ); + "Parent: Unable to write duplicated socket %d to the child.", nsd); return -1; } } ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, - "Parent: Sent %d listeners to child %d", lcnt, dwProcessId); + "Parent: Sent %d listeners to child %lu", lcnt, dwProcessId); return 0; } @@ -722,11 +712,12 @@ static int create_process(apr_pool_t *p, HANDLE *child_proc, HANDLE *child_exit_ } env = apr_palloc(ptemp, (envc + 2) * sizeof (char*)); memcpy(env, _environ, envc * sizeof (char*)); - apr_snprintf(pidbuf, sizeof(pidbuf), "AP_PARENT_PID=%i", parent_pid); + apr_snprintf(pidbuf, sizeof(pidbuf), "AP_PARENT_PID=%lu", parent_pid); env[envc] = pidbuf; env[envc + 1] = NULL; - rv = apr_proc_create(&new_child, cmd, args, env, attr, ptemp); + rv = apr_proc_create(&new_child, cmd, (const char * const *)args, + (const char * const *)env, attr, ptemp); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Parent: Failed to create the child process."); @@ -845,13 +836,14 @@ static int create_process(apr_pool_t *p, HANDLE *child_proc, HANDLE *child_exit_ static int master_main(server_rec *s, HANDLE shutdown_event, HANDLE restart_event) { int rv, cld; + int child_created; int restart_pending; int shutdown_pending; HANDLE child_exit_event; HANDLE event_handles[NUM_WAIT_HANDLES]; DWORD child_pid; - restart_pending = shutdown_pending = 0; + child_created = restart_pending = shutdown_pending = 0; event_handles[SHUTDOWN_HANDLE] = shutdown_event; event_handles[RESTART_HANDLE] = restart_event; @@ -866,6 +858,9 @@ static int master_main(server_rec *s, HANDLE shutdown_event, HANDLE restart_even shutdown_pending = 1; goto die_now; } + + child_created = 1; + if (!strcasecmp(signal_arg, "runservice")) { mpm_service_started(); } @@ -915,7 +910,7 @@ static int master_main(server_rec *s, HANDLE shutdown_event, HANDLE restart_even } if (SetEvent(child_exit_event) == 0) { ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), s, - "Parent: SetEvent for child process %d failed.", + "Parent: SetEvent for child process %pp failed.", event_handles[CHILD_HANDLE]); } /* Don't wait to verify that the child process really exits, @@ -935,14 +930,14 @@ static int master_main(server_rec *s, HANDLE shutdown_event, HANDLE restart_even || exitcode == APEXIT_CHILDINIT || exitcode == APEXIT_INIT) { ap_log_error(APLOG_MARK, APLOG_CRIT, 0, ap_server_conf, - "Parent: child process exited with status %u -- Aborting.", exitcode); + "Parent: child process exited with status %lu -- Aborting.", exitcode); shutdown_pending = 1; } else { int i; restart_pending = 1; ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf, - "Parent: child process exited with status %u -- Restarting.", exitcode); + "Parent: child process exited with status %lu -- Restarting.", exitcode); for (i = 0; i < ap_threads_per_child; i++) { ap_update_child_status_from_indexes(0, i, SERVER_DEAD, NULL); } @@ -960,6 +955,10 @@ die_now: int timeout = 30000; /* Timeout is milliseconds */ winnt_mpm_state = AP_MPMQ_STOPPING; + if (!child_created) { + return 0; /* Tell the caller we do not want to restart */ + } + /* This shutdown is only marginally graceful. We will give the * child a bit of time to exit gracefully. If the time expires, * the child will be wacked. @@ -970,7 +969,8 @@ die_now: /* Signal the child processes to exit */ if (SetEvent(child_exit_event) == 0) { ap_log_error(APLOG_MARK,APLOG_ERR, apr_get_os_error(), ap_server_conf, - "Parent: SetEvent for child process %d failed", event_handles[CHILD_HANDLE]); + "Parent: SetEvent for child process %pp failed", + event_handles[CHILD_HANDLE]); } if (event_handles[CHILD_HANDLE]) { rv = WaitForSingleObject(event_handles[CHILD_HANDLE], timeout); @@ -982,7 +982,8 @@ die_now: } else { ap_log_error(APLOG_MARK,APLOG_NOTICE, APR_SUCCESS, ap_server_conf, - "Parent: Forcing termination of child process %d ", event_handles[CHILD_HANDLE]); + "Parent: Forcing termination of child process %pp", + event_handles[CHILD_HANDLE]); TerminateProcess(event_handles[CHILD_HANDLE], 1); CloseHandle(event_handles[CHILD_HANDLE]); event_handles[CHILD_HANDLE] = NULL; @@ -1057,9 +1058,9 @@ static apr_status_t service_set = SERVICE_UNSET; static apr_status_t service_to_start_success; static int inst_argc; static const char * const *inst_argv; -static char *service_name = NULL; +static const char *service_name = NULL; -void winnt_rewrite_args(process_rec *process) +static void winnt_rewrite_args(process_rec *process) { /* Handle the following SCM aspects in this phase: * @@ -1199,7 +1200,7 @@ void winnt_rewrite_args(process_rec *process) optbuf[0] = '-'; optbuf[2] = '\0'; - apr_getopt_init(&opt, process->pool, process->argc, (char**) process->argv); + apr_getopt_init(&opt, process->pool, process->argc, process->argv); opt->errfn = NULL; while ((rv = apr_getopt(opt, "wn:k:" AP_SERVER_BASEARGS, optbuf + 1, &optarg)) == APR_SUCCESS) { @@ -1523,7 +1524,7 @@ static int winnt_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *pt * across a restart */ PSECURITY_ATTRIBUTES sa = GetNullACL(); /* returns NULL if invalid (Win95?) */ - setup_signal_names(apr_psprintf(pconf,"ap%d", parent_pid)); + setup_signal_names(apr_psprintf(pconf,"ap%lu", parent_pid)); ap_log_pid(pconf, ap_pid_fname); @@ -1635,7 +1636,7 @@ static void winnt_child_init(apr_pool_t *pchild, struct server_rec *s) { apr_status_t rv; - setup_signal_names(apr_psprintf(pchild,"ap%d", parent_pid)); + setup_signal_names(apr_psprintf(pchild,"ap%lu", parent_pid)); /* This is a child process, not in single process mode */ if (!one_process) { @@ -1657,7 +1658,7 @@ static void winnt_child_init(apr_pool_t *pchild, struct server_rec *s) APR_LOCK_DEFAULT, s->process->pool); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK,APLOG_ERR, rv, ap_server_conf, - "%s child %d: Unable to init the start_mutex.", + "%s child %lu: Unable to init the start_mutex.", service_name, my_pid); exit(APEXIT_CHILDINIT); } @@ -1700,12 +1701,12 @@ AP_DECLARE(int) ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s ) /* The child process or in one_process (debug) mode */ ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf, - "Child %d: Child process is running", my_pid); + "Child %lu: Child process is running", my_pid); child_main(pconf); ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf, - "Child %d: Child process is exiting", my_pid); + "Child %lu: Child process is exiting", my_pid); return 1; } else diff --git a/server/mpm/winnt/mpm_winnt.h b/server/mpm/winnt/mpm_winnt.h index dfe0e518..e21a6f43 100644 --- a/server/mpm/winnt/mpm_winnt.h +++ b/server/mpm/winnt/mpm_winnt.h @@ -62,7 +62,7 @@ void mpm_start_child_console_handler(void); /* From nt_eventlog.c: */ -void mpm_nt_eventlog_stderr_open(char *display_name, apr_pool_t *p); +void mpm_nt_eventlog_stderr_open(const char *display_name, apr_pool_t *p); void mpm_nt_eventlog_stderr_flush(void); /* From winnt.c: */ @@ -126,5 +126,9 @@ PCOMP_CONTEXT mpm_get_completion_context(void); void mpm_recycle_completion_context(PCOMP_CONTEXT pCompContext); apr_status_t mpm_post_completion_context(PCOMP_CONTEXT pCompContext, io_state_e state); void hold_console_open_on_error(void); + +/* From child.c: */ +void child_main(apr_pool_t *pconf); + #endif /* APACHE_MPM_WINNT_H */ /** @} */ diff --git a/server/mpm/winnt/nt_eventlog.c b/server/mpm/winnt/nt_eventlog.c index baa1a88b..d8d758bb 100644 --- a/server/mpm/winnt/nt_eventlog.c +++ b/server/mpm/winnt/nt_eventlog.c @@ -24,7 +24,7 @@ #include "apr_portable.h" #include "ap_regkey.h" -static char *display_name = NULL; +static const char *display_name = NULL; static HANDLE stderr_thread = NULL; static HANDLE stderr_ready; @@ -101,7 +101,7 @@ static DWORD WINAPI service_stderr_thread(LPVOID hPipe) if ((errres = GetLastError()) != ERROR_BROKEN_PIPE) { apr_snprintf(errbuf, sizeof(errbuf), - "Win32 error %d reading stderr pipe stream\r\n", + "Win32 error %lu reading stderr pipe stream\r\n", GetLastError()); ReportEvent(hEventSource, EVENTLOG_ERROR_TYPE, 0, @@ -131,13 +131,11 @@ void mpm_nt_eventlog_stderr_flush(void) } -void mpm_nt_eventlog_stderr_open(char *argv0, apr_pool_t *p) +void mpm_nt_eventlog_stderr_open(const char *argv0, apr_pool_t *p) { SECURITY_ATTRIBUTES sa; - HANDLE hProc = GetCurrentProcess(); HANDLE hPipeRead = NULL; HANDLE hPipeWrite = NULL; - HANDLE hDup = NULL; DWORD threadid; apr_file_t *eventlog_file; apr_file_t *stderr_file; diff --git a/server/mpm/winnt/service.c b/server/mpm/winnt/service.c index 6c5d87b4..aa5291d2 100644 --- a/server/mpm/winnt/service.c +++ b/server/mpm/winnt/service.c @@ -34,6 +34,7 @@ #endif #undef _WINUSER_ #include <winuser.h> +#include <time.h> static char *mpm_service_name = NULL; static char *mpm_display_name = NULL; @@ -52,42 +53,6 @@ static struct static int ReportStatusToSCMgr(int currentState, int exitCode, int waitHint); -#define PRODREGKEY "SOFTWARE\\" AP_SERVER_BASEVENDOR "\\" \ - AP_SERVER_BASEPRODUCT "\\" AP_SERVER_BASEREVISION - -/* - * Get the server root from the registry into 'dir' which is - * size bytes long. Returns 0 if the server root was found - * or if the serverroot key does not exist (in which case - * dir will contain an empty string), or -1 if there was - * an error getting the key. - */ -apr_status_t ap_registry_get_server_root(apr_pool_t *p, char **buf) -{ - apr_status_t rv; - ap_regkey_t *key; - - if ((rv = ap_regkey_open(&key, AP_REGKEY_LOCAL_MACHINE, PRODREGKEY, - APR_READ, p)) == APR_SUCCESS) { - rv = ap_regkey_value_get(buf, key, "ServerRoot", p); - ap_regkey_close(key); - if (rv == APR_SUCCESS) - return rv; - } - - if ((rv = ap_regkey_open(&key, AP_REGKEY_CURRENT_USER, PRODREGKEY, - APR_READ, p)) == APR_SUCCESS) { - rv = ap_regkey_value_get(buf, key, "ServerRoot", p); - ap_regkey_close(key); - if (rv == APR_SUCCESS) - return rv; - } - - *buf = NULL; - return rv; -} - - /* The service configuration's is stored under the following trees: * * HKLM\System\CurrentControlSet\Services\[service name] @@ -157,7 +122,8 @@ void hold_console_open_on_error(void) return; } remains = ((start + 30) - time(NULL)); - sprintf (count, "%d...", remains); + sprintf(count, "%d...", + (int)remains); /* 30 or less, so can't overflow int */ if (!SetConsoleCursorPosition(hConErr, coninfo.dwCursorPosition)) return; if (!WriteConsole(hConErr, count, (DWORD)strlen(count), &result, NULL) @@ -427,7 +393,6 @@ static void set_service_description(void) { const char *full_description; SC_HANDLE schSCManager; - BOOL ret = 0; /* Nothing to do if we are a console */ @@ -565,7 +530,7 @@ static void __stdcall service_nt_main_fn(DWORD argc, LPTSTR *argv) } -DWORD WINAPI service_nt_dispatch_thread(LPVOID nada) +static DWORD WINAPI service_nt_dispatch_thread(LPVOID nada) { apr_status_t rv = APR_SUCCESS; @@ -675,7 +640,7 @@ apr_status_t mpm_merge_service_args(apr_pool_t *p, } -void service_stopped(void) +static void service_stopped(void) { /* Still have a thread & window to clean up, so signal now */ if (globdat.service_thread) @@ -1075,7 +1040,7 @@ apr_status_t mpm_service_start(apr_pool_t *ptemp, int argc, if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT) { - char **start_argv; + CHAR **start_argv; SC_HANDLE schService; SC_HANDLE schSCManager; |
