diff options
author | Graham.Dumpleton <devnull@localhost> | 2009-02-21 10:58:32 +0000 |
---|---|---|
committer | Graham.Dumpleton <devnull@localhost> | 2009-02-21 10:58:32 +0000 |
commit | 2089e6a689d99c9a33f1114a8fe066ee172bc826 (patch) | |
tree | ec0b10e678464f86dbf3fb9532d5397c366ea95e | |
parent | b12b609f89d55bba41e578ab64bfd0ea50d35de4 (diff) | |
download | mod_wsgi-2089e6a689d99c9a33f1114a8fe066ee172bc826.tar.gz |
Reimplement mechanism for detecting signals sent to shutdown daemon mode
processes. This is a back port of fix from mod_wsgi 3.0. See issue #87.
-rw-r--r-- | mod_wsgi.c | 45 |
1 files changed, 27 insertions, 18 deletions
@@ -7657,20 +7657,17 @@ static const char *wsgi_set_accept_mutex(cmd_parms *cmd, void *mconfig, return NULL; } -static void wsgi_signal_handler(int signum) -{ - wsgi_daemon_shutdown++; -} +static apr_file_t *wsgi_signal_pipe_in = NULL; +static apr_file_t *wsgi_signal_pipe_out = NULL; -static int wsgi_check_signal(int signum) +static void wsgi_signal_handler(int signum) { - if (signum == SIGINT || signum == SIGTERM) { - wsgi_daemon_shutdown++; + apr_size_t nbytes = 1; - return 1; - } + apr_file_write(wsgi_signal_pipe_out, "X", &nbytes); + apr_file_flush(wsgi_signal_pipe_out); - return 0; + wsgi_daemon_shutdown++; } static int wsgi_start_process(apr_pool_t *p, WSGIDaemonProcess *daemon); @@ -8420,19 +8417,31 @@ static void wsgi_daemon_main(apr_pool_t *p, WSGIDaemonProcess *daemon) apr_status_t rv; apr_status_t thread_rv; - /* Block all signals from being received. */ + apr_pollfd_t poll_fd; + 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. + */ + + rv = apr_file_pipe_create(&wsgi_signal_pipe_in, &wsgi_signal_pipe_out, p); - rv = apr_setup_signal_thread(); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, WSGI_LOG_EMERG(rv), wsgi_server, "mod_wsgi (pid=%d): Couldn't initialise signal " - "thread in daemon process '%s'.", getpid(), + "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; + /* Initialise maximum request count for daemon. */ if (daemon->group->maximum_requests) @@ -8520,7 +8529,9 @@ static void wsgi_daemon_main(apr_pool_t *p, WSGIDaemonProcess *daemon) /* Block until we get a process shutdown signal. */ - apr_signal_thread(wsgi_check_signal); + do { + rv = apr_poll(&poll_fd, 1, &poll_count, -1); + } while (APR_STATUS_IS_EINTR(rv)); ap_log_error(APLOG_MARK, WSGI_LOG_INFO(0), wsgi_server, "mod_wsgi (pid=%d): Shutdown requested '%s'.", @@ -8744,10 +8755,8 @@ static int wsgi_start_process(apr_pool_t *p, WSGIDaemonProcess *daemon) wsgi_daemon_shutdown = 0; - if (daemon->group->threads == 1) { - apr_signal(SIGINT, wsgi_signal_handler); - apr_signal(SIGTERM, wsgi_signal_handler); - } + apr_signal(SIGINT, wsgi_signal_handler); + apr_signal(SIGTERM, wsgi_signal_handler); /* * Flag whether multiple daemon processes or denoted |