From 3867e2c18d79d2ea83ed48606dde0364c08ef7f4 Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Sun, 15 Apr 2012 15:05:42 +1000 Subject: Fix bug where signal pipe not setup before signal handlers created. --- mod_wsgi.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/mod_wsgi.c b/mod_wsgi.c index 62e9b1a..3257e85 100644 --- a/mod_wsgi.c +++ b/mod_wsgi.c @@ -10755,23 +10755,10 @@ static void wsgi_daemon_main(apr_pool_t *p, WSGIDaemonProcess *daemon) apr_int32_t poll_count = 0; /* - * Create pipe by which signal handler can notify the main - * thread that signal has arrived indicating that process - * needs to shutdown. + * Setup poll object for listening for shutdown notice from + * signal handler. */ - rv = apr_file_pipe_create(&wsgi_signal_pipe_in, &wsgi_signal_pipe_out, p); - - if (rv != APR_SUCCESS) { - ap_log_error(APLOG_MARK, WSGI_LOG_EMERG(rv), wsgi_server, - "mod_wsgi (pid=%d): Couldn't initialise signal " - "pipe in daemon process '%s'.", getpid(), - daemon->group->name); - sleep(20); - - return; - } - poll_fd.desc_type = APR_POLL_FILE; poll_fd.reqevents = APR_POLLIN; poll_fd.desc.f = wsgi_signal_pipe_in; @@ -11174,9 +11161,25 @@ static int wsgi_start_process(apr_pool_t *p, WSGIDaemonProcess *daemon) /* * Register signal handler to receive shutdown signal - * from Apache parent process. + * from Apache parent process. We need to first create + * pipe by which signal handler can notify the main + * thread that signal has arrived indicating that + * process needs to shutdown. */ + status = apr_file_pipe_create(&wsgi_signal_pipe_in, + &wsgi_signal_pipe_out, p); + + if (status != APR_SUCCESS) { + ap_log_error(APLOG_MARK, WSGI_LOG_EMERG(status), wsgi_server, + "mod_wsgi (pid=%d): Couldn't initialise signal " + "pipe in daemon process '%s'.", getpid(), + daemon->group->name); + sleep(20); + + exit(-1); + } + wsgi_daemon_shutdown = 0; apr_signal(SIGINT, wsgi_signal_handler); -- cgit v1.2.1