diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-01-13 16:43:23 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-01-13 16:43:23 +0000 |
commit | 49783fc42ec15bfb7c1100be9441e28b0b8f14df (patch) | |
tree | e47cf189eb3893b410bd6b64588e88edc2a82c55 /src | |
parent | 993dc06b4e39daff4650afea5a7c2d11784d1c78 (diff) | |
download | nginx-49783fc42ec15bfb7c1100be9441e28b0b8f14df.tar.gz nginx-49783fc42ec15bfb7c1100be9441e28b0b8f14df.zip |
nginx-0.0.1-2004-01-13-19:43:23 import
Diffstat (limited to 'src')
-rw-r--r-- | src/core/nginx.c | 206 | ||||
-rw-r--r-- | src/core/ngx_config.h | 2 | ||||
-rw-r--r-- | src/os/unix/ngx_os.h | 3 | ||||
-rw-r--r-- | src/os/unix/ngx_posix_init.c | 18 | ||||
-rw-r--r-- | src/os/unix/ngx_process.c | 6 | ||||
-rw-r--r-- | src/os/unix/ngx_process.h | 8 |
6 files changed, 130 insertions, 113 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index 742aeb89c..b3d29d23d 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -76,10 +76,12 @@ u_int ngx_connection_counter; ngx_int_t ngx_process; ngx_int_t ngx_inherited; + +ngx_int_t ngx_signal; ngx_int_t ngx_reap; ngx_int_t ngx_terminate; ngx_int_t ngx_quit; -ngx_int_t ngx_pause; +ngx_int_t ngx_noaccept; ngx_int_t ngx_reconfigure; ngx_int_t ngx_reopen; ngx_int_t ngx_change_binary; @@ -233,7 +235,7 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) int signo; ngx_msec_t delay; struct timeval tv; - ngx_uint_t i, live, first; + ngx_uint_t i, live, mark; sigset_t set, wset; delay = 125; @@ -242,7 +244,7 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) sigaddset(&set, SIGCHLD); sigaddset(&set, ngx_signal_value(NGX_RECONFIGURE_SIGNAL)); sigaddset(&set, ngx_signal_value(NGX_REOPEN_SIGNAL)); - sigaddset(&set, ngx_signal_value(NGX_PAUSE_SIGNAL)); + sigaddset(&set, ngx_signal_value(NGX_NOACCEPT_SIGNAL)); sigaddset(&set, ngx_signal_value(NGX_TERMINATE_SIGNAL)); sigaddset(&set, ngx_signal_value(NGX_SHUTDOWN_SIGNAL)); sigaddset(&set, ngx_signal_value(NGX_CHANGEBIN_SIGNAL)); @@ -254,6 +256,10 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) "sigprocmask() failed"); } + ngx_signal = 0; + signo = 0; + mark = 1; + for ( ;; ) { ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle"); @@ -278,96 +284,99 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) for ( ;; ) { - signo = 0; - first = 1; - /* an event loop */ for ( ;; ) { if (ngx_process == NGX_PROCESS_MASTER) { - sigsuspend(&wset); + if (signo) { + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "signal cycle"); - ngx_gettimeofday(&tv); - ngx_time_update(tv.tv_sec); + if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "sigprocmask() failed"); + continue; + } - } else if (ngx_process == NGX_PROCESS_SINGLE) { - ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "worker cycle"); + /* + * there is very big chance that the pending signals + * would be delivered right on the sigprocmask() return + */ - ngx_process_events(cycle->log); + if (!ngx_signal) { - } else if (ngx_process == NGX_PROCESS_QUITING - || ngx_process == NGX_PROCESS_PAUSED) - { - ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "quit cycle"); + if (delay < 15000) { + delay *= 2; + } - if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - "sigprocmask() failed"); - continue; - } + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "msleep %d", delay); - if (ngx_reap == 0) { + ngx_msleep(delay); - if (delay < 15000) { - delay *= 2; + ngx_gettimeofday(&tv); + ngx_time_update(tv.tv_sec); + + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "wake up"); } - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "msleep %d", delay); + if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "sigprocmask() failed"); + } - ngx_msleep(delay); + ngx_signal = 0; + + } else { + sigsuspend(&wset); 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) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - "sigprocmask() failed"); - } + /* TODO: broken */ + } else if (ngx_process == NGX_PROCESS_SINGLE) { + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "worker cycle"); - if (ngx_reap) { - ngx_reap = 0; + ngx_process_events(cycle->log); + } - live = 0; - for (i = 0; i < ngx_last_process; i++) { - if (ngx_processes[i].exiting - && !ngx_processes[i].exited) - { - live = 1; - continue; - } + if (ngx_reap) { + live = 0; + for (i = 0; i < ngx_last_process; i++) { + if (ngx_processes[i].exiting + && !ngx_processes[i].exited) + { + live = 1; + continue; + } - if (i != --ngx_last_process) { - ngx_processes[i--] = + if (i != --ngx_last_process) { + ngx_processes[i--] = ngx_processes[ngx_last_process]; - } } + } - if (live == 0) { - if (ngx_process == NGX_PROCESS_QUITING) { - if (ngx_delete_file(ctx->pid.name.data) + if (!live) { + if (ngx_terminate || ngx_quit) { + if (ngx_delete_file(ctx->pid.name.data) == NGX_FILE_ERROR) - { - ngx_log_error(NGX_LOG_ALERT, cycle->log, - ngx_errno, - ngx_delete_file_n - " \"%s\" failed", - ctx->pid.name.data); - } - - } else { /* NGX_PROCESS_PAUSED */ - ngx_pause = 0; + { + ngx_log_error(NGX_LOG_ALERT, cycle->log, + ngx_errno, + ngx_delete_file_n + " \"%s\" failed", + ctx->pid.name.data); } ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exit"); exit(0); + + } else { + signo = 0; } } } @@ -378,65 +387,72 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) } else { signo = ngx_signal_value(NGX_TERMINATE_SIGNAL); } - ngx_process = NGX_PROCESS_QUITING; - } - if (ngx_quit) { + } else if (ngx_quit) { signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); - ngx_process = NGX_PROCESS_QUITING; - } - if (ngx_pause) { - signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); - ngx_process = NGX_PROCESS_PAUSED; - } + } else { - if (ngx_reap) { - ngx_reap = 0; - ngx_respawn_processes(cycle); - } + if (ngx_reap) { + ngx_respawn_processes(cycle); + } - if (ngx_change_binary) { - ngx_change_binary = 0; - ngx_log_error(NGX_LOG_INFO, cycle->log, 0, - "changing binary"); - ngx_exec_new_binary(cycle, ctx->argv); - } + if (ngx_noaccept) { + if (mark == 0) { + mark = 1; + } + signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); + } - if (ngx_reconfigure) { - signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); - ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reconfiguring"); - } + if (ngx_change_binary) { + ngx_change_binary = 0; + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, + "changing binary"); + ngx_exec_new_binary(cycle, ctx->argv); + } - if (ngx_reopen) { - signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); - ngx_log_error(NGX_LOG_INFO, cycle->log, 0, - "reopening logs"); - ngx_reopen_files(cycle); - ngx_reopen = 0; + if (ngx_reconfigure) { + mark = 1; + signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, + "reconfiguring"); + } + + if (ngx_reopen) { + mark = 1; + ngx_reopen = 0; + signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, + "reopening logs"); + ngx_reopen_files(cycle); + } } if (signo) { - if (first) { + if (mark == 1) { for (i = 0; i < ngx_last_process; i++) { if (!ngx_processes[i].detached) { ngx_processes[i].signal = 1; } } - first = 0; + mark = -1; delay = 125; } ngx_signal_processes(cycle, signo); } + if (ngx_reap) { + ngx_reap = 0; + } + if (ngx_reconfigure) { break; } } - if (ngx_process == NGX_PROCESS_PAUSED) { - ngx_process = NGX_PROCESS_MASTER; + if (ngx_noaccept) { + ngx_noaccept = 0; } else { cycle = ngx_init_cycle(cycle); diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h index 33cf76921..522c645cf 100644 --- a/src/core/ngx_config.h +++ b/src/core/ngx_config.h @@ -65,7 +65,7 @@ typedef u_int ngx_uint_t; /* TODO: #ifndef */ #define NGX_SHUTDOWN_SIGNAL QUIT #define NGX_TERMINATE_SIGNAL TERM -#define NGX_PAUSE_SIGNAL INT +#define NGX_NOACCEPT_SIGNAL ABRT #define NGX_RECONFIGURE_SIGNAL HUP #define NGX_REOPEN_SIGNAL USR1 #define NGX_CHANGEBIN_SIGNAL USR2 diff --git a/src/os/unix/ngx_os.h b/src/os/unix/ngx_os.h index 4f59137c2..8d9a6deed 100644 --- a/src/os/unix/ngx_os.h +++ b/src/os/unix/ngx_os.h @@ -51,10 +51,11 @@ extern int ngx_inherited_nonblocking; extern ngx_int_t ngx_process; +extern ngx_int_t ngx_signal; extern ngx_int_t ngx_reap; extern ngx_int_t ngx_quit; extern ngx_int_t ngx_terminate; -extern ngx_int_t ngx_pause; +extern ngx_int_t ngx_noaccept; extern ngx_int_t ngx_reconfigure; extern ngx_int_t ngx_reopen; extern ngx_int_t ngx_change_binary; diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c index 374f60b13..d5f28d0eb 100644 --- a/src/os/unix/ngx_posix_init.c +++ b/src/os/unix/ngx_posix_init.c @@ -26,8 +26,8 @@ ngx_signal_t signals[] = { "SIG" ngx_value(NGX_REOPEN_SIGNAL), ngx_signal_handler }, - { ngx_signal_value(NGX_PAUSE_SIGNAL), - "SIG" ngx_value(NGX_PAUSE_SIGNAL), + { ngx_signal_value(NGX_NOACCEPT_SIGNAL), + "SIG" ngx_value(NGX_NOACCEPT_SIGNAL), ngx_signal_handler }, { ngx_signal_value(NGX_TERMINATE_SIGNAL), @@ -96,6 +96,8 @@ void ngx_signal_handler(int signo) ngx_err_t err; ngx_signal_t *sig; + ngx_signal = 1; + err = ngx_errno; for (sig = signals; sig->signo != 0; sig++) { @@ -112,8 +114,6 @@ void ngx_signal_handler(int signo) switch (ngx_process) { case NGX_PROCESS_MASTER: - case NGX_PROCESS_QUITING: - case NGX_PROCESS_PAUSED: switch (signo) { case ngx_signal_value(NGX_SHUTDOWN_SIGNAL): @@ -122,13 +122,14 @@ void ngx_signal_handler(int signo) break; case ngx_signal_value(NGX_TERMINATE_SIGNAL): + case SIGINT: ngx_terminate = 1; action = ", exiting"; break; - case ngx_signal_value(NGX_PAUSE_SIGNAL): - ngx_pause = 1; - action = ", pausing"; + case ngx_signal_value(NGX_NOACCEPT_SIGNAL): + ngx_noaccept = 1; + action = ", stop the accepting connections"; break; case ngx_signal_value(NGX_RECONFIGURE_SIGNAL): @@ -162,6 +163,7 @@ void ngx_signal_handler(int signo) break; case ngx_signal_value(NGX_TERMINATE_SIGNAL): + case SIGINT: ngx_terminate = 1; action = ", exiting"; break; @@ -175,7 +177,7 @@ void ngx_signal_handler(int signo) case ngx_signal_value(NGX_RECONFIGURE_SIGNAL): case ngx_signal_value(NGX_REOPEN_SIGNAL): - case ngx_signal_value(NGX_PAUSE_SIGNAL): + case ngx_signal_value(NGX_NOACCEPT_SIGNAL): case ngx_signal_value(NGX_CHANGEBIN_SIGNAL): action = ", ignoring"; break; diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c index b660d8bec..4a802574d 100644 --- a/src/os/unix/ngx_process.c +++ b/src/os/unix/ngx_process.c @@ -9,7 +9,7 @@ ngx_uint_t ngx_last_process; ngx_process_t ngx_processes[NGX_MAX_PROCESSES]; -ngx_int_t ngx_spawn_process(ngx_cycle_t *cycle, +ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle, ngx_spawn_proc_pt proc, void *data, char *name, ngx_int_t respawn) { @@ -59,7 +59,7 @@ ngx_int_t ngx_spawn_process(ngx_cycle_t *cycle, if (respawn >= 0) { ngx_processes[respawn].pid = pid; ngx_processes[respawn].exited = 0; - return NGX_OK; + return pid; } ngx_processes[ngx_last_process].pid = pid; @@ -81,7 +81,7 @@ ngx_int_t ngx_spawn_process(ngx_cycle_t *cycle, return NGX_ERROR; } - return NGX_OK; + return pid; } diff --git a/src/os/unix/ngx_process.h b/src/os/unix/ngx_process.h index a71f68293..1eb545bce 100644 --- a/src/os/unix/ngx_process.h +++ b/src/os/unix/ngx_process.h @@ -33,19 +33,17 @@ typedef struct { #define NGX_PROCESS_SINGLE 0 #define NGX_PROCESS_MASTER 1 #define NGX_PROCESS_WORKER 2 -#define NGX_PROCESS_QUITING 3 -#define NGX_PROCESS_PAUSED 4 #define NGX_MAX_PROCESSES 1024 -#define NGX_PROCESS_RESPAWN -1 -#define NGX_PROCESS_NORESPAWN -2 +#define NGX_PROCESS_NORESPAWN -1 +#define NGX_PROCESS_RESPAWN -2 #define NGX_PROCESS_DETACHED -3 #define ngx_getpid getpid -ngx_int_t ngx_spawn_process(ngx_cycle_t *cycle, +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); |