diff options
Diffstat (limited to 'src/os/unix')
-rw-r--r-- | src/os/unix/ngx_os.h | 3 | ||||
-rw-r--r-- | src/os/unix/ngx_posix_init.c | 1 | ||||
-rw-r--r-- | src/os/unix/ngx_process.c | 80 | ||||
-rw-r--r-- | src/os/unix/ngx_process.h | 8 |
4 files changed, 22 insertions, 70 deletions
diff --git a/src/os/unix/ngx_os.h b/src/os/unix/ngx_os.h index ed6b69520..571bef7c3 100644 --- a/src/os/unix/ngx_os.h +++ b/src/os/unix/ngx_os.h @@ -49,8 +49,9 @@ extern int ngx_max_sockets; extern int ngx_inherited_nonblocking; -extern ngx_int_t ngx_master; +extern ngx_int_t ngx_process; +extern ngx_int_t ngx_reap; extern ngx_int_t ngx_quit; extern ngx_int_t ngx_terminate; extern ngx_int_t ngx_reconfigure; diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c index bacd03535..769b1339b 100644 --- a/src/os/unix/ngx_posix_init.c +++ b/src/os/unix/ngx_posix_init.c @@ -120,6 +120,7 @@ void ngx_signal_handler(int signo) switch (signo) { case SIGCHLD: + ngx_reap = 1; ngx_process_get_status(); break; diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c index e9de91e16..4d208c2e4 100644 --- a/src/os/unix/ngx_process.c +++ b/src/os/unix/ngx_process.c @@ -8,14 +8,6 @@ static void ngx_exec_proc(ngx_cycle_t *cycle, void *data); ngx_uint_t ngx_last_process; ngx_process_t ngx_processes[NGX_MAX_PROCESSES]; -sigset_t ngx_sigmask; - - -void ngx_wait_events() -{ - sigsuspend(&ngx_sigmask); -} - ngx_int_t ngx_spawn_process(ngx_cycle_t *cycle, ngx_spawn_proc_pt proc, void *data, @@ -122,17 +114,8 @@ static void ngx_exec_proc(ngx_cycle_t *cycle, void *data) void ngx_signal_processes(ngx_cycle_t *cycle, ngx_int_t signal) { - sigset_t set, oset; ngx_uint_t i; - sigemptyset(&set); - sigaddset(&set, SIGCHLD); - if (sigprocmask(SIG_BLOCK, &set, &oset) == -1) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - "sigprocmask() failed while signaling processes"); - return; - } - for (i = 0; i < ngx_last_process; i++) { if (ngx_processes[i].detached) { @@ -160,61 +143,32 @@ void ngx_signal_processes(ngx_cycle_t *cycle, ngx_int_t signal) ngx_processes[i].exiting = 1; } } - - if (sigprocmask(SIG_SETMASK, &oset, &set) == -1) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - "sigprocmask() failed while signaling processes"); - } } void ngx_respawn_processes(ngx_cycle_t *cycle) { - sigset_t set, oset; ngx_uint_t i; - sigemptyset(&set); - sigaddset(&set, SIGCHLD); - if (sigprocmask(SIG_BLOCK, &set, &oset) == -1) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - "sigprocmask() failed while respawning processes"); - return; - } - - /* - * to avoid a race condition we can check and set value of ngx_respawn - * only in signal handler or while SIGCHLD is blocked - */ - - if (ngx_respawn) { - - for (i = 0; i < ngx_last_process; i++) { - if (!ngx_processes[i].exited) { - continue; - } - - if (!ngx_processes[i].respawn) { - if (i != --ngx_last_process) { - ngx_processes[i--] = ngx_processes[ngx_last_process]; - } - continue; - } + for (i = 0; i < ngx_last_process; i++) { + if (!ngx_processes[i].exited) { + continue; + } - if (ngx_spawn_process(cycle, - ngx_processes[i].proc, ngx_processes[i].data, - ngx_processes[i].name, i) == NGX_ERROR) - { - ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, - "can not respawn %s", ngx_processes[i].name); + if (!ngx_processes[i].respawn) { + if (i != --ngx_last_process) { + ngx_processes[i--] = ngx_processes[ngx_last_process]; } + continue; } - ngx_respawn = 0; - } - - if (sigprocmask(SIG_SETMASK, &oset, &set) == -1) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - "sigprocmask() failed while respawning processes"); + if (ngx_spawn_process(cycle, + ngx_processes[i].proc, ngx_processes[i].data, + ngx_processes[i].name, i) == NGX_ERROR) + { + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, + "can not respawn %s", ngx_processes[i].name); + } } } @@ -261,10 +215,6 @@ void ngx_process_get_status() if (!ngx_processes[i].exiting) { ngx_processes[i].exited = 1; - - if (ngx_processes[i].respawn) { - ngx_respawn = 1; - } } process = ngx_processes[i].name; diff --git a/src/os/unix/ngx_process.h b/src/os/unix/ngx_process.h index c63ff5260..e8a978460 100644 --- a/src/os/unix/ngx_process.h +++ b/src/os/unix/ngx_process.h @@ -29,9 +29,10 @@ typedef struct { } ngx_exec_ctx_t; -#define NGX_PROCESS_SINGLE 0 -#define NGX_PROCESS_MASTER 1 -#define NGX_PROCESS_WORKER 2 +#define NGX_PROCESS_SINGLE 0 +#define NGX_PROCESS_MASTER 1 +#define NGX_PROCESS_WORKER 2 +#define NGX_PROCESS_MASTER_QUIT 3 #define NGX_MAX_PROCESSES 1024 @@ -50,7 +51,6 @@ void ngx_signal_processes(ngx_cycle_t *cycle, ngx_int_t signal); void ngx_respawn_processes(ngx_cycle_t *cycle); void ngx_process_get_status(void); -extern ngx_int_t ngx_respawn; extern ngx_uint_t ngx_last_process; extern ngx_process_t ngx_processes[NGX_MAX_PROCESSES]; |