diff options
author | Igor Sysoev <igor@sysoev.ru> | 2003-05-21 13:28:21 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2003-05-21 13:28:21 +0000 |
commit | fa73aac7747c9d0a8575eb2beffcdab50171e006 (patch) | |
tree | d1e354f2e321b8f1c4e5518984759bab1ae05ddd /src/os/unix/ngx_posix_init.c | |
parent | 1c13c662f0ae8066d1d4849b4158d7459a4c7822 (diff) | |
download | nginx-fa73aac7747c9d0a8575eb2beffcdab50171e006.tar.gz nginx-fa73aac7747c9d0a8575eb2beffcdab50171e006.zip |
nginx-0.0.1-2003-05-21-17:28:21 import
Diffstat (limited to 'src/os/unix/ngx_posix_init.c')
-rw-r--r-- | src/os/unix/ngx_posix_init.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c new file mode 100644 index 000000000..aadb64c2d --- /dev/null +++ b/src/os/unix/ngx_posix_init.c @@ -0,0 +1,70 @@ + +#include <ngx_config.h> +#include <ngx_core.h> + + +int ngx_max_sockets; +int ngx_inherited_nonblocking; + + +int ngx_posix_init(ngx_log_t *log) +{ + struct sigaction sa; + struct rlimit rlmt; + + ngx_memzero(&sa, sizeof(struct sigaction)); + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + + if (sigaction(SIGPIPE, &sa, NULL) == -1) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, + "sigaction(SIGPIPE, SIG_IGN) failed"); + return NGX_ERROR; + } + + + if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) { + ngx_log_error(NGX_LOG_ALERT, log, errno, + "getrlimit(RLIMIT_NOFILE) failed)"); + return NGX_ERROR; + } + + ngx_log_error(NGX_LOG_INFO, log, 0, + "getrlimit(RLIMIT_NOFILE): %qd:%qd", + rlmt.rlim_cur, rlmt.rlim_max); + + ngx_max_sockets = rlmt.rlim_cur; + +#if (HAVE_INHERITED_NONBLOCK) + ngx_inherited_nonblocking = 1; +#else + ngx_inherited_nonblocking = 0; +#endif + + return NGX_OK; +} + + +int ngx_posix_post_conf_init(ngx_log_t *log) +{ + ngx_fd_t pp[2]; + + if (pipe(pp) == -1) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "pipe() failed"); + return NGX_ERROR; + } + + if (dup2(pp[1], STDERR_FILENO) == -1) { + ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDERR) failed"); + return NGX_ERROR; + } + + if (pp[1] > STDERR_FILENO) { + if (close(pp[1]) == -1) { + ngx_log_error(NGX_LOG_EMERG, log, errno, "close() failed"); + return NGX_ERROR; + } + } + + return NGX_OK; +} |