diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-04-08 15:58:25 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-04-08 15:58:25 +0000 |
commit | fff32326ca9009ebba0aadd24aa0683afe0d4a02 (patch) | |
tree | ac738d570dd46b0ef6b15b09b42d9956245f5005 /src | |
parent | 9a864bd8f87efd0fa23f552d4277475dd76bcea4 (diff) | |
download | nginx-fff32326ca9009ebba0aadd24aa0683afe0d4a02.tar.gz nginx-fff32326ca9009ebba0aadd24aa0683afe0d4a02.zip |
nginx-0.0.3-2004-04-08-19:58:25 import
Diffstat (limited to 'src')
-rw-r--r-- | src/core/ngx_log.h | 37 | ||||
-rw-r--r-- | src/event/modules/ngx_kqueue_module.c | 31 | ||||
-rw-r--r-- | src/event/ngx_event.c | 60 | ||||
-rw-r--r-- | src/event/ngx_event.h | 16 | ||||
-rw-r--r-- | src/event/ngx_event_accept.c | 19 | ||||
-rw-r--r-- | src/http/modules/ngx_http_charset_filter.c | 10 | ||||
-rw-r--r-- | src/http/ngx_http_core_module.c | 8 | ||||
-rw-r--r-- | src/http/ngx_http_request.c | 4 | ||||
-rw-r--r-- | src/http/ngx_http_write_filter.c | 2 |
9 files changed, 145 insertions, 42 deletions
diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h index d1fdab63d..87090dc09 100644 --- a/src/core/ngx_log.h +++ b/src/core/ngx_log.h @@ -6,24 +6,25 @@ #include <ngx_core.h> -#define NGX_LOG_STDERR 0 -#define NGX_LOG_EMERG 1 -#define NGX_LOG_ALERT 2 -#define NGX_LOG_CRIT 3 -#define NGX_LOG_ERR 4 -#define NGX_LOG_WARN 5 -#define NGX_LOG_NOTICE 6 -#define NGX_LOG_INFO 7 -#define NGX_LOG_DEBUG 8 - -#define NGX_LOG_DEBUG_CORE 0x10 -#define NGX_LOG_DEBUG_ALLOC 0x20 -#define NGX_LOG_DEBUG_EVENT 0x40 -#define NGX_LOG_DEBUG_HTTP 0x80 - -#define NGX_LOG_DEBUG_FIRST NGX_LOG_DEBUG_CORE -#define NGX_LOG_DEBUG_LAST NGX_LOG_DEBUG_HTTP -#define NGX_LOG_DEBUG_ALL 0xfffffff0 +#define NGX_LOG_STDERR 0 +#define NGX_LOG_EMERG 1 +#define NGX_LOG_ALERT 2 +#define NGX_LOG_CRIT 3 +#define NGX_LOG_ERR 4 +#define NGX_LOG_WARN 5 +#define NGX_LOG_NOTICE 6 +#define NGX_LOG_INFO 7 +#define NGX_LOG_DEBUG 8 + +#define NGX_LOG_DEBUG_CORE 0x10 +#define NGX_LOG_DEBUG_ALLOC 0x20 +#define NGX_LOG_DEBUG_EVENT 0x40 +#define NGX_LOG_DEBUG_HTTP 0x80 + +#define NGX_LOG_DEBUG_FIRST NGX_LOG_DEBUG_CORE +#define NGX_LOG_DEBUG_LAST NGX_LOG_DEBUG_HTTP +#define NGX_LOG_DEBUG_CONNECTION 0x80000000 +#define NGX_LOG_DEBUG_ALL 0x7ffffff0 /* diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c index c339660db..abc577b1e 100644 --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -22,6 +22,8 @@ static int ngx_kqueue_add_event(ngx_event_t *ev, int event, u_int flags); static int ngx_kqueue_del_event(ngx_event_t *ev, int event, u_int flags); static int ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags); static int ngx_kqueue_process_events(ngx_cycle_t *cycle); +static ngx_inline void ngx_kqueue_dump_event(ngx_log_t *log, + struct kevent *kev); static void *ngx_kqueue_create_conf(ngx_cycle_t *cycle); static char *ngx_kqueue_init_conf(ngx_cycle_t *cycle, void *conf); @@ -443,17 +445,7 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle) for (i = 0; i < events; i++) { - ngx_log_debug6(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - - (event_list[i].ident > 0x8000000 - && event_list[i].ident != (unsigned) -1) ? - "kevent: " PTR_FMT ": ft:%d fl:%04X ff:%08X d:%d ud:" - PTR_FMT: - "kevent: %d: ft:%d fl:%04X ff:%08X d:%d ud:" PTR_FMT, - - event_list[i].ident, event_list[i].filter, - event_list[i].flags, event_list[i].fflags, - event_list[i].data, event_list[i].udata); + ngx_kqueue_dump_event(cycle->log, &event_list[i]); if (event_list[i].flags & EV_ERROR) { ngx_log_error(NGX_LOG_ALERT, cycle->log, event_list[i].data, @@ -472,6 +464,10 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle) ev = (ngx_event_t *) ((uintptr_t) ev & (uintptr_t) ~1); ev->returned_instance = instance; + if (ev->log && (ev->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { + ngx_kqueue_dump_event(ev->log, &event_list[i]); + } + if (!ev->active || ev->instance != instance) { /* @@ -560,6 +556,19 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle) } +static ngx_inline void ngx_kqueue_dump_event(ngx_log_t *log, struct kevent *kev) +{ + ngx_log_debug6(NGX_LOG_DEBUG_EVENT, log, 0, + (kev->ident > 0x8000000 && kev->ident != (unsigned) -1) ? + "kevent: " PTR_FMT ": ft:%d fl:%04X ff:%08X d:%d ud:" + PTR_FMT: + "kevent: %d: ft:%d fl:%04X ff:%08X d:%d ud:" PTR_FMT, + kev->ident, kev->filter, + kev->flags, kev->fflags, + kev->data, kev->udata); +} + + static void *ngx_kqueue_create_conf(ngx_cycle_t *cycle) { ngx_kqueue_conf_t *kcf; diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c index ebb56ce84..c5ea45d2c 100644 --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -35,6 +35,8 @@ static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf); static void *ngx_event_create_conf(ngx_cycle_t *cycle); static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf); @@ -117,6 +119,13 @@ static ngx_command_t ngx_event_core_commands[] = { offsetof(ngx_event_conf_t, accept_mutex_delay), NULL }, + { ngx_string("debug_connection"), + NGX_EVENT_CONF|NGX_CONF_TAKE1, + ngx_event_debug_connection, + 0, + 0, + NULL }, + ngx_null_command }; @@ -517,6 +526,52 @@ static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } +static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf) +{ +#if (NGX_DEBUG) + ngx_event_conf_t *ecf = conf; + + in_addr_t *addr; + ngx_str_t *value; + struct hostent *h; + + value = cf->args->elts; + + /* AF_INET only */ + + if (!(addr = ngx_push_array(&ecf->debug_connection))) { + return NGX_CONF_ERROR; + } + + *addr = inet_addr((char *) value[1].data); + + if (*addr != INADDR_NONE) { + return NGX_OK; + } + + h = gethostbyname((char *) value[1].data); + + if (h == NULL || h->h_addr_list[0] == NULL) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "host %s not found", value[1].data); + return NGX_CONF_ERROR; + } + + *addr = *(in_addr_t *)(h->h_addr_list[0]); + +#else + + ngx_conf_log_error(NGX_LOG_WARN, cf, 0, + "\"debug_connection\" is ignored, you need to rebuild " + "nginx using --with-debug option to enable it"); + +#endif + + return NGX_OK; +} + + static void *ngx_event_create_conf(ngx_cycle_t *cycle) { ngx_event_conf_t *ecf; @@ -531,6 +586,11 @@ static void *ngx_event_create_conf(ngx_cycle_t *cycle) ecf->accept_mutex_delay = NGX_CONF_UNSET_MSEC; ecf->name = (void *) NGX_CONF_UNSET; +#if (NGX_DEBUG) + ngx_init_array(ecf->debug_connection, cycle->pool, 5, sizeof(in_addr_t), + NGX_CONF_ERROR); +#endif + return ecf; } diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h index 1dcfe5066..433d6cffc 100644 --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -381,15 +381,19 @@ extern ngx_event_actions_t ngx_event_actions; typedef struct { - ngx_int_t connections; - ngx_int_t use; + ngx_int_t connections; + ngx_int_t use; - ngx_flag_t multi_accept; - ngx_flag_t accept_mutex; + ngx_flag_t multi_accept; + ngx_flag_t accept_mutex; - ngx_msec_t accept_mutex_delay; + ngx_msec_t accept_mutex_delay; - u_char *name; + u_char *name; + +#if (NGX_DEBUG) + ngx_array_t debug_connection; +#endif } ngx_event_conf_t; diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index c955bbfa3..70db78d71 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -275,6 +275,25 @@ void ngx_event_accept(ngx_event_t *ev) ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, "accept: fd:%d c:%d", s, c->number); +#if (NGX_DEBUG) + { + + uint32_t *addr; + in_addr_t i; + struct sockaddr_in *addr_in; + + addr_in = (struct sockaddr_in *) sa; + addr = ecf->debug_connection.elts; + for (i = 0; i < ecf->debug_connection.nelts; i++) { + if (addr[i] == addr_in->sin_addr.s_addr) { + log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL; + break; + } + } + + } +#endif + if (ngx_add_conn) { if (ngx_add_conn(c) == NGX_ERROR) { if (ngx_close_socket(s) == -1) { diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c index a545eafa1..052a1f822 100644 --- a/src/http/modules/ngx_http_charset_filter.c +++ b/src/http/modules/ngx_http_charset_filter.c @@ -62,6 +62,12 @@ static int ngx_http_charset_header_filter(ngx_http_request_t *r) { ngx_http_charset_loc_conf_t *lcf; + lcf = ngx_http_get_module_loc_conf(r, ngx_http_charset_filter_module); + + if (lcf->default_charset.len == 0) { + return ngx_http_next_header_filter(r); + } + if (r->headers_out.content_type == NULL || ngx_strncasecmp(r->headers_out.content_type->value.data, "text/", 5) != 0 @@ -72,8 +78,6 @@ static int ngx_http_charset_header_filter(ngx_http_request_t *r) return ngx_http_next_header_filter(r); } - lcf = ngx_http_get_module_loc_conf(r, ngx_http_charset_filter_module); - if (r->headers_out.status == NGX_HTTP_MOVED_PERMANENTLY && r->headers_out.status == NGX_HTTP_MOVED_TEMPORARILY) { @@ -135,7 +139,7 @@ static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, ngx_http_charset_loc_conf_t *conf = child; ngx_conf_merge_str_value(conf->default_charset, - prev->default_charset, "koi8-r"); + prev->default_charset, ""); return NGX_CONF_OK; } diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 3ae61829f..6b0db2625 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -482,7 +482,9 @@ int ngx_http_find_location_config(ngx_http_request_t *r) r->loc_conf = clcfp[i]->loc_conf; clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); r->connection->log->file = clcf->err_log->file; - r->connection->log->log_level = clcf->err_log->log_level; + if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { + r->connection->log->log_level = clcf->err_log->log_level; + } if (clcfp[i]->exact_match && r->uri.len == clcfp[i]->name.len) { #if (HAVE_PCRE) @@ -529,7 +531,9 @@ int ngx_http_find_location_config(ngx_http_request_t *r) r->loc_conf = clcfp[i]->loc_conf; clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); r->connection->log->file = clcf->err_log->file; - r->connection->log->log_level = clcf->err_log->log_level; + if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { + r->connection->log->log_level = clcf->err_log->log_level; + } break; } diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index a2a0feda6..9233f89d8 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -231,7 +231,9 @@ static void ngx_http_init_request(ngx_event_t *rev) clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); c->log->file = clcf->err_log->file; - c->log->log_level = clcf->err_log->log_level; + if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { + c->log->log_level = clcf->err_log->log_level; + } if (c->buffer == NULL) { c->buffer = ngx_create_temp_hunk(c->pool, diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c index 5fa144fbc..8c1a98a91 100644 --- a/src/http/ngx_http_write_filter.c +++ b/src/http/ngx_http_write_filter.c @@ -133,7 +133,7 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) * the size of the hunks is smaller than "postpone_output" directive */ - if (!last && flush == 0 && size < conf->postpone_output) { + if (!last && flush == 0 && size < (off_t) conf->postpone_output) { return NGX_OK; } |