aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/nginx.c105
-rw-r--r--src/event/modules/ngx_devpoll_module.c2
-rw-r--r--src/http/modules/ngx_http_gzip_filter.c6
-rw-r--r--src/http/modules/ngx_http_ssi_filter.c2
-rw-r--r--src/os/unix/ngx_os.h2
-rw-r--r--src/os/unix/ngx_posix_init.c11
6 files changed, 68 insertions, 60 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 4ed865606..b436dd45a 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -85,8 +85,8 @@ ngx_int_t ngx_process;
ngx_pid_t ngx_new_binary;
ngx_int_t ngx_inherited;
-ngx_int_t ngx_signal;
ngx_int_t ngx_reap;
+ngx_int_t ngx_timer;
ngx_int_t ngx_terminate;
ngx_int_t ngx_quit;
ngx_int_t ngx_noaccept;
@@ -229,16 +229,18 @@ int main(int argc, char *const *argv, char **envp)
static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
{
- int signo;
- char *name;
- sigset_t set, wset;
- struct timeval tv;
- ngx_uint_t i, live;
- ngx_msec_t delay;
- ngx_core_conf_t *ccf;
+ int signo;
+ sigset_t set;
+ struct timeval tv;
+ struct itimerval itv;
+ ngx_uint_t i, live;
+ ngx_msec_t delay;
+ ngx_core_conf_t *ccf;
sigemptyset(&set);
sigaddset(&set, SIGCHLD);
+ sigaddset(&set, SIGALRM);
+ sigaddset(&set, SIGINT);
sigaddset(&set, ngx_signal_value(NGX_RECONFIGURE_SIGNAL));
sigaddset(&set, ngx_signal_value(NGX_REOPEN_SIGNAL));
sigaddset(&set, ngx_signal_value(NGX_NOACCEPT_SIGNAL));
@@ -246,16 +248,15 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
sigaddset(&set, ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
sigaddset(&set, ngx_signal_value(NGX_CHANGEBIN_SIGNAL));
- sigemptyset(&wset);
-
if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"sigprocmask() failed");
}
+ sigemptyset(&set);
+
ngx_setproctitle("master process");
- ngx_signal = 0;
ngx_new_binary = 0;
delay = 0;
signo = 0;
@@ -267,6 +268,23 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
if (ngx_process == NGX_PROCESS_MASTER) {
ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
"worker process", NGX_PROCESS_RESPAWN);
+
+ /*
+ * we have to limit the maximum life time of the worker processes
+ * by 1 month because our millisecond event timer is limited
+ * by 49 days on 32-bit platforms
+ */
+
+ itv.it_interval.tv_sec = 0;
+ itv.it_interval.tv_usec = 0;
+ itv.it_value.tv_sec = 30 * 24 * 60 * 60;
+ itv.it_value.tv_usec = 0;
+
+ if (setitimer(ITIMER_REAL, &itv, NULL) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ "setitimer() failed");
+ }
+
live = 1;
} else {
@@ -295,55 +313,32 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
if (ngx_process == NGX_PROCESS_MASTER) {
if (delay) {
- ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "temination cycle");
-
- if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1) {
- ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
- "sigprocmask() failed");
- continue;
- }
-
- /*
- * there is very big chance that the pending signals
- * would be delivered right on the sigprocmask() return
- */
+ delay *= 2;
- if (!ngx_signal) {
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
+ "temination cycle: %d", delay);
- delay *= 2;
+ itv.it_interval.tv_sec = 0;
+ itv.it_interval.tv_usec = 0;
+ itv.it_value.tv_sec = delay / 1000;
+ itv.it_value.tv_usec = (delay % 1000 ) * 1000;
- ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "msleep %d", delay);
-
- ngx_msleep(delay);
-
- ngx_gettimeofday(&tv);
- ngx_time_update(tv.tv_sec);
-
- ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "wake up");
- }
-
- if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
+ if (setitimer(ITIMER_REAL, &itv, NULL) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
- "sigprocmask() failed");
+ "setitimer() failed");
}
+ }
- ngx_signal = 0;
-
- } else {
- ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "sigsuspend");
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
+ "sigsuspend");
- sigsuspend(&wset);
+ sigsuspend(&set);
- ngx_gettimeofday(&tv);
- ngx_time_update(tv.tv_sec);
+ ngx_gettimeofday(&tv);
+ ngx_time_update(tv.tv_sec);
- ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "wake up");
- }
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
+ "wake up");
} else { /* NGX_PROCESS_SINGLE */
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
@@ -430,6 +425,9 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
} else if (ngx_quit) {
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
+ } else if (ngx_timer) {
+ signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
+
} else {
if (ngx_noaccept) {
@@ -512,7 +510,7 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
}
}
- if (ngx_reopen || ngx_reconfigure) {
+ if (ngx_reopen || ngx_reconfigure || ngx_timer) {
break;
}
}
@@ -520,6 +518,9 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
if (ngx_reopen) {
ngx_reopen = 0;
+ } else if (ngx_timer) {
+ ngx_timer = 0;
+
} else if (ngx_noaccept) {
ngx_noaccept = 0;
ngx_reconfigure = 0;
diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c
index 583d08c6b..c8217de58 100644
--- a/src/event/modules/ngx_devpoll_module.c
+++ b/src/event/modules/ngx_devpoll_module.c
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2002-2003 Igor Sysoev, http://sysoev.ru
+ * Copyright (C) 2002-2004 Igor Sysoev, http://sysoev.ru/en/
*/
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c
index c5e68c9a5..fae9c9edb 100644
--- a/src/http/modules/ngx_http_gzip_filter.c
+++ b/src/http/modules/ngx_http_gzip_filter.c
@@ -240,11 +240,9 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_http_gzip_ctx_t *ctx;
ngx_http_gzip_conf_t *conf;
- if (!(ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module))) {
- return ngx_http_next_body_filter(r, in);
- }
+ ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module);
- if (ctx->done) {
+ if (ctx == NULL || ctx->done) {
return ngx_http_next_body_filter(r, in);
}
diff --git a/src/http/modules/ngx_http_ssi_filter.c b/src/http/modules/ngx_http_ssi_filter.c
index b6dc637ac..56070d11f 100644
--- a/src/http/modules/ngx_http_ssi_filter.c
+++ b/src/http/modules/ngx_http_ssi_filter.c
@@ -193,7 +193,7 @@ static int ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module);
if (ctx == NULL || (in == NULL && ctx->in == NULL)) {
- return ngx_http_next_body_filter(r, NULL);
+ return ngx_http_next_body_filter(r, in);
}
/* add the incoming hunk to the chain ctx->in */
diff --git a/src/os/unix/ngx_os.h b/src/os/unix/ngx_os.h
index 161661253..90d253912 100644
--- a/src/os/unix/ngx_os.h
+++ b/src/os/unix/ngx_os.h
@@ -53,8 +53,8 @@ extern ngx_int_t ngx_process;
extern ngx_pid_t ngx_new_binary;
extern ngx_int_t ngx_inherited;
-extern ngx_int_t ngx_signal;
extern ngx_int_t ngx_reap;
+extern ngx_int_t ngx_timer;
extern ngx_int_t ngx_quit;
extern ngx_int_t ngx_terminate;
extern ngx_int_t ngx_noaccept;
diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c
index 84c9c519b..b76a9af75 100644
--- a/src/os/unix/ngx_posix_init.c
+++ b/src/os/unix/ngx_posix_init.c
@@ -42,6 +42,8 @@ ngx_signal_t signals[] = {
"SIG" ngx_value(NGX_CHANGEBIN_SIGNAL),
ngx_signal_handler },
+ { SIGALRM, "SIGALRM", ngx_signal_handler },
+
{ SIGINT, "SIGINT", ngx_signal_handler },
{ SIGCHLD, "SIGCHLD", ngx_signal_handler },
@@ -99,7 +101,6 @@ void ngx_signal_handler(int signo)
ngx_err_t err;
ngx_signal_t *sig;
- ngx_signal = 1;
ignore = 0;
err = ngx_errno;
@@ -172,6 +173,14 @@ void ngx_signal_handler(int signo)
action = ", changing binary";
break;
+ case SIGALRM:
+ if (!ngx_terminate) {
+ ngx_timer = 1;
+ action = ", shutting down old worker process";
+ }
+
+ break;
+
case SIGCHLD:
ngx_reap = 1;
break;