mirror of
https://github.com/nginx/nginx.git
synced 2024-12-20 06:03:31 -06:00
nginx-0.0.3-2004-04-16-09:14:16 import
This commit is contained in:
parent
68df19d33a
commit
630ad0c7b1
@ -77,8 +77,6 @@ ngx_pid_t ngx_pid;
|
||||
ngx_pid_t ngx_new_binary;
|
||||
ngx_int_t ngx_inherited;
|
||||
|
||||
ngx_uint_t ngx_test_config;
|
||||
|
||||
|
||||
int main(int argc, char *const *argv)
|
||||
{
|
||||
@ -146,6 +144,7 @@ int main(int argc, char *const *argv)
|
||||
}
|
||||
|
||||
if (ngx_test_config) {
|
||||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "config syntax is ok");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -181,7 +180,12 @@ int main(int argc, char *const *argv)
|
||||
|
||||
#endif
|
||||
|
||||
ngx_master_process_cycle(cycle, &ctx);
|
||||
if (ngx_process == NGX_PROCESS_MASTER) {
|
||||
ngx_master_process_cycle(cycle, &ctx);
|
||||
|
||||
} else {
|
||||
ngx_single_process_cycle(cycle, &ctx);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ ngx_array_t ngx_old_cycles;
|
||||
static ngx_pool_t *ngx_temp_pool;
|
||||
static ngx_event_t ngx_cleaner_event;
|
||||
|
||||
ngx_uint_t ngx_test_config;
|
||||
|
||||
|
||||
/* STUB NAME */
|
||||
static ngx_connection_t dumb;
|
||||
@ -263,7 +265,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
|
||||
}
|
||||
}
|
||||
|
||||
if (!failed) {
|
||||
if (!ngx_test_config && !failed) {
|
||||
if (ngx_open_listening_sockets(cycle) == NGX_ERROR) {
|
||||
failed = 1;
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv);
|
||||
extern volatile ngx_cycle_t *ngx_cycle;
|
||||
extern ngx_array_t ngx_old_cycles;
|
||||
extern ngx_module_t ngx_core_module;
|
||||
extern ngx_uint_t ngx_test_config;
|
||||
|
||||
|
||||
#endif /* _NGX_CYCLE_H_INCLUDED_ */
|
||||
|
@ -333,7 +333,8 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"devpoll expired timer");
|
||||
|
||||
ngx_event_expire_timers(ngx_elapsed_msec - ngx_old_elapsed_msec);
|
||||
ngx_event_expire_timers((ngx_msec_t)
|
||||
(ngx_elapsed_msec - ngx_old_elapsed_msec));
|
||||
}
|
||||
|
||||
/* NGX_TIMER_INFINITE == INFTIM */
|
||||
|
@ -363,7 +363,8 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"epoll expired timer");
|
||||
|
||||
ngx_event_expire_timers(ngx_elapsed_msec - ngx_old_elapsed_msec);
|
||||
ngx_event_expire_timers((ngx_msec_t)
|
||||
(ngx_elapsed_msec - ngx_old_elapsed_msec));
|
||||
}
|
||||
|
||||
/* NGX_TIMER_INFINITE == INFTIM */
|
||||
|
@ -376,7 +376,8 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle)
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"kevent expired timer");
|
||||
|
||||
ngx_event_expire_timers(ngx_elapsed_msec - ngx_old_elapsed_msec);
|
||||
ngx_event_expire_timers((ngx_msec_t)
|
||||
(ngx_elapsed_msec - ngx_old_elapsed_msec));
|
||||
|
||||
/* TODO: if ngx_threaded then wake up the worker thread */
|
||||
}
|
||||
|
@ -287,7 +287,8 @@ int ngx_poll_process_events(ngx_cycle_t *cycle)
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"poll expired timer");
|
||||
|
||||
ngx_event_expire_timers(ngx_elapsed_msec - ngx_old_elapsed_msec);
|
||||
ngx_event_expire_timers((ngx_msec_t)
|
||||
(ngx_elapsed_msec - ngx_old_elapsed_msec));
|
||||
}
|
||||
|
||||
/* NGX_TIMER_INFINITE == INFTIM */
|
||||
|
@ -214,7 +214,8 @@ int ngx_rtsig_process_events(ngx_cycle_t *cycle)
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"rtsig expired timer");
|
||||
|
||||
ngx_event_expire_timers(ngx_elapsed_msec - ngx_old_elapsed_msec);
|
||||
ngx_event_expire_timers((ngx_msec_t)
|
||||
(ngx_elapsed_msec - ngx_old_elapsed_msec));
|
||||
}
|
||||
|
||||
expire = 1;
|
||||
|
@ -273,7 +273,8 @@ static int ngx_select_process_events(ngx_cycle_t *cycle)
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"select expired timer");
|
||||
|
||||
ngx_event_expire_timers(ngx_elapsed_msec - ngx_old_elapsed_msec);
|
||||
ngx_event_expire_timers((ngx_msec_t)
|
||||
(ngx_elapsed_msec - ngx_old_elapsed_msec));
|
||||
}
|
||||
|
||||
ngx_old_elapsed_msec = ngx_elapsed_msec;
|
||||
|
@ -1260,7 +1260,7 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
|
||||
if (prev->err_log) {
|
||||
conf->err_log = prev->err_log;
|
||||
} else {
|
||||
conf->err_log = cf->cycle->log;
|
||||
conf->err_log = cf->cycle->new_log;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,12 +49,30 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle,
|
||||
ngx_processes[ngx_last_process].proc = proc;
|
||||
ngx_processes[ngx_last_process].data = data;
|
||||
ngx_processes[ngx_last_process].name = name;
|
||||
ngx_processes[ngx_last_process].respawn =
|
||||
(respawn == NGX_PROCESS_RESPAWN) ? 1 : 0;
|
||||
ngx_processes[ngx_last_process].detached =
|
||||
(respawn == NGX_PROCESS_DETACHED) ? 1 : 0;
|
||||
ngx_processes[ngx_last_process].exited = 0;
|
||||
ngx_processes[ngx_last_process].exiting = 0;
|
||||
|
||||
switch (respawn) {
|
||||
|
||||
case NGX_PROCESS_RESPAWN:
|
||||
ngx_processes[ngx_last_process].respawn = 1;
|
||||
ngx_processes[ngx_last_process].just_respawn = 0;
|
||||
ngx_processes[ngx_last_process].detached = 0;
|
||||
break;
|
||||
|
||||
case NGX_PROCESS_JUST_RESPAWN:
|
||||
ngx_processes[ngx_last_process].respawn = 1;
|
||||
ngx_processes[ngx_last_process].just_respawn = 1;
|
||||
ngx_processes[ngx_last_process].detached = 0;
|
||||
break;
|
||||
|
||||
case NGX_PROCESS_DETACHED:
|
||||
ngx_processes[ngx_last_process].respawn = 0;
|
||||
ngx_processes[ngx_last_process].just_respawn = 0;
|
||||
ngx_processes[ngx_last_process].detached = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
ngx_last_process++;
|
||||
|
||||
return pid;
|
||||
@ -82,34 +100,6 @@ static void ngx_execute_proc(ngx_cycle_t *cycle, void *data)
|
||||
}
|
||||
|
||||
|
||||
void ngx_respawn_processes(ngx_cycle_t *cycle)
|
||||
{
|
||||
ngx_uint_t i;
|
||||
|
||||
for (i = 0; i < ngx_last_process; i++) {
|
||||
|
||||
if (ngx_processes[i].exiting || !ngx_processes[i].exited) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ngx_processes[i].respawn) {
|
||||
if (i != --ngx_last_process) {
|
||||
ngx_processes[i--] = ngx_processes[ngx_last_process];
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ngx_process_get_status()
|
||||
{
|
||||
int status;
|
||||
|
@ -15,6 +15,7 @@ typedef struct {
|
||||
char *name;
|
||||
|
||||
unsigned respawn:1;
|
||||
unsigned just_respawn:1;
|
||||
unsigned detached:1;
|
||||
unsigned exiting:1;
|
||||
unsigned exited:1;
|
||||
@ -29,11 +30,12 @@ typedef struct {
|
||||
} ngx_exec_ctx_t;
|
||||
|
||||
|
||||
#define NGX_MAX_PROCESSES 1024
|
||||
#define NGX_MAX_PROCESSES 1024
|
||||
|
||||
#define NGX_PROCESS_NORESPAWN -1
|
||||
#define NGX_PROCESS_RESPAWN -2
|
||||
#define NGX_PROCESS_DETACHED -3
|
||||
#define NGX_PROCESS_NORESPAWN -1
|
||||
#define NGX_PROCESS_RESPAWN -2
|
||||
#define NGX_PROCESS_JUST_RESPAWN -3
|
||||
#define NGX_PROCESS_DETACHED -4
|
||||
|
||||
|
||||
#define ngx_getpid getpid
|
||||
@ -43,7 +45,6 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle,
|
||||
ngx_spawn_proc_pt proc, void *data,
|
||||
char *name, ngx_int_t respawn);
|
||||
ngx_pid_t ngx_execute(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx);
|
||||
void ngx_respawn_processes(ngx_cycle_t *cycle);
|
||||
void ngx_process_get_status(void);
|
||||
|
||||
extern ngx_pid_t ngx_pid;
|
||||
|
@ -6,7 +6,9 @@
|
||||
#include <nginx.h>
|
||||
|
||||
|
||||
static void ngx_start_worker_processes(ngx_cycle_y *cycle, ngx_int_t n)
|
||||
static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
|
||||
ngx_int_t type);
|
||||
static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo);
|
||||
static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx);
|
||||
static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
|
||||
#if (NGX_THREADS)
|
||||
@ -36,11 +38,11 @@ ngx_uint_t ngx_restart;
|
||||
|
||||
void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
||||
{
|
||||
int signo;
|
||||
ngx_uint_t i;
|
||||
sigset_t set;
|
||||
struct timeval tv;
|
||||
struct itimerval itv;
|
||||
ngx_uint_t i, live;
|
||||
ngx_uint_t live;
|
||||
ngx_msec_t delay;
|
||||
ngx_core_conf_t *ccf;
|
||||
|
||||
@ -66,11 +68,11 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
||||
|
||||
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
|
||||
|
||||
ngx_start_worker_processes(ccf->worker_processes);
|
||||
ngx_start_worker_processes(cycle, ccf->worker_processes,
|
||||
NGX_PROCESS_RESPAWN);
|
||||
|
||||
ngx_new_binary = 0;
|
||||
delay = 0;
|
||||
signo = 0;
|
||||
live = 1;
|
||||
|
||||
for ( ;; ) {
|
||||
@ -107,13 +109,14 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
||||
live = 0;
|
||||
for (i = 0; i < ngx_last_process; i++) {
|
||||
|
||||
ngx_log_debug5(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"child: " PID_T_FMT " e:%d t:%d d:%d r:%d",
|
||||
ngx_log_debug6(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"child: " PID_T_FMT " e:%d t:%d d:%d r:%d j:%d",
|
||||
ngx_processes[i].pid,
|
||||
ngx_processes[i].exiting,
|
||||
ngx_processes[i].exited,
|
||||
ngx_processes[i].detached,
|
||||
ngx_processes[i].respawn);
|
||||
ngx_processes[i].respawn,
|
||||
ngx_processes[i].just_respawn);
|
||||
|
||||
if (ngx_processes[i].exited) {
|
||||
|
||||
@ -168,19 +171,32 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
||||
}
|
||||
|
||||
if (delay > 1000) {
|
||||
signo = SIGKILL;
|
||||
ngx_signal_worker_processes(cycle, SIGKILL);
|
||||
} else {
|
||||
signo = ngx_signal_value(NGX_TERMINATE_SIGNAL);
|
||||
ngx_signal_worker_processes(cycle,
|
||||
ngx_signal_value(NGX_TERMINATE_SIGNAL));
|
||||
}
|
||||
|
||||
} else if (ngx_quit) {
|
||||
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
||||
continue;
|
||||
}
|
||||
|
||||
} else if (ngx_timer) {
|
||||
ngx_start_worker_processes(ccf->worker_processes);
|
||||
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
||||
if (ngx_quit) {
|
||||
ngx_signal_worker_processes(cycle,
|
||||
ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
|
||||
continue;
|
||||
}
|
||||
|
||||
} else if (ngx_reconfigure) {
|
||||
if (ngx_timer) {
|
||||
ngx_timer = 0;
|
||||
ngx_start_worker_processes(cycle, ccf->worker_processes,
|
||||
NGX_PROCESS_JUST_RESPAWN);
|
||||
live = 1;
|
||||
ngx_signal_worker_processes(cycle,
|
||||
ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
|
||||
}
|
||||
|
||||
if (ngx_reconfigure) {
|
||||
ngx_reconfigure = 0;
|
||||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reconfiguring");
|
||||
|
||||
cycle = ngx_init_cycle(cycle);
|
||||
@ -192,381 +208,94 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
||||
ngx_cycle = cycle;
|
||||
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
|
||||
ngx_core_module);
|
||||
ngx_start_worker_processes(ccf->worker_processes);
|
||||
ngx_start_worker_processes(cycle, ccf->worker_processes,
|
||||
NGX_PROCESS_JUST_RESPAWN);
|
||||
live = 1;
|
||||
ngx_signal_worker_processes(cycle,
|
||||
ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
|
||||
}
|
||||
|
||||
ngx_reconfigure = 0;
|
||||
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
||||
|
||||
} else if (ngx_restart) {
|
||||
ngx_start_worker_processes(ccf->worker_processes);
|
||||
if (ngx_restart) {
|
||||
ngx_restart = 0;
|
||||
|
||||
} else if (ngx_reopen) {
|
||||
if (ngx_process == NGX_PROCESS_MASTER) {
|
||||
signo = ngx_signal_value(NGX_REOPEN_SIGNAL);
|
||||
ngx_reopen = 0;
|
||||
|
||||
} else { /* NGX_PROCESS_SINGLE */
|
||||
ngx_reopen = 0;
|
||||
}
|
||||
|
||||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
|
||||
"reopening logs");
|
||||
ngx_reopen_files(cycle, ccf->user);
|
||||
|
||||
} else if (ngx_change_binary) {
|
||||
ngx_change_binary = 0;
|
||||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
|
||||
"changing binary");
|
||||
ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv);
|
||||
|
||||
} else if (ngx_noaccept) {
|
||||
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
||||
}
|
||||
ngx_start_worker_processes(cycle, ccf->worker_processes,
|
||||
NGX_PROCESS_RESPAWN);
|
||||
live = 1;
|
||||
}
|
||||
|
||||
if (signo) {
|
||||
for (i = 0; i < ngx_last_process; i++) {
|
||||
|
||||
if (ngx_processes[i].detached) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
||||
"kill (" PID_T_FMT ", %d)" ,
|
||||
ngx_processes[i].pid, signo);
|
||||
|
||||
if (kill(ngx_processes[i].pid, signo) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
||||
"kill(%d, %d) failed",
|
||||
ngx_processes[i].pid, signo);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL)) {
|
||||
ngx_processes[i].exiting = 1;
|
||||
}
|
||||
}
|
||||
|
||||
signo = 0;
|
||||
if (ngx_reopen) {
|
||||
ngx_reopen = 0;
|
||||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reopening logs");
|
||||
ngx_reopen_files(cycle, ccf->user);
|
||||
ngx_signal_worker_processes(cycle,
|
||||
ngx_signal_value(NGX_REOPEN_SIGNAL));
|
||||
}
|
||||
|
||||
if (ngx_change_binary) {
|
||||
ngx_change_binary = 0;
|
||||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "changing binary");
|
||||
ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (ngx_noaccept) {
|
||||
ngx_noaccept = 0;
|
||||
ngx_noaccepting = 1;
|
||||
ngx_signal_worker_processes(cycle,
|
||||
ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
||||
void ngx_single_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
||||
{
|
||||
int signo;
|
||||
sigset_t set;
|
||||
struct timeval tv;
|
||||
struct itimerval itv;
|
||||
ngx_uint_t i, live;
|
||||
ngx_msec_t delay;
|
||||
ngx_core_conf_t *ccf;
|
||||
ngx_uint_t i;
|
||||
|
||||
if (ngx_process == NGX_PROCESS_MASTER) {
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGCHLD);
|
||||
sigaddset(&set, SIGALRM);
|
||||
sigaddset(&set, SIGINT);
|
||||
sigaddset(&set, ngx_signal_value(NGX_RECONFIGURE_SIGNAL));
|
||||
sigaddset(&set, ngx_signal_value(NGX_REOPEN_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));
|
||||
ngx_setproctitle("single worker process");
|
||||
|
||||
if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
||||
"sigprocmask() failed");
|
||||
ngx_init_temp_number();
|
||||
|
||||
for (i = 0; ngx_modules[i]; i++) {
|
||||
if (ngx_modules[i]->init_process) {
|
||||
if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) {
|
||||
/* fatal */
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
sigemptyset(&set);
|
||||
}
|
||||
|
||||
ngx_setproctitle("master process");
|
||||
|
||||
ngx_new_binary = 0;
|
||||
delay = 0;
|
||||
signo = 0;
|
||||
live = 0;
|
||||
|
||||
for ( ;; ) {
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle");
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
|
||||
|
||||
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
|
||||
ngx_core_module);
|
||||
ngx_process_events(cycle);
|
||||
|
||||
if (ngx_process == NGX_PROCESS_MASTER) {
|
||||
for (i = 0; i < (ngx_uint_t) ccf->worker_processes; i++) {
|
||||
ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
|
||||
"worker process", NGX_PROCESS_RESPAWN);
|
||||
}
|
||||
|
||||
/*
|
||||
* we have to limit the maximum life time of the worker processes
|
||||
* by 10 days because our millisecond event timer is limited
|
||||
* by 24 days on 32-bit platforms
|
||||
*/
|
||||
|
||||
itv.it_interval.tv_sec = 0;
|
||||
itv.it_interval.tv_usec = 0;
|
||||
itv.it_value.tv_sec = 10 * 24 * 60 * 60;
|
||||
itv.it_value.tv_usec = 0;
|
||||
|
||||
if (setitimer(ITIMER_REAL, &itv, NULL) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
||||
"setitimer() failed");
|
||||
}
|
||||
|
||||
live = 1;
|
||||
|
||||
} else {
|
||||
ngx_init_temp_number();
|
||||
|
||||
for (i = 0; ngx_modules[i]; i++) {
|
||||
if (ngx_modules[i]->init_process) {
|
||||
if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) {
|
||||
/* fatal */
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ngx_terminate || ngx_quit) {
|
||||
ngx_master_exit(cycle, ctx);
|
||||
}
|
||||
|
||||
if (ngx_reconfigure) {
|
||||
ngx_reconfigure = 0;
|
||||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reconfiguring");
|
||||
|
||||
/* a cycle with the same configuration because a new one is invalid */
|
||||
|
||||
for ( ;; ) {
|
||||
|
||||
/* an event loop */
|
||||
|
||||
for ( ;; ) {
|
||||
|
||||
if (ngx_process == NGX_PROCESS_MASTER) {
|
||||
if (delay) {
|
||||
delay *= 2;
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"temination cycle: %d", delay);
|
||||
|
||||
itv.it_interval.tv_sec = 0;
|
||||
itv.it_interval.tv_usec = 0;
|
||||
itv.it_value.tv_sec = delay / 1000;
|
||||
itv.it_value.tv_usec = (delay % 1000 ) * 1000;
|
||||
|
||||
if (setitimer(ITIMER_REAL, &itv, NULL) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
||||
"setitimer() failed");
|
||||
}
|
||||
}
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"sigsuspend");
|
||||
|
||||
sigsuspend(&set);
|
||||
|
||||
ngx_gettimeofday(&tv);
|
||||
ngx_time_update(tv.tv_sec);
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"wake up");
|
||||
|
||||
} else { /* NGX_PROCESS_SINGLE */
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"worker cycle");
|
||||
|
||||
ngx_process_events(cycle);
|
||||
live = 0;
|
||||
}
|
||||
|
||||
if (ngx_reap) {
|
||||
ngx_reap = 0;
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"reap childs");
|
||||
|
||||
live = 0;
|
||||
for (i = 0; i < ngx_last_process; i++) {
|
||||
|
||||
ngx_log_debug5(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||
"child: " PID_T_FMT
|
||||
" e:%d t:%d d:%d r:%d",
|
||||
ngx_processes[i].pid,
|
||||
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].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;
|
||||
}
|
||||
|
||||
live = 1;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_processes[i].pid == ngx_new_binary) {
|
||||
ngx_new_binary = 0;
|
||||
|
||||
/* TODO: if (ngx_noaccept) ngx_configure = 1 */
|
||||
}
|
||||
|
||||
if (i != --ngx_last_process) {
|
||||
ngx_processes[i--] =
|
||||
ngx_processes[ngx_last_process];
|
||||
}
|
||||
|
||||
} else if (ngx_processes[i].exiting
|
||||
|| !ngx_processes[i].detached)
|
||||
{
|
||||
live = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!live && (ngx_terminate || ngx_quit)) {
|
||||
ngx_master_exit(cycle, ctx);
|
||||
}
|
||||
|
||||
if (ngx_terminate) {
|
||||
if (delay == 0) {
|
||||
delay = 50;
|
||||
}
|
||||
|
||||
if (delay > 1000) {
|
||||
signo = SIGKILL;
|
||||
} else {
|
||||
signo = ngx_signal_value(NGX_TERMINATE_SIGNAL);
|
||||
}
|
||||
|
||||
} else if (ngx_quit) {
|
||||
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
||||
|
||||
} else if (ngx_timer) {
|
||||
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
||||
|
||||
} else if (ngx_reconfigure) {
|
||||
ngx_reconfigure = 0;
|
||||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reconfiguring");
|
||||
|
||||
cycle = ngx_init_cycle(cycle);
|
||||
if (cycle == NULL) {
|
||||
cycle = (ngx_cycle_t *) ngx_cycle;
|
||||
continue;
|
||||
}
|
||||
|
||||
ngx_cycle = cycle;
|
||||
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
||||
|
||||
} else if (ngx_reopen) {
|
||||
if (ngx_process == NGX_PROCESS_MASTER) {
|
||||
signo = ngx_signal_value(NGX_REOPEN_SIGNAL);
|
||||
ngx_reopen = 0;
|
||||
|
||||
} else { /* NGX_PROCESS_SINGLE */
|
||||
ngx_reopen = 0;
|
||||
}
|
||||
|
||||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
|
||||
"reopening logs");
|
||||
ngx_reopen_files(cycle, ccf->user);
|
||||
|
||||
} else if (ngx_change_binary) {
|
||||
ngx_change_binary = 0;
|
||||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
|
||||
"changing binary");
|
||||
ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv);
|
||||
|
||||
} else if (ngx_noaccept) {
|
||||
signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
|
||||
}
|
||||
}
|
||||
|
||||
if (signo) {
|
||||
for (i = 0; i < ngx_last_process; i++) {
|
||||
|
||||
if (ngx_processes[i].detached) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
||||
"kill (" PID_T_FMT ", %d)" ,
|
||||
ngx_processes[i].pid, signo);
|
||||
|
||||
if (kill(ngx_processes[i].pid, signo) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
||||
"kill(%d, %d) failed",
|
||||
ngx_processes[i].pid, signo);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL)) {
|
||||
ngx_processes[i].exiting = 1;
|
||||
}
|
||||
}
|
||||
|
||||
signo = 0;
|
||||
}
|
||||
|
||||
if (ngx_reopen || ngx_reconfigure || ngx_timer) {
|
||||
break;
|
||||
}
|
||||
cycle = ngx_init_cycle(cycle);
|
||||
if (cycle == NULL) {
|
||||
cycle = (ngx_cycle_t *) ngx_cycle;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_reopen) {
|
||||
ngx_reopen = 0;
|
||||
ngx_cycle = cycle;
|
||||
}
|
||||
|
||||
} else if (ngx_timer) {
|
||||
ngx_timer = 0;
|
||||
|
||||
} else if (ngx_noaccept) {
|
||||
ngx_noaccept = 0;
|
||||
ngx_reconfigure = 0;
|
||||
|
||||
} else {
|
||||
cycle = ngx_init_cycle(cycle);
|
||||
if (cycle == NULL) {
|
||||
cycle = (ngx_cycle_t *) ngx_cycle;
|
||||
continue;
|
||||
}
|
||||
|
||||
ngx_cycle = cycle;
|
||||
ngx_reconfigure = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
if (ngx_reopen) {
|
||||
ngx_reopen = 0;
|
||||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reopening logs");
|
||||
ngx_reopen_files(cycle, (ngx_uid_t) -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void ngx_start_worker_processes(ngx_cycle_y *cycle, ngx_int_t n)
|
||||
static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
|
||||
ngx_int_t type)
|
||||
{
|
||||
struct itimerval itv;
|
||||
|
||||
@ -574,7 +303,7 @@ static void ngx_start_worker_processes(ngx_cycle_y *cycle, ngx_int_t n)
|
||||
|
||||
while (n--) {
|
||||
ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
|
||||
"worker process", NGX_PROCESS_RESPAWN);
|
||||
"worker process", type);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -594,6 +323,44 @@ static void ngx_start_worker_processes(ngx_cycle_y *cycle, ngx_int_t n)
|
||||
}
|
||||
}
|
||||
|
||||
static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo)
|
||||
{
|
||||
ngx_uint_t i;
|
||||
|
||||
for (i = 0; i < ngx_last_process; i++) {
|
||||
|
||||
if (ngx_processes[i].detached) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_processes[i].just_respawn) {
|
||||
ngx_processes[i].just_respawn = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_processes[i].exiting
|
||||
&& signo == ngx_signal_value(NGX_SHUTDOWN_SIGNAL))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
||||
"kill (" PID_T_FMT ", %d)" ,
|
||||
ngx_processes[i].pid, signo);
|
||||
|
||||
if (kill(ngx_processes[i].pid, signo) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
||||
"kill(%d, %d) failed",
|
||||
ngx_processes[i].pid, signo);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL)) {
|
||||
ngx_processes[i].exiting = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ typedef struct {
|
||||
|
||||
|
||||
void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx);
|
||||
void ngx_single_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx);
|
||||
|
||||
|
||||
extern ngx_int_t ngx_process;
|
||||
|
@ -33,6 +33,12 @@ sig_atomic_t ngx_change_binary;
|
||||
|
||||
|
||||
void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
||||
{
|
||||
exit(2);
|
||||
}
|
||||
|
||||
|
||||
void ngx_single_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
||||
{
|
||||
ngx_int_t i;
|
||||
|
||||
|
@ -20,6 +20,7 @@ typedef struct {
|
||||
|
||||
|
||||
void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx);
|
||||
void ngx_single_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx);
|
||||
|
||||
|
||||
extern ngx_int_t ngx_process;
|
||||
|
Loading…
Reference in New Issue
Block a user