From c7a2f6860669f45f5abe342163de5bc68e344816 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Tue, 10 Feb 2004 16:23:38 +0000 Subject: [PATCH] nginx-0.0.2-2004-02-10-19:23:38 import --- auto/configure | 2 +- auto/unix | 6 ++++++ src/core/nginx.c | 12 ++++++++++- src/core/nginx.h | 19 +++++++++--------- src/core/ngx_connection.c | 4 ++-- src/core/ngx_connection.h | 10 ++++++++++ src/event/modules/ngx_epoll_module.c | 5 ++++- src/event/ngx_event.h | 9 --------- src/http/ngx_http_request.c | 6 +++--- src/os/unix/ngx_errno.c | 30 ++++++++++++++++++++++++++++ src/os/unix/ngx_errno.h | 6 +++--- src/os/unix/ngx_freebsd_config.h | 2 ++ src/os/unix/ngx_linux_config.h | 3 ++- src/os/unix/ngx_recv.c | 2 +- src/os/unix/ngx_solaris_config.h | 3 ++- 15 files changed, 87 insertions(+), 32 deletions(-) diff --git a/auto/configure b/auto/configure index 162a69746..f9ad3191c 100755 --- a/auto/configure +++ b/auto/configure @@ -3,7 +3,7 @@ . auto/init . auto/sources -test -d $OBJ || mkdir $OBJ +test -d $OBJS || mkdir $OBJS echo > $NGX_AUTO_CONFIG_H if [ "$PLATFORM" != win32 ]; then diff --git a/auto/unix b/auto/unix index 3aa188303..d6fc3730e 100755 --- a/auto/unix +++ b/auto/unix @@ -98,6 +98,12 @@ ngx_func_test="char buf[20]; int n; n = strerror_r(1, buf, 20)" . auto/func +ngx_func="gnu_strerror_r()" +ngx_func_inc="#include " +ngx_func_test="char buf[20], *str; str = strerror_r(1, buf, 20)" +. auto/func + + ngx_func="localtime_r()" ngx_func_inc="#include " ngx_func_test="struct tm t; time_t c=0; localtime_r(&c, &t)" diff --git a/src/core/nginx.c b/src/core/nginx.c index 34f204f43..005417ced 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -203,6 +203,15 @@ int main(int argc, char *const *argv, char **envp) ccf->pid.data = NGINX_PID; ccf->newpid.len = sizeof(NGINX_NEW_PID) - 1; ccf->newpid.data = NGINX_NEW_PID; + + } else { + ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEW_PID_EXT); + if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) { + return 1; + } + + ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len), + NGINX_NEW_PID_EXT, sizeof(NGINX_NEW_PID_EXT)); } len = ngx_snprintf(pid, /* STUB */ 10, PID_T_FMT, ngx_getpid()); @@ -785,7 +794,7 @@ static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle) } } - if (cycle->conf_file.len == NULL) { + if (cycle->conf_file.data == NULL) { cycle->conf_file.len = sizeof(NGINX_CONF) - 1; cycle->conf_file.data = NGINX_CONF; } @@ -814,6 +823,7 @@ static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle) /* set by pcalloc() * * ccf->pid = NULL; + * ccf->newpid = NULL; */ ccf->daemon = NGX_CONF_UNSET; ccf->master = NGX_CONF_UNSET; diff --git a/src/core/nginx.h b/src/core/nginx.h index 99423d32a..eb7fe93ad 100644 --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -2,19 +2,20 @@ #define _NGINX_H_INCLUDED_ -#define NGINX_VER "nginx/0.0.2" -#define NGINX_CONF "nginx.conf" -#define NGINX_PID "nginx.pid" -#define NGINX_NEW_PID NGINX_PID ".newbin" +#define NGINX_VER "nginx/0.0.2" +#define NGINX_CONF "nginx.conf" +#define NGINX_PID "nginx.pid" +#define NGINX_NEW_PID_EXT ".newbin" +#define NGINX_NEW_PID NGINX_PID NGINX_NEW_PID_EXT -#define NGINX_VAR "NGINX=" -#define NGINX_VAR_LEN (sizeof(NGINX_VAR) - 1) +#define NGINX_VAR "NGINX=" +#define NGINX_VAR_LEN (sizeof(NGINX_VAR) - 1) -extern ngx_module_t ngx_core_module; +extern ngx_module_t ngx_core_module; -extern ngx_uint_t ngx_connection_counter; +extern ngx_uint_t ngx_connection_counter; -extern ngx_int_t ngx_process; +extern ngx_int_t ngx_process; #endif /* _NGINX_H_INCLUDED_ */ diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index e0b24fa63..115748432 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -243,14 +243,14 @@ ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text) ngx_int_t level; if (err == NGX_ECONNRESET - && c->read->log_error == NGX_ERROR_IGNORE_ECONNRESET) + && c->log_error == NGX_ERROR_IGNORE_ECONNRESET) { return 0; } if (err == NGX_ECONNRESET || err == NGX_EPIPE || err == NGX_ENOTCONN) { - switch (c->read->log_error) { + switch (c->log_error) { case NGX_ERROR_INFO: level = NGX_LOG_INFO; diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h index 6f87fd2d8..835f5e1cb 100644 --- a/src/core/ngx_connection.h +++ b/src/core/ngx_connection.h @@ -52,6 +52,14 @@ typedef struct { } ngx_listening_t; +typedef enum { + NGX_ERROR_CRIT = 0, + NGX_ERROR_ERR, + NGX_ERROR_INFO, + NGX_ERROR_IGNORE_ECONNRESET +} ngx_connection_log_error_e; + + struct ngx_connection_s { void *data; ngx_event_t *read; @@ -84,6 +92,8 @@ struct ngx_connection_s { ngx_int_t number; + unsigned log_error:2; /* ngx_connection_log_error_e */ + unsigned pipeline:1; unsigned unexpected_eof:1; signed tcp_nopush:2; diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c index 3f46a83ad..111432b91 100644 --- a/src/event/modules/ngx_epoll_module.c +++ b/src/event/modules/ngx_epoll_module.c @@ -132,12 +132,15 @@ ngx_module_t ngx_epoll_module = { static int ngx_epoll_init(ngx_cycle_t *cycle) { size_t n; + ngx_event_conf_t *ecf; ngx_epoll_conf_t *epcf; + ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); + epcf = ngx_event_get_conf(cycle->conf_ctx, ngx_epoll_module); if (ep == -1) { - ep = epoll_create(/* STUB: open_files / 2 */ 512); + ep = epoll_create(ecf->connections / 2); if (ep == -1) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h index 68d9f8199..a2c1e9cb6 100644 --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -20,14 +20,6 @@ typedef struct { #endif -typedef enum { - NGX_ERROR_CRIT = 0, - NGX_ERROR_ERR, - NGX_ERROR_INFO, - NGX_ERROR_IGNORE_ECONNRESET -} ngx_event_log_error_e; - - struct ngx_event_s { void *data; /* TODO rename to handler */ @@ -88,7 +80,6 @@ struct ngx_event_s { unsigned short read_discarded:1; - unsigned short log_error:2; /* ngx_event_log_error_e */ unsigned short unexpected_eof:1; unsigned short deferred_accept:1; diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index 8d20a31d5..ff53a7ba6 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -79,10 +79,10 @@ void ngx_http_init_connection(ngx_connection_t *c) ctx->action = "reading client request line"; c->log->data = ctx; c->log->handler = ngx_http_log_error; + c->log_error = NGX_ERROR_INFO; rev = c->read; rev->event_handler = ngx_http_init_request; - rev->log_error = NGX_ERROR_INFO; /* STUB: epoll */ c->write->event_handler = ngx_http_empty_handler; @@ -1272,10 +1272,10 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev) * so we ignore ECONNRESET here. */ - rev->log_error = NGX_ERROR_IGNORE_ECONNRESET; + c->log_error = NGX_ERROR_IGNORE_ECONNRESET; ngx_set_socket_errno(0); n = ngx_recv(c, c->buffer->last, c->buffer->end - c->buffer->last); - rev->log_error = NGX_ERROR_INFO; + c->log_error = NGX_ERROR_INFO; if (n == NGX_AGAIN) { return; diff --git a/src/os/unix/ngx_errno.c b/src/os/unix/ngx_errno.c index c50da8251..410cfde5c 100644 --- a/src/os/unix/ngx_errno.c +++ b/src/os/unix/ngx_errno.c @@ -25,4 +25,34 @@ ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size) return len; } +#elif (HAVE_GNU_STRERROR_R) + +/* Linux strerror_r() */ + +ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size) +{ + char *str; + size_t len; + + if (size == 0) { + return 0; + } + + errstr[0] = '\0'; + + str = strerror_r(err, errstr, size); + + if (str != errstr) { + return ngx_cpystrn(errstr, str, size) - errstr; + } + + for (len = 0; len < size; len++) { + if (errstr[len] == '\0') { + break; + } + } + + return len; +} + #endif diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h index 208faa244..7ead602f7 100644 --- a/src/os/unix/ngx_errno.h +++ b/src/os/unix/ngx_errno.h @@ -2,8 +2,8 @@ #define _NGX_ERRNO_H_INCLUDED_ -#include -#include +#include +#include typedef int ngx_err_t; @@ -34,7 +34,7 @@ typedef int ngx_err_t; #define ngx_set_socket_errno(err) errno = err -#if (HAVE_STRERROR_R) +#if (HAVE_STRERROR_R || HAVE_GNU_STRERROR_R) ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size); diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h index 2e14831ea..3d53d2026 100644 --- a/src/os/unix/ngx_freebsd_config.h +++ b/src/os/unix/ngx_freebsd_config.h @@ -7,7 +7,9 @@ #include #include #include +#include #include +#include #include #include #include diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h index fca68f622..76b0dd04c 100644 --- a/src/os/unix/ngx_linux_config.h +++ b/src/os/unix/ngx_linux_config.h @@ -13,10 +13,11 @@ #include #include #include +#include #include +#include #include #include -#include #include #include #include diff --git a/src/os/unix/ngx_recv.c b/src/os/unix/ngx_recv.c index 60e2d099f..3c454e98c 100644 --- a/src/os/unix/ngx_recv.c +++ b/src/os/unix/ngx_recv.c @@ -32,7 +32,7 @@ ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size) ngx_set_socket_errno(rev->kq_errno); if (rev->kq_errno == NGX_ECONNRESET - && rev->log_error == NGX_ERROR_IGNORE_ECONNRESET) + && c->log_error == NGX_ERROR_IGNORE_ECONNRESET) { return 0; } diff --git a/src/os/unix/ngx_solaris_config.h b/src/os/unix/ngx_solaris_config.h index 920aaf904..f4f8df2af 100644 --- a/src/os/unix/ngx_solaris_config.h +++ b/src/os/unix/ngx_solaris_config.h @@ -14,9 +14,10 @@ #include #include #include +#include #include +#include #include -#include #include #include #include