diff options
Diffstat (limited to 'src/os/unix')
-rw-r--r-- | src/os/unix/ngx_os.h | 2 | ||||
-rw-r--r-- | src/os/unix/ngx_posix_init.c | 37 | ||||
-rw-r--r-- | src/os/unix/ngx_process.c | 16 | ||||
-rw-r--r-- | src/os/unix/ngx_process.h | 2 |
4 files changed, 43 insertions, 14 deletions
diff --git a/src/os/unix/ngx_os.h b/src/os/unix/ngx_os.h index 8d9a6deed..161661253 100644 --- a/src/os/unix/ngx_os.h +++ b/src/os/unix/ngx_os.h @@ -50,7 +50,9 @@ extern int ngx_inherited_nonblocking; 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_quit; diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c index d5f28d0eb..b23dc3122 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 }, + { SIGINT, "SIGINT", ngx_signal_handler }, + { SIGCHLD, "SIGCHLD", ngx_signal_handler }, { SIGPIPE, "SIGPIPE, SIG_IGN", SIG_IGN }, @@ -93,10 +95,12 @@ void ngx_signal_handler(int signo) { char *action; struct timeval tv; + ngx_int_t ignore; ngx_err_t err; ngx_signal_t *sig; ngx_signal = 1; + ignore = 0; err = ngx_errno; @@ -138,11 +142,31 @@ void ngx_signal_handler(int signo) break; case ngx_signal_value(NGX_REOPEN_SIGNAL): - ngx_reopen = 1; - action = ", reopen logs"; - break; + if (ngx_noaccept) { + action = ", ignoring"; + + } else { + ngx_reopen = 1; + action = ", reopen logs"; + break; + } case ngx_signal_value(NGX_CHANGEBIN_SIGNAL): + if ((ngx_inherited && getppid() > 1) + || (!ngx_inherited && ngx_new_binary > 0)) + { + /* + * Ignore the signal in the new binary if its parent is + * not the init process, i.e. the old binary's process + * is still running. Or ingore the signal in the old binary's + * process if the new binary's process is already running. + */ + + action = ", ignoring"; + ignore = 1; + break; + } + ngx_change_binary = 1; action = ", changing binary"; break; @@ -189,6 +213,13 @@ void ngx_signal_handler(int signo) ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0, "signal %d (%s) received%s", signo, sig->signame, action); + if (ignore) { + ngx_log_error(NGX_LOG_CRIT, ngx_cycle->log, 0, + "the changing binary signal is ignored: " + "you should shutdown or terminate " + "before either old or new binary's process"); + } + if (signo == SIGCHLD) { ngx_process_get_status(); } diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c index 4a802574d..f59138362 100644 --- a/src/os/unix/ngx_process.c +++ b/src/os/unix/ngx_process.c @@ -85,17 +85,10 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle, } -ngx_int_t ngx_exec(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx) +ngx_pid_t ngx_exec(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx) { - if (ngx_spawn_process(cycle, ngx_exec_proc, ctx, ctx->name, - NGX_PROCESS_DETACHED) == NGX_ERROR) - { - ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, - "can not spawn %s", ctx->name); - return NGX_ERROR; - } - - return NGX_OK; + return ngx_spawn_process(cycle, ngx_exec_proc, ctx, ctx->name, + NGX_PROCESS_DETACHED); } @@ -154,6 +147,9 @@ void ngx_respawn_processes(ngx_cycle_t *cycle) ngx_uint_t i; for (i = 0; i < ngx_last_process; i++) { + ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, + "proc table " PID_T_FMT, ngx_processes[i].pid); + if (ngx_processes[i].exiting || !ngx_processes[i].exited) { continue; } diff --git a/src/os/unix/ngx_process.h b/src/os/unix/ngx_process.h index 1eb545bce..5b565091c 100644 --- a/src/os/unix/ngx_process.h +++ b/src/os/unix/ngx_process.h @@ -46,7 +46,7 @@ typedef struct { ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle, ngx_spawn_proc_pt proc, void *data, char *name, ngx_int_t respawn); -ngx_int_t ngx_exec(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx); +ngx_pid_t ngx_exec(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx); void ngx_signal_processes(ngx_cycle_t *cycle, ngx_int_t signo); void ngx_respawn_processes(ngx_cycle_t *cycle); void ngx_process_get_status(void); |