diff options
Diffstat (limited to 'src/os/unix')
-rw-r--r-- | src/os/unix/ngx_process.c | 28 | ||||
-rw-r--r-- | src/os/unix/ngx_process_cycle.c | 49 |
2 files changed, 53 insertions, 24 deletions
diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c index d6e2d390d..cd160c233 100644 --- a/src/os/unix/ngx_process.c +++ b/src/os/unix/ngx_process.c @@ -20,7 +20,23 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle, ngx_pid_t pid; ngx_int_t s; - s = respawn >= 0 ? respawn : ngx_last_process; + if (respawn >= 0) { + s = respawn; + + } else { + for (s = 0; s < ngx_last_process; s++) { + if (ngx_processes[s].pid == -1) { + break; + } + } + + if (s == NGX_MAX_PROCESSES) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, + "no more than %d processes can be spawned", + NGX_MAX_PROCESSES); + return NGX_ERROR; + } + } if (respawn != NGX_PROCESS_DETACHED) { @@ -146,7 +162,9 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle, break; } - ngx_last_process++; + if (s == ngx_last_process) { + ngx_last_process++; + } return pid; } @@ -220,7 +238,7 @@ void ngx_process_get_status() one = 1; - process = ""; + process = "unknown process"; for (i = 0; i < ngx_last_process; i++) { if (ngx_processes[i].pid == pid) { @@ -231,10 +249,6 @@ void ngx_process_get_status() } } - if (i == ngx_last_process) { - process = "unknown process"; - } - if (WTERMSIG(status)) { ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "%s " PID_T_FMT " exited on signal %d%s", diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c index 83b8da8c2..4ff2bae01 100644 --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -306,11 +306,17 @@ static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, ch.slot = ngx_process_slot; ch.fd = ngx_processes[ngx_process_slot].channel[0]; - for (i = 0; i < ngx_last_process - 1; i++) { + for (i = 0; i < ngx_last_process; i++) { - ngx_log_debug4(NGX_LOG_DEBUG_CORE, cycle->log, 0, - "pass channel s: %d pid:" PID_T_FMT " fd:%d to:" - PID_T_FMT, ch.slot, ch.pid, ch.fd, ngx_processes[i].pid); + if (i == ngx_process_slot || ngx_processes[i].pid == -1) { + continue; + } + + ngx_log_debug5(NGX_LOG_DEBUG_CORE, cycle->log, 0, + "pass channel s:%d pid:" PID_T_FMT + " fd:%d to s:%d pid:" PID_T_FMT, + ch.slot, ch.pid, ch.fd, + i, ngx_processes[i].pid); /* TODO: NGX_AGAIN */ @@ -367,7 +373,7 @@ static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo) for (i = 0; i < ngx_last_process; i++) { - if (ngx_processes[i].detached) { + if (ngx_processes[i].detached || ngx_processes[i].pid == -1) { continue; } @@ -432,8 +438,9 @@ static ngx_uint_t ngx_reap_childs(ngx_cycle_t *cycle) live = 0; for (i = 0; i < ngx_last_process; i++) { - 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_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "child: %d " PID_T_FMT " e:%d t:%d d:%d r:%d j:%d", + i, ngx_processes[i].pid, ngx_processes[i].exiting, ngx_processes[i].exited, @@ -441,6 +448,10 @@ static ngx_uint_t ngx_reap_childs(ngx_cycle_t *cycle) ngx_processes[i].respawn, ngx_processes[i].just_respawn); + if (ngx_processes[i].pid == -1) { + continue; + } + if (ngx_processes[i].exited) { if (!ngx_processes[i].detached) { @@ -454,13 +465,14 @@ static ngx_uint_t ngx_reap_childs(ngx_cycle_t *cycle) for (n = 0; n < ngx_last_process; n++) { if (ngx_processes[n].exited + || ngx_processes[n].pid == -1 || ngx_processes[n].channel[0] == -1) { continue; } ngx_log_debug3(NGX_LOG_DEBUG_CORE, cycle->log, 0, - "pass close channel s: %d pid:" PID_T_FMT + "pass close channel s:%d pid:" PID_T_FMT " to:" PID_T_FMT, ch.slot, ch.pid, ngx_processes[n].pid); /* TODO: NGX_AGAIN */ @@ -498,8 +510,11 @@ static ngx_uint_t ngx_reap_childs(ngx_cycle_t *cycle) } } - if (i != --ngx_last_process) { - ngx_processes[i--] = ngx_processes[ngx_last_process]; + if (i == ngx_last_process - 1) { + ngx_last_process--; + + } else { + ngx_processes[i].pid = -1; } } else if (ngx_processes[i].exiting || !ngx_processes[i].detached) { @@ -593,14 +608,9 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) } } - for (n = 0; n <= ngx_last_process; n++) { - - if (n == ngx_process_slot) { - if (close(ngx_processes[n].channel[0]) == -1) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - "close() failed"); - } + for (n = 0; n < ngx_last_process; n++) { + if (ngx_processes[n].pid == -1) { continue; } @@ -610,6 +620,11 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) } } + if (close(ngx_processes[ngx_process_slot].channel[0]) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "close() failed"); + } + #if 0 ngx_last_process = 0; #endif |