diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-06-23 05:54:27 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-06-23 05:54:27 +0000 |
commit | a1796d747c556e0dc8114e4e39aca6e57a8285f9 (patch) | |
tree | f7c020bf3f6b5713143d1732a17e0190659ebc34 /src/os/unix/ngx_process.c | |
parent | 3d5c0fc89e6a5e572e9e3071bd632cbc41b1f8d0 (diff) | |
download | nginx-a1796d747c556e0dc8114e4e39aca6e57a8285f9.tar.gz nginx-a1796d747c556e0dc8114e4e39aca6e57a8285f9.zip |
nginx-0.0.7-2004-06-23-09:54:27 import
Diffstat (limited to 'src/os/unix/ngx_process.c')
-rw-r--r-- | src/os/unix/ngx_process.c | 82 |
1 files changed, 55 insertions, 27 deletions
diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c index d2c1e30a5..799eabee3 100644 --- a/src/os/unix/ngx_process.c +++ b/src/os/unix/ngx_process.c @@ -23,40 +23,55 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle, s = respawn >= 0 ? respawn : ngx_last_process; - /* Solaris 9 still has no AF_LOCAL */ + if (respawn != NGX_PROCESS_DETACHED) { - if (socketpair(AF_UNIX, SOCK_STREAM, 0, ngx_processes[s].channel) == -1) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - "socketpair() failed while spawning \"%s\"", name); - return NGX_ERROR; - } + /* Solaris 9 still has no AF_LOCAL */ - if (ngx_nonblocking(ngx_processes[s].channel[0]) == -1) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - ngx_nonblocking_n " failed while spawning \"%s\"", name); - return NGX_ERROR; - } + if (socketpair(AF_UNIX, SOCK_STREAM, 0, ngx_processes[s].channel) == -1) + { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "socketpair() failed while spawning \"%s\"", name); + return NGX_ERROR; + } - if (ngx_nonblocking(ngx_processes[s].channel[1]) == -1) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - ngx_nonblocking_n " failed while spawning \"%s\"", name); - return NGX_ERROR; - } + if (ngx_nonblocking(ngx_processes[s].channel[0]) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + ngx_nonblocking_n " failed while spawning \"%s\"", + name); + ngx_close_channel(ngx_processes[s].channel, cycle->log); + return NGX_ERROR; + } - on = 1; - if (ioctl(ngx_processes[s].channel[0], FIOASYNC, &on) == -1) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - "ioctl(FIOASYNC) failed while spawning \"%s\"", name); - return NGX_ERROR; - } + if (ngx_nonblocking(ngx_processes[s].channel[1]) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + ngx_nonblocking_n " failed while spawning \"%s\"", + name); + ngx_close_channel(ngx_processes[s].channel, cycle->log); + return NGX_ERROR; + } - if (fcntl(ngx_processes[s].channel[0], F_SETOWN, ngx_pid) == -1) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - "fcntl(F_SETOWN) failed while spawning \"%s\"", name); - return NGX_ERROR; + on = 1; + if (ioctl(ngx_processes[s].channel[0], FIOASYNC, &on) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "ioctl(FIOASYNC) failed while spawning \"%s\"", name); + ngx_close_channel(ngx_processes[s].channel, cycle->log); + return NGX_ERROR; + } + + if (fcntl(ngx_processes[s].channel[0], F_SETOWN, ngx_pid) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "fcntl(F_SETOWN) failed while spawning \"%s\"", name); + ngx_close_channel(ngx_processes[s].channel, cycle->log); + return NGX_ERROR; + } + + ngx_channel = ngx_processes[s].channel[1]; + + } else { + ngx_processes[s].channel[0] = -1; + ngx_processes[s].channel[1] = -1; } - ngx_channel = ngx_processes[s].channel[1]; ngx_process_slot = s; @@ -67,6 +82,7 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle, case -1: ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, "fork() failed while spawning \"%s\"", name); + ngx_close_channel(ngx_processes[s].channel, cycle->log); return NGX_ERROR; case 0: @@ -224,3 +240,15 @@ void ngx_process_get_status() } } } + + +void ngx_close_channel(ngx_fd_t *fd, ngx_log_t *log) +{ + if (close(fd[0]) == -1) { + ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "close() failed"); + } + + if (close(fd[1]) == -1) { + ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "close() failed"); + } +} |