--- server/mpm/worker/worker.c (revision 834394) +++ server/mpm/worker/worker.c (working copy) @@ -237,8 +237,42 @@ * perform a non-graceful (forced) shutdown of the server. */ static apr_socket_t **worker_sockets; +#ifdef HAVE_PTHREAD_KILL + +#define SOCKET_SIGNAL AP_SIG_GRACEFUL_STOP + +static apr_os_thread_t **worker_os_threads; + +static void worker_socket_shutdown(int sig) +{ + int i; + + for (i = 0; i < threads_per_child; i++) { + if (worker_os_threads[i] && + pthread_equal(*worker_os_threads[i], pthread_self())) { + + if (worker_sockets[i]) { + apr_socket_shutdown(worker_sockets[i], + APR_SHUTDOWN_READWRITE); + } + break; + } + } +} + static void close_worker_sockets(void) { + int i; + + for (i = 0; i < threads_per_child; i++) { + if (worker_os_threads[i]) { + pthread_kill(*worker_os_threads[i], SOCKET_SIGNAL); + } + } +} +#else +static void close_worker_sockets(void) +{ int i; for (i = 0; i < threads_per_child; i++) { if (worker_sockets[i]) { @@ -247,6 +281,7 @@ } } } +#endif static void wakeup_listener(void) { @@ -863,6 +898,9 @@ #ifdef HAVE_PTHREAD_KILL unblock_signal(WORKER_SIGNAL); apr_signal(WORKER_SIGNAL, dummy_signal_handler); + + unblock_signal(SOCKET_SIGNAL); + apr_signal(SOCKET_SIGNAL, worker_socket_shutdown); #endif while (!workers_may_exit) { @@ -1003,6 +1041,10 @@ worker_sockets = apr_pcalloc(pchild, threads_per_child * sizeof(apr_socket_t *)); +#ifdef HAVE_PTHREAD_KILL + worker_os_threads = apr_pcalloc(pchild, threads_per_child + * sizeof(*worker_os_threads)); +#endif loops = prev_threads_created = 0; while (1) { @@ -1038,6 +1080,9 @@ /* let the parent decide how bad this really is */ clean_child_exit(APEXIT_CHILDSICK); } +#ifdef HAVE_PTHREAD_KILL + apr_os_thread_get(&worker_os_threads[i], threads[i]); +#endif threads_created++; } /* Start the listener only when there are workers available */