3
0
mirror of https://github.com/nginx/nginx.git synced 2025-01-01 11:46:59 -06:00

nginx-0.0.1-2004-01-13-19:43:23 import

This commit is contained in:
Igor Sysoev 2004-01-13 16:43:23 +00:00
parent 993dc06b4e
commit 49783fc42e
6 changed files with 138 additions and 121 deletions

View File

@ -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;
}
/*
* there is very big chance that the pending signals
* would be delivered right on the sigprocmask() return
*/
if (!ngx_signal) {
if (delay < 15000) {
delay *= 2;
}
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) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"sigprocmask() failed");
}
ngx_signal = 0;
} else {
sigsuspend(&wset);
ngx_gettimeofday(&tv);
ngx_time_update(tv.tv_sec);
}
/* TODO: broken */
} else if (ngx_process == NGX_PROCESS_SINGLE) {
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"worker cycle");
ngx_process_events(cycle->log);
}
} 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 (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"sigprocmask() failed");
continue;
}
if (ngx_reap == 0) {
if (delay < 15000) {
delay *= 2;
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;
}
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) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"sigprocmask() failed");
}
if (ngx_reap) {
ngx_reap = 0;
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);

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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);