mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 17:52:38 +08:00
nginx-0.0.1-2004-01-14-21:19:42 import
This commit is contained in:
parent
80340f0152
commit
0911f77083
134
src/core/nginx.c
134
src/core/nginx.c
@ -241,7 +241,7 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||||||
char *name;
|
char *name;
|
||||||
sigset_t set, wset;
|
sigset_t set, wset;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
ngx_uint_t i, live, mark;
|
ngx_uint_t i, live, sent;
|
||||||
ngx_msec_t delay;
|
ngx_msec_t delay;
|
||||||
|
|
||||||
delay = 125;
|
delay = 125;
|
||||||
@ -265,7 +265,7 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||||||
ngx_signal = 0;
|
ngx_signal = 0;
|
||||||
ngx_new_binary = 0;
|
ngx_new_binary = 0;
|
||||||
signo = 0;
|
signo = 0;
|
||||||
mark = 1;
|
sent = 0;
|
||||||
|
|
||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle");
|
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle");
|
||||||
@ -273,7 +273,6 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||||||
if (ngx_process == NGX_PROCESS_MASTER) {
|
if (ngx_process == NGX_PROCESS_MASTER) {
|
||||||
ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
|
ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
|
||||||
"worker process", NGX_PROCESS_RESPAWN);
|
"worker process", NGX_PROCESS_RESPAWN);
|
||||||
mark = 1;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ngx_init_temp_number();
|
ngx_init_temp_number();
|
||||||
@ -297,9 +296,9 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
|
|
||||||
if (ngx_process == NGX_PROCESS_MASTER) {
|
if (ngx_process == NGX_PROCESS_MASTER) {
|
||||||
if (signo) {
|
if (sent) {
|
||||||
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||||
"signal cycle: %d, %d", signo, mark);
|
"sent signal cycle");
|
||||||
|
|
||||||
if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1) {
|
if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1) {
|
||||||
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
||||||
@ -364,14 +363,37 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||||||
live = 0;
|
live = 0;
|
||||||
for (i = 0; i < ngx_last_process; i++) {
|
for (i = 0; i < ngx_last_process; i++) {
|
||||||
|
|
||||||
if (ngx_processes[i].exiting
|
ngx_log_debug6(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||||
&& !ngx_processes[i].exited)
|
"child: " PID_T_FMT
|
||||||
{
|
" s:%d e:%d t:%d d:%d r:%d",
|
||||||
live = 1;
|
ngx_processes[i].pid,
|
||||||
continue;
|
ngx_processes[i].signal,
|
||||||
}
|
ngx_processes[i].exiting,
|
||||||
|
ngx_processes[i].exited,
|
||||||
|
ngx_processes[i].detached,
|
||||||
|
ngx_processes[i].respawn);
|
||||||
|
|
||||||
if (ngx_processes[i].exited) {
|
if (ngx_processes[i].exited) {
|
||||||
|
|
||||||
|
if (ngx_processes[i].respawn
|
||||||
|
&& !ngx_processes[i].exiting
|
||||||
|
&& !ngx_terminate
|
||||||
|
&& !ngx_quit)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (ngx_processes[i].pid == ngx_new_binary) {
|
if (ngx_processes[i].pid == ngx_new_binary) {
|
||||||
ngx_new_binary = 0;
|
ngx_new_binary = 0;
|
||||||
}
|
}
|
||||||
@ -380,6 +402,14 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||||||
ngx_processes[i--] =
|
ngx_processes[i--] =
|
||||||
ngx_processes[ngx_last_process];
|
ngx_processes[ngx_last_process];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (!ngx_processes[i].detached
|
||||||
|
&& (ngx_terminate || ngx_quit))
|
||||||
|
{
|
||||||
|
live = 1;
|
||||||
|
|
||||||
|
} else if (ngx_processes[i].exiting) {
|
||||||
|
live = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,8 +434,7 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
signo = 0;
|
sent = 0;
|
||||||
mark = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -415,31 +444,14 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||||||
signo = SIGKILL;
|
signo = SIGKILL;
|
||||||
} else {
|
} else {
|
||||||
signo = ngx_signal_value(NGX_TERMINATE_SIGNAL);
|
signo = ngx_signal_value(NGX_TERMINATE_SIGNAL);
|
||||||
if (mark == 0) {
|
|
||||||
mark = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
|
||||||
"mark: %d", mark);
|
|
||||||
|
|
||||||
} else if (ngx_quit) {
|
} else if (ngx_quit) {
|
||||||
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
||||||
if (mark == 0) {
|
|
||||||
mark = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (ngx_reap) {
|
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
|
||||||
"respawn processes");
|
|
||||||
ngx_respawn_processes(cycle);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ngx_noaccept) {
|
if (ngx_noaccept) {
|
||||||
if (mark == 0) {
|
|
||||||
mark = 1;
|
|
||||||
}
|
|
||||||
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,17 +463,13 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ngx_reconfigure) {
|
if (ngx_reconfigure) {
|
||||||
mark = 1;
|
|
||||||
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
||||||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
|
ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
|
||||||
"reconfiguring");
|
"reconfiguring");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ngx_reopen) {
|
if (ngx_reopen) {
|
||||||
ngx_reopen = 0;
|
|
||||||
|
|
||||||
/* STUB */
|
/* STUB */
|
||||||
mark = 1;
|
|
||||||
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
||||||
|
|
||||||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
|
ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
|
||||||
@ -471,26 +479,49 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (signo) {
|
if (signo) {
|
||||||
if (mark == 1) {
|
for (i = 0; i < ngx_last_process; i++) {
|
||||||
for (i = 0; i < ngx_last_process; i++) {
|
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT,
|
|
||||||
cycle->log, 0,
|
|
||||||
"proc " PID_T_FMT,
|
|
||||||
ngx_processes[i].pid);
|
|
||||||
|
|
||||||
if (!ngx_processes[i].detached) {
|
if (!ngx_processes[i].detached) {
|
||||||
ngx_processes[i].signal = 1;
|
ngx_processes[i].signal = signo;
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT,
|
|
||||||
cycle->log, 0,
|
ngx_log_debug2(NGX_LOG_DEBUG_EVENT,
|
||||||
"mark " PID_T_FMT,
|
cycle->log, 0,
|
||||||
ngx_processes[i].pid);
|
"signal " PID_T_FMT " %d",
|
||||||
}
|
ngx_processes[i].pid, signo);
|
||||||
}
|
}
|
||||||
mark = -1;
|
}
|
||||||
delay = 125;
|
delay = 125;
|
||||||
|
signo = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < ngx_last_process; i++) {
|
||||||
|
|
||||||
|
if (ngx_processes[i].signal == 0) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngx_signal_processes(cycle, signo);
|
sent = 1;
|
||||||
|
|
||||||
|
ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
||||||
|
"kill (" PID_T_FMT ", %d)" ,
|
||||||
|
ngx_processes[i].pid,
|
||||||
|
ngx_processes[i].signal);
|
||||||
|
|
||||||
|
if (kill(ngx_processes[i].pid, ngx_processes[i].signal)
|
||||||
|
== -1)
|
||||||
|
{
|
||||||
|
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
||||||
|
"kill(%d, %d) failed",
|
||||||
|
ngx_processes[i].pid,
|
||||||
|
ngx_processes[i].signal);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ngx_processes[i].signal
|
||||||
|
!= ngx_signal_value(NGX_REOPEN_SIGNAL))
|
||||||
|
{
|
||||||
|
ngx_processes[i].exiting = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ngx_reap) {
|
if (ngx_reap) {
|
||||||
@ -499,6 +530,7 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||||||
|
|
||||||
/* STUB */
|
/* STUB */
|
||||||
if (ngx_reopen) {
|
if (ngx_reopen) {
|
||||||
|
ngx_reopen = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,8 +138,6 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
|
|||||||
NGX_FILE_RDWR,
|
NGX_FILE_RDWR,
|
||||||
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
|
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
|
||||||
|
|
||||||
ngx_log_debug(log, "OPEN: %d:%s" _ file[i].fd _ file[i].name.data);
|
|
||||||
|
|
||||||
if (file[i].fd == NGX_INVALID_FILE) {
|
if (file[i].fd == NGX_INVALID_FILE) {
|
||||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
||||||
ngx_open_file_n " \"%s\" failed",
|
ngx_open_file_n " \"%s\" failed",
|
||||||
@ -156,6 +154,14 @@ ngx_log_debug(log, "OPEN: %d:%s" _ file[i].fd _ file[i].name.data);
|
|||||||
failed = 1;
|
failed = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (fcntl(file[i].fd, F_SETFD, FD_CLOEXEC) == -1) {
|
||||||
|
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
||||||
|
"fcntl(FD_CLOEXEC) \"%s\" failed",
|
||||||
|
file[i].name.data);
|
||||||
|
failed = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -629,6 +635,20 @@ void ngx_reopen_files(ngx_cycle_t *cycle)
|
|||||||
file[i].name.data);
|
file[i].name.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
|
||||||
|
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
||||||
|
"fcntl(FD_CLOEXEC) \"%s\" failed",
|
||||||
|
file[i].name.data);
|
||||||
|
|
||||||
|
if (ngx_close_file(fd) == NGX_FILE_ERROR) {
|
||||||
|
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
||||||
|
ngx_close_file_n " \"%s\" failed",
|
||||||
|
file[i].name.data);
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -276,8 +276,8 @@ ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args)
|
|||||||
ngx_test_null(log, ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)), NULL);
|
ngx_test_null(log, ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)), NULL);
|
||||||
ngx_test_null(log->file, ngx_conf_open_file(cycle, name), NULL);
|
ngx_test_null(log->file, ngx_conf_open_file(cycle, name), NULL);
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
/* STUB */ log->log_level = NGX_LOG_DEBUG;
|
/* STUB */ log->log_level = NGX_LOG_DEBUG | NGX_LOG_DEBUG_CORE | NGX_LOG_DEBUG_ALLOC | NGX_LOG_DEBUG_EVENT | NGX_LOG_DEBUG_HTTP;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return log;
|
return log;
|
||||||
|
@ -374,7 +374,7 @@ static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
|
|
||||||
value = cf->args->elts;
|
value = cf->args->elts;
|
||||||
|
|
||||||
if (cf->cycle->old_cycle) {
|
if (cf->cycle->old_cycle->conf_ctx) {
|
||||||
old_ecf = ngx_event_get_conf(cf->cycle->old_cycle->conf_ctx,
|
old_ecf = ngx_event_get_conf(cf->cycle->old_cycle->conf_ctx,
|
||||||
ngx_event_core_module);
|
ngx_event_core_module);
|
||||||
} else {
|
} else {
|
||||||
|
@ -106,13 +106,15 @@ static void ngx_exec_proc(ngx_cycle_t *cycle, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ngx_signal_processes(ngx_cycle_t *cycle, ngx_int_t signo)
|
#if 0
|
||||||
|
|
||||||
|
void ngx_signal_processes(ngx_cycle_t *cycle)
|
||||||
{
|
{
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
|
|
||||||
for (i = 0; i < ngx_last_process; i++) {
|
for (i = 0; i < ngx_last_process; i++) {
|
||||||
|
|
||||||
if (!ngx_processes[i].signal) {
|
if (ngx_processes[i].signal0 == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,28 +129,29 @@ void ngx_signal_processes(ngx_cycle_t *cycle, ngx_int_t signo)
|
|||||||
|
|
||||||
ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
||||||
"kill (" PID_T_FMT ", %d)" ,
|
"kill (" PID_T_FMT ", %d)" ,
|
||||||
ngx_processes[i].pid, signo);
|
ngx_processes[i].pid, ngx_processes[i].signal0);
|
||||||
|
|
||||||
if (kill(ngx_processes[i].pid, signo) == -1) {
|
if (kill(ngx_processes[i].pid, ngx_processes[i].signal0) == -1) {
|
||||||
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
||||||
"kill(%d, %d) failed", ngx_processes[i].pid, signo);
|
"kill(%d, %d) failed",
|
||||||
|
ngx_processes[i].pid, ngx_processes[i].signal0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL)) {
|
if (ngx_processes[i].signal0 != ngx_signal_value(NGX_REOPEN_SIGNAL)) {
|
||||||
ngx_processes[i].exiting = 1;
|
ngx_processes[i].exiting = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void ngx_respawn_processes(ngx_cycle_t *cycle)
|
void ngx_respawn_processes(ngx_cycle_t *cycle)
|
||||||
{
|
{
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
|
|
||||||
for (i = 0; i < ngx_last_process; 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) {
|
if (ngx_processes[i].exiting || !ngx_processes[i].exited) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -8,6 +8,7 @@ typedef void (*ngx_spawn_proc_pt) (ngx_cycle_t *cycle, void *data);
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ngx_pid_t pid;
|
ngx_pid_t pid;
|
||||||
|
int signal;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
ngx_spawn_proc_pt proc;
|
ngx_spawn_proc_pt proc;
|
||||||
@ -16,7 +17,6 @@ typedef struct {
|
|||||||
|
|
||||||
unsigned respawn:1;
|
unsigned respawn:1;
|
||||||
unsigned detached:1;
|
unsigned detached:1;
|
||||||
unsigned signal:1;
|
|
||||||
unsigned exiting:1;
|
unsigned exiting:1;
|
||||||
unsigned exited:1;
|
unsigned exited:1;
|
||||||
} ngx_process_t;
|
} ngx_process_t;
|
||||||
@ -47,7 +47,6 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle,
|
|||||||
ngx_spawn_proc_pt proc, void *data,
|
ngx_spawn_proc_pt proc, void *data,
|
||||||
char *name, ngx_int_t respawn);
|
char *name, ngx_int_t respawn);
|
||||||
ngx_pid_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_respawn_processes(ngx_cycle_t *cycle);
|
||||||
void ngx_process_get_status(void);
|
void ngx_process_get_status(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user