diff options
author | Igor Sysoev <igor@sysoev.ru> | 2003-12-14 23:10:27 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2003-12-14 23:10:27 +0300 |
commit | dc867cd0fed793f86ce2b460f8c2ad069ddec1b5 (patch) | |
tree | 507db64a0a152c9ec99785a3ea887154ec4873b3 /src | |
parent | 2b58fbf045acee349c323de8f50501f94c41c04d (diff) |
nginx-0.0.1-2003-12-14-23:10:27 import
Diffstat (limited to 'src')
-rw-r--r-- | src/core/nginx.c | 52 | ||||
-rw-r--r-- | src/core/nginx.h | 1 | ||||
-rw-r--r-- | src/core/ngx_config.h | 4 | ||||
-rw-r--r-- | src/core/ngx_log.c | 7 | ||||
-rw-r--r-- | src/core/ngx_log.h | 36 | ||||
-rw-r--r-- | src/event/modules/ngx_kqueue_module.c | 65 | ||||
-rw-r--r-- | src/event/ngx_event_timer.c | 288 | ||||
-rw-r--r-- | src/event/ngx_event_timer.h | 49 | ||||
-rw-r--r-- | src/http/ngx_http_core_module.c | 45 | ||||
-rw-r--r-- | src/http/ngx_http_core_module.h | 2 | ||||
-rw-r--r-- | src/http/ngx_http_header_filter.c | 2 | ||||
-rw-r--r-- | src/http/ngx_http_log_handler.c | 16 | ||||
-rw-r--r-- | src/http/ngx_http_parse.c | 6 | ||||
-rw-r--r-- | src/http/ngx_http_request.c | 65 | ||||
-rw-r--r-- | src/http/ngx_http_request.h | 2 | ||||
-rw-r--r-- | src/os/unix/ngx_errno.c | 24 | ||||
-rw-r--r-- | src/os/unix/ngx_errno.h | 11 | ||||
-rw-r--r-- | src/os/unix/ngx_os.h | 1 | ||||
-rw-r--r-- | src/os/unix/ngx_posix_init.c | 134 | ||||
-rw-r--r-- | src/os/win32/ngx_time.c | 2 | ||||
-rw-r--r-- | src/os/win32/ngx_win32_init.c | 14 |
21 files changed, 388 insertions, 438 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index e02866e53..36a8b4bd8 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -16,7 +16,8 @@ static void ngx_clean_old_cycles(ngx_event_t *ev); typedef struct { - int daemon; + int daemon; + ngx_str_t pid; } ngx_core_conf_t; @@ -61,6 +62,7 @@ static ngx_connection_t dumb; u_int ngx_connection_counter; +int done; int restart; int rotate; @@ -73,6 +75,9 @@ int main(int argc, char *const *argv) ngx_cycle_t *cycle; ngx_open_file_t *file; #if !(WIN32) + size_t len; + char pid[/* STUB */ 10]; + ngx_file_t pidfile; ngx_core_conf_t *ccf; #endif @@ -119,6 +124,33 @@ int main(int argc, char *const *argv) return 1; } + if (ccf->pid.len == 0) { + ccf->pid.len = sizeof(NGINX_PID) - 1; + ccf->pid.data = NGINX_PID; + } + + len = ngx_snprintf(pid, /* STUB */ 10, PID_T_FMT, ngx_getpid()); + ngx_memzero(&pidfile, sizeof(ngx_file_t)); + pidfile.name = ccf->pid; + + pidfile.fd = ngx_open_file(pidfile.name.data, NGX_FILE_RDWR, + NGX_FILE_CREATE_OR_OPEN); + + if (pidfile.fd == NGX_INVALID_FILE) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, + ngx_open_file_n " \"%s\" failed", pidfile.name.data); + return 1; + } + + if (ngx_write_file(&pidfile, pid, len, 0) == NGX_ERROR) { + return 1; + } + + if (ngx_close_file(pidfile.fd) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + ngx_close_file_n " \"%s\" failed", pidfile.name.data); + } + #endif /* life cycle */ @@ -162,8 +194,20 @@ int main(int argc, char *const *argv) ngx_process_events(cycle->log); + if (done) { + if (ngx_delete_file(pidfile.name.data) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + ngx_delete_file_n " \"%s\" failed", + pidfile.name.data); + } + + ngx_log_error(NGX_LOG_INFO, + cycle->log, 0, "exiting"); + exit(0); + } + if (rotate) { - ngx_log_debug(cycle->log, "rotate"); + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "rotating logs"); file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { @@ -313,6 +357,10 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log) ngx_destroy_pool(pool); return NULL; } + /* set by pcalloc() + * + * ccf->pid = NULL; + */ ccf->daemon = -1; ((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf; diff --git a/src/core/nginx.h b/src/core/nginx.h index 6a9fd493b..38942aa25 100644 --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -4,6 +4,7 @@ #define NGINX_VER "nginx/0.0.1" #define NGINX_CONF "nginx.conf" +#define NGINX_PID "nginx.pid" extern int ngx_max_module; diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h index b943960b2..bf393f6ab 100644 --- a/src/core/ngx_config.h +++ b/src/core/ngx_config.h @@ -39,7 +39,7 @@ typedef int ngx_int_t; typedef u_int ngx_uint_t; /* STUB: autoconf */ -#define PTR_FMT "%X" +#define PTR_FMT "%08X" #include <ngx_auto_config.h> @@ -60,6 +60,8 @@ typedef u_int ngx_uint_t; /* TODO: #ifndef */ #define NGX_RESTART_SIGNAL HUP #define NGX_ROTATE_SIGNAL USR1 +#define NGX_SHUTDOWN_SIGNAL TERM +#define NGX_INTERRUPT_SIGNAL INT #endif diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c index fede0a079..98b71c8d3 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -82,13 +82,6 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err, len = ngx_cached_err_log_time.len; -#if 0 - ngx_localtime(&tm); - len = ngx_snprintf(errstr, sizeof(errstr), "%4d/%02d/%02d %02d:%02d:%02d", - tm.ngx_tm_year, tm.ngx_tm_mon, tm.ngx_tm_mday, - tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec); -#endif - len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1, " [%s] ", err_levels[level]); diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h index 71da9d524..c3771d74a 100644 --- a/src/core/ngx_log.h +++ b/src/core/ngx_log.h @@ -190,6 +190,24 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...); #define ngx_log_debug1(level, log, err, fmt, arg1) #endif +#if (NGX_DEBUG) +#define ngx_log_debug2(level, log, err, fmt, arg1, arg2) \ + if (log->log_level & level) \ + ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, arg1, arg2) +#else +#define ngx_log_debug2(level, log, err, fmt, arg1, arg2) +#endif + +#if (NGX_DEBUG) +#define ngx_log_debug6(level, log, err, fmt, \ + arg1, arg2, arg3, arg4, arg5, arg6) \ + if (log->log_level & level) \ + ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, \ + arg1, arg2, arg3, arg4, arg5, arg6) +#else +#define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6) +#endif + /*********************************/ #else /* NO VARIADIC MACROS */ @@ -209,6 +227,24 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...); #else #define ngx_log_debug1(level, log, err, fmt, arg1) #endif + +#if (NGX_DEBUG) +#define ngx_log_debug2(level, log, err, fmt, arg1, arg2) \ + if (log->log_level & level) \ + ngx_log_debug_core(log, err, fmt, arg1, arg2) +#else +#define ngx_log_debug2(level, log, err, fmt, arg1, arg2) +#endif + +#if (NGX_DEBUG) +#define ngx_log_debug6(level, log, err, fmt, \ + arg1, arg2, arg3, arg4, arg5, arg6) \ + if (log->log_level & level) \ + ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6) +#else +#define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6) +#endif + #endif diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c index d36160ab1..0ddf4f67e 100644 --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -419,23 +419,17 @@ static int ngx_kqueue_process_events(ngx_log_t *log) for (i = 0; i < events; i++) { -#if (NGX_DEBUG_EVENT) - if (event_list[i].ident > 0x8000000 - && event_list[i].ident != (unsigned) -1) - { - ngx_log_debug(log, - "kevent: %08x: ft:%d fl:%08x ff:%08x d:%d ud:%08x" _ - event_list[i].ident _ event_list[i].filter _ - event_list[i].flags _ event_list[i].fflags _ - event_list[i].data _ event_list[i].udata); - } else { - ngx_log_debug(log, - "kevent: %d: ft:%d fl:%08x ff:%08x d:%d ud:%08x" _ - event_list[i].ident _ event_list[i].filter _ - event_list[i].flags _ event_list[i].fflags _ - event_list[i].data _ event_list[i].udata); - } -#endif + ngx_log_debug6(NGX_LOG_DEBUG_EVENT, 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); if (event_list[i].flags & EV_ERROR) { ngx_log_error(NGX_LOG_ALERT, log, event_list[i].data, @@ -453,13 +447,15 @@ static int ngx_kqueue_process_events(ngx_log_t *log) instance = (uintptr_t) ev & 1; ev = (ngx_event_t *) ((uintptr_t) ev & (uintptr_t) ~1); - /* - * it's a stale event from a file descriptor - * that was just closed in this iteration - */ - if (ev->active == 0 || ev->instance != instance) { - ngx_log_debug(log, "stale kevent"); + + /* + * it's a stale event from a file descriptor + * that was just closed in this iteration + */ + + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, + "kevent: stale event " PTR_FMT, ev); continue; } @@ -511,6 +507,29 @@ static int ngx_kqueue_process_events(ngx_log_t *log) } +static void ngx_kqueue_thread_handler(ngx_event_t *ev, ngx_log_t *log) +{ + ngx_int_t instance; + + instance = (uintptr_t) ev & 1; + ev = (ngx_event_t *) ((uintptr_t) ev & (uintptr_t) ~1); + + if (ev->active && ev->instance == instance) { + ev->event_handler(ev); + return; + } + + /* + * it's a stale event from a file descriptor + * that was just closed in this iteration + */ + + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, + "kevent: stale event " PTR_FMT, ev); + +} + + static void *ngx_kqueue_create_conf(ngx_cycle_t *cycle) { ngx_kqueue_conf_t *kcf; diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c index c0852e866..4ed9498b3 100644 --- a/src/event/ngx_event_timer.c +++ b/src/event/ngx_event_timer.c @@ -4,6 +4,12 @@ #include <ngx_event.h> +/* + * TODO: in multithreaded enviroment all timer operations must be + * protected by the single mutex + */ + + ngx_rbtree_t *ngx_event_timer_rbtree; ngx_rbtree_t ngx_event_timer_sentinel; @@ -39,7 +45,11 @@ ngx_msec_t ngx_event_find_timer(void) } else { return (ngx_msec_t) + (node->key * NGX_TIMER_RESOLUTION - + ngx_elapsed_msec / NGX_TIMER_RESOLUTION * NGX_TIMER_RESOLUTION); +#if 0 (node->key * NGX_TIMER_RESOLUTION - ngx_elapsed_msec); +#endif } } @@ -82,281 +92,3 @@ void ngx_event_expire_timers(ngx_msec_t timer) break; } } - - -#if 0 - -/* TODO: in multithreaded enviroment all timer operations must be - protected by the single mutex */ - - -#if 0 -static ngx_event_t *ngx_timer_queue, ngx_temp_timer_queue; -static int ngx_expire_timers; -#endif - -static ngx_event_t *ngx_timer_queue; -static ngx_msec_t *ngx_timer_delta; -static int ngx_timer_cur_queue; -static int ngx_timer_queue_num; - - -int ngx_event_timer_init(ngx_cycle_t *cycle) -{ - ngx_int_t i; - ngx_msec_t *new_delta; - ngx_event_t *new_queue; - ngx_event_conf_t *ecf; - - ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); - - if (ngx_timer_queue_num < ecf->timer_queues) { - ngx_test_null(new_queue, - ngx_alloc(ecf->timer_queues * sizeof(ngx_event_t), - cycle->log), - NGX_ERROR); - - for (i = 0; i < ngx_timer_queue_num; i++) { - new_queue[i] = ngx_timer_queue[i]; - } - - if (ngx_timer_queue) { - ngx_free(ngx_timer_queue); - } - - ngx_timer_queue = new_queue; - - ngx_test_null(new_delta, - ngx_calloc(ecf->timer_queues * sizeof(ngx_msec_t), - cycle->log), - NGX_ERROR); - - for (i = 0; i < ngx_timer_queue_num; i++) { - new_delta[i] = ngx_timer_delta[i]; - } - - if (ngx_timer_delta) { - ngx_free(ngx_timer_delta); - } - - ngx_timer_delta = new_delta; - - ngx_timer_queue_num = ecf->timer_queues; - ngx_timer_cur_queue = 0; - - for (/* void */; i < ngx_timer_queue_num; i++) { - ngx_timer_queue[i].timer_prev = &ngx_timer_queue[i]; - ngx_timer_queue[i].timer_next = &ngx_timer_queue[i]; - } - - } else if (ngx_timer_queue_num > ecf->timer_queues) { - /* STUB */ - ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "NOT READY: timer"); - exit(1); - } - -#if 0 - ngx_temp_timer_queue.timer_prev = &ngx_temp_timer_queue; - ngx_temp_timer_queue.timer_next = &ngx_temp_timer_queue; -#endif - - return NGX_OK;; -} - - -void ngx_event_timer_done(ngx_cycle_t *cycle) -{ - ngx_free(ngx_timer_queue); - ngx_timer_queue = NULL; - - ngx_free(ngx_timer_delta); - ngx_timer_delta = NULL; - - ngx_timer_queue_num = 0; -} - - -void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer) -{ - ngx_event_t *e, *queue; -#if (NGX_DEBUG_EVENT) - ngx_connection_t *c; -#endif - - if (ev->timer_set) { - ngx_del_timer(ev); - } - -#if (NGX_DEBUG_EVENT) - c = ev->data; - ngx_log_debug(ev->log, "set timer: %d:%d:%d, slot: %d" _ - c->fd _ ev->write _ timer _ ngx_timer_cur_queue); -#endif - - if (ev->timer_next || ev->timer_prev) { - ngx_log_error(NGX_LOG_ALERT, ev->log, 0, "timer already set"); - return; - } - - queue = &ngx_timer_queue[ngx_timer_cur_queue]; - timer += ngx_timer_delta[ngx_timer_cur_queue++]; - - if (ngx_timer_cur_queue >= ngx_timer_queue_num) { - ngx_timer_cur_queue = 0; - } - - -#if 0 - if (ngx_expire_timers) { - queue = &ngx_temp_timer_queue; - - } else { - queue = &ngx_timer_queue[ngx_timer_cur_queue++]; - - if (ngx_timer_cur_queue >= ngx_timer_queue_num) { - ngx_timer_cur_queue = 0; - } - } -#endif - - for (e = queue->timer_next; - e != queue && timer > e->timer_delta; - e = e->timer_next) - { - timer -= e->timer_delta; - } - - ev->timer_delta = timer; - - ev->timer_next = e; - ev->timer_prev = e->timer_prev; - - e->timer_prev->timer_next = ev; - e->timer_prev = ev; - - ev->timer_set = 1; - - return; -} - - -int ngx_event_find_timer(void) -{ - ngx_int_t i; - ngx_msec_t timer; - - timer = NGX_MAX_MSEC; - - for (i = 0; i < ngx_timer_queue_num; i++) { - if (ngx_timer_queue[i].timer_next == &ngx_timer_queue[i]) { - continue; - } - - if (timer > ngx_timer_queue[i].timer_next->timer_delta) { - timer = ngx_timer_queue[i].timer_next->timer_delta; - } - } - - if (timer == NGX_MAX_MSEC) { - return 0; - } - - return timer; -} - - -void ngx_event_set_timer_delta(ngx_msec_t timer) -{ - ngx_int_t i; - - for (i = 0; i < ngx_timer_queue_num; i++) { - ngx_timer_delta[i] = timer; - } -} - - -/* void ngx_event_expire_timers() */ -void ngx_event_expire_timers(ngx_msec_t timer) -{ - ngx_int_t i; -#if 0 - ngx_msec_t delta; -#endif - ngx_event_t *ev; - -#if 0 - ngx_expire_timers = 1; -#endif - - for (i = 0; i < ngx_timer_queue_num; i++) { - -#if 0 - delta = timer; -#endif - - for ( ;; ) { - ev = ngx_timer_queue[i].timer_next; - - if (ev == &ngx_timer_queue[i]) { - break; - } - - if (ev->timer_delta > ngx_timer_delta[i]) { - ev->timer_delta -= ngx_timer_delta[i]; - break; - } - - ngx_timer_delta[i] -= ev->timer_delta; - -#if 0 - if (ev->timer_delta > delta) { - ev->timer_delta -= delta; - break; - } - - delta -= ev->timer_delta; -#endif - - ngx_del_timer(ev); - - if (ev->delayed) { - ev->delayed = 0; - if (ev->ready == 0) { - continue; - } - - } else { - ev->timedout = 1; - } - - ev->event_handler(ev); - } - - ngx_timer_delta[i] = 0; - } - -#if 0 - ngx_expire_timers = 0; - - if (ngx_temp_timer_queue.timer_next == &ngx_temp_timer_queue) { - return; - } - - timer = 0; - - while (ngx_temp_timer_queue.timer_next != &ngx_temp_timer_queue) { - timer += ngx_temp_timer_queue.timer_next->timer_delta; - ev = ngx_temp_timer_queue.timer_next; - -#if (NGX_DEBUG_EVENT) - ngx_log_debug(ev->log, "process temp timer queue"); -#endif - - ngx_del_timer(ev); - ngx_add_timer(ev, timer); - } -#endif -} - - -#endif diff --git a/src/event/ngx_event_timer.h b/src/event/ngx_event_timer.h index 21867ce20..51e3229c9 100644 --- a/src/event/ngx_event_timer.h +++ b/src/event/ngx_event_timer.h @@ -8,7 +8,7 @@ /* - * 32 bit key value resolution + * 32 bit timer key value resolution * * 1 msec - 49 days * 10 msec - 1 years 4 months @@ -28,15 +28,6 @@ int ngx_event_timer_init(void); ngx_msec_t ngx_event_find_timer(void); void ngx_event_expire_timers(ngx_msec_t timer); -#if 0 -int ngx_event_timer_init(ngx_cycle_t *cycle); -void ngx_event_timer_done(ngx_cycle_t *cycle); -void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer); -int ngx_event_find_timer(void); -void ngx_event_set_timer_delta(ngx_msec_t timer); -void ngx_event_expire_timers(ngx_msec_t timer); -#endif - extern ngx_rbtree_t *ngx_event_timer_rbtree; extern ngx_rbtree_t ngx_event_timer_sentinel; @@ -59,7 +50,11 @@ ngx_inline static void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer) } ev->rbtree_key = (ngx_int_t) + (ngx_elapsed_msec / NGX_TIMER_RESOLUTION * NGX_TIMER_RESOLUTION + + timer) / NGX_TIMER_RESOLUTION; +#if 0 (ngx_elapsed_msec + timer) / NGX_TIMER_RESOLUTION; +#endif ngx_rbtree_insert(&ngx_event_timer_rbtree, &ngx_event_timer_sentinel, (ngx_rbtree_t *) &ev->rbtree_key); @@ -68,38 +63,4 @@ ngx_inline static void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer) } -#if 0 - -ngx_inline static void ngx_event_del_timer(ngx_event_t *ev) -{ -#if (NGX_DEBUG_EVENT) - ngx_connection_t *c = ev->data; - ngx_log_debug(ev->log, "del timer: %d:%d" _ c->fd _ ev->write); -#endif - - if (!ev->timer_next || !ev->timer_prev) { - ngx_log_error(NGX_LOG_ALERT, ev->log, 0, "timer already deleted"); - return; - } - - if (ev->timer_prev) { - ev->timer_prev->timer_next = ev->timer_next; - } - - if (ev->timer_next) { - ev->timer_next->timer_delta += ev->timer_delta; - ev->timer_next->timer_prev = ev->timer_prev; - ev->timer_next = NULL; - } - - if (ev->timer_prev) { - ev->timer_prev = NULL; - } - - ev->timer_set = 0; -} - -#endif - - #endif /* _NGX_EVENT_TIMER_H_INCLUDED_ */ diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 2f5c92345..6d20fdf7f 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -407,14 +407,17 @@ int ngx_http_find_location_config(ngx_http_request_t *r) clcfp = cscf->locations.elts; for (i = 0; i < cscf->locations.nelts; i++) { -#if 1 -ngx_log_debug(r->connection->log, "trans: %s: %d" _ - clcfp[i]->name.data _ clcfp[i]->exact_match); -#endif +#if (HAVE_PCRE) if (clcfp[i]->regex) { break; } +#endif + + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "find location: %s\"%s\"", + clcfp[i]->exact_match ? "= " : "", + clcfp[i]->name.data); if (clcfp[i]->auto_redirect && r->uri.len == clcfp[i]->name.len - 1 @@ -449,20 +452,23 @@ ngx_log_debug(r->connection->log, "trans: %s: %d" _ } } +#if (HAVE_PCRE) + if (!exact && !auto_redirect) { /* regex matches */ for (/* void */; i < cscf->locations.nelts; i++) { -#if 1 -ngx_log_debug(r->connection->log, "trans: %s: %d" _ - clcfp[i]->name.data _ clcfp[i]->exact_match); -#endif - if (!clcfp[i]->regex) { continue; } + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "find location: %s\"%s\"", + clcfp[i]->exact_match ? "= " : + clcfp[i]->regex ? "~ " : "", + clcfp[i]->name.data); + rc = ngx_regex_exec(clcfp[i]->regex, &r->uri); if (rc == NGX_DECLINED) { @@ -488,6 +494,8 @@ ngx_log_debug(r->connection->log, "trans: %s: %d" _ } } +#endif /* HAVE_PCRE */ + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); if (!(ngx_io.flags & NGX_IO_SENDFILE) || !clcf->sendfile) { @@ -504,10 +512,6 @@ ngx_log_debug(r->connection->log, "trans: %s: %d" _ return NGX_HTTP_INTERNAL_SERVER_ERROR; } -#if 0 - r->headers_out.location->key.len = 8; - r->headers_out.location->key.data = "Location"; -#endif r->headers_out.location->value = *auto_redirect; return NGX_HTTP_MOVED_PERMANENTLY; @@ -614,7 +618,8 @@ int ngx_http_internal_redirect(ngx_http_request_t *r, { int i; - ngx_log_debug(r->connection->log, "internal redirect: '%s'" _ uri->data); + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "internal redirect: \"%s\"", uri->data); r->uri.len = uri->len; r->uri.data = uri->data; @@ -798,6 +803,8 @@ static int ngx_cmp_locations(const void *one, const void *two) ngx_int_t rc; +#if (HAVE_PCRE) + if (first->regex && !second->regex) { /* shift regex matches to the end */ return 1; @@ -808,6 +815,8 @@ static int ngx_cmp_locations(const void *one, const void *two) return 0; } +#endif + rc = ngx_strcmp(first->name.data, second->name.data); if (rc == 0 && second->exact_match) { @@ -876,6 +885,7 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) && value[1].data[0] == '~' && value[1].data[1] == '*')) { +#if (HAVE_PCRE) err.len = NGX_MAX_CONF_ERRSTR; err.data = errstr; @@ -890,6 +900,13 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) clcf->name.len = value[2].len; clcf->name.data = value[2].data; +#else + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "the using of the regex \"%s\" " + "requires PCRE library", + value[2].data); + return NGX_CONF_ERROR; +#endif } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h index ed228d791..17ee46fcb 100644 --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -134,7 +134,9 @@ typedef struct { ngx_http_cache_hash_t *open_files; +#if (HAVE_PCRE) ngx_regex_t *regex; +#endif unsigned exact_match:1; unsigned auto_redirect:1; diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c index 49f1dba2d..e3731d7ee 100644 --- a/src/http/ngx_http_header_filter.c +++ b/src/http/ngx_http_header_filter.c @@ -340,6 +340,8 @@ static int ngx_http_header_filter(ngx_http_request_t *r) /* the end of HTTP header */ *(h->last++) = CR; *(h->last++) = LF; + r->header_size = h->last - h->pos; + if (r->header_only) { h->type |= NGX_HUNK_LAST; } diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c index ff943950c..caef96750 100644 --- a/src/http/ngx_http_log_handler.c +++ b/src/http/ngx_http_log_handler.c @@ -19,6 +19,8 @@ static char *ngx_http_log_status(ngx_http_request_t *r, char *buf, uintptr_t data); static char *ngx_http_log_length(ngx_http_request_t *r, char *buf, uintptr_t data); +static char *ngx_http_log_apache_length(ngx_http_request_t *r, char *buf, + uintptr_t data); static char *ngx_http_log_header_in(ngx_http_request_t *r, char *buf, uintptr_t data); static char *ngx_http_log_connection_header_out(ngx_http_request_t *r, @@ -97,7 +99,7 @@ static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; static ngx_str_t ngx_http_combined_fmt = - ngx_string("%addr - - [%time] \"%request\" %status %length " + ngx_string("%addr - - [%time] \"%request\" %status %apache_length " "\"%{Referer}i\" %{User-Agent}i\""); @@ -110,6 +112,7 @@ ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = { { ngx_string("request"), 0, ngx_http_log_request }, { ngx_string("status"), 3, ngx_http_log_status }, { ngx_string("length"), NGX_OFF_T_LEN, ngx_http_log_length }, + { ngx_string("apache_length"), NGX_OFF_T_LEN, ngx_http_log_apache_length }, { ngx_string("i"), NGX_HTTP_LOG_ARG, ngx_http_log_header_in }, { ngx_string("o"), NGX_HTTP_LOG_ARG, ngx_http_log_header_out }, { ngx_null_string, 0, NULL } @@ -129,7 +132,8 @@ int ngx_http_log_handler(ngx_http_request_t *r) u_int written; #endif - ngx_log_debug(r->connection->log, "log handler"); + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http log handler"); lcf = ngx_http_get_module_loc_conf(r, ngx_http_log_module); @@ -248,6 +252,14 @@ static char *ngx_http_log_length(ngx_http_request_t *r, char *buf, } +static char *ngx_http_log_apache_length(ngx_http_request_t *r, char *buf, + uintptr_t data) +{ + return buf + ngx_snprintf(buf, NGX_OFF_T_LEN + 1, OFF_T_FMT, + r->connection->sent - r->header_size); +} + + static char *ngx_http_log_header_in(ngx_http_request_t *r, char *buf, uintptr_t data) { diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c index 5dc0bc3bd..599114c49 100644 --- a/src/http/ngx_http_parse.c +++ b/src/http/ngx_http_parse.c @@ -3,7 +3,7 @@ #include <ngx_core.h> #include <ngx_http.h> -int ngx_http_parse_request_line(ngx_http_request_t *r) +ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r) { char ch, *p; enum { @@ -419,7 +419,7 @@ int ngx_http_parse_request_line(ngx_http_request_t *r) } -int ngx_http_parse_header_line(ngx_http_request_t *r, ngx_hunk_t *h) +ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_hunk_t *h) { char c, ch, *p; enum { @@ -621,7 +621,7 @@ int ngx_http_parse_header_line(ngx_http_request_t *r, ngx_hunk_t *h) } -int ngx_http_parse_complex_uri(ngx_http_request_t *r) +ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) { char c, ch, decoded, *p, *u; enum { diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index 51478c6b1..66bf9be47 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -42,10 +42,12 @@ static char *client_header_errors[] = { }; +#if 0 static void ngx_http_dummy(ngx_event_t *wev) { return; } +#endif void ngx_http_init_connection(ngx_connection_t *c) @@ -110,7 +112,7 @@ void ngx_http_init_connection(ngx_connection_t *c) static void ngx_http_init_request(ngx_event_t *rev) { - int i; + ngx_int_t i; socklen_t len; struct sockaddr_in addr_in; ngx_connection_t *c; @@ -147,8 +149,6 @@ static void ngx_http_init_request(ngx_event_t *rev) in_port = c->servers; in_addr = in_port->addrs.elts; -ngx_log_debug(rev->log, "IN: %08x" _ in_port); - r->port = in_port->port; r->port_name = &in_port->port_name; @@ -274,8 +274,8 @@ ngx_log_debug(rev->log, "IN: %08x" _ in_port); static void ngx_http_process_request_line(ngx_event_t *rev) { - int rc, offset; ssize_t n; + ngx_int_t rc, offset; ngx_connection_t *c; ngx_http_request_t *r; ngx_http_log_ctx_t *ctx; @@ -439,15 +439,18 @@ static void ngx_http_process_request_line(ngx_event_t *rev) ngx_cpystrn(r->args.data, r->args_start, r->args.len + 1); } -#if 1 /* DEBUG */ - if (r->exten.data == NULL) { r->exten.data = ""; } - if (r->args.data == NULL) { r->args.data = ""; } - ngx_log_debug(c->log, "HTTP: %d, %d, '%s', '%s', '%s'" _ - r->method _ r->http_version _ - r->uri.data _ r->exten.data _ r->args.data); - if (r->exten.data[0] == '\0') { r->exten.data = NULL; } - if (r->args.data[0] == '\0') { r->args.data = NULL; } -#endif + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, + "http request line: \"%s\"", r->request_line.data); + + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, + "http uri: \"%s\"", r->uri.data); + + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, + "http args: \"%s\"", r->args.data ? r->args.data : ""); + + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, + "http exten: \"%s\"", + r->exten.data ? r->exten.data : ""); if (r->http_version < NGX_HTTP_VERSION_10) { rev->event_handler = ngx_http_block_read; @@ -532,8 +535,8 @@ static void ngx_http_process_request_line(ngx_event_t *rev) static void ngx_http_process_request_headers(ngx_event_t *rev) { - int rc, i, offset; ssize_t n; + ngx_int_t rc, i, offset; ngx_table_elt_t *h; ngx_connection_t *c; ngx_http_request_t *r; @@ -616,8 +619,9 @@ static void ngx_http_process_request_headers(ngx_event_t *rev) } } - ngx_log_debug(r->connection->log, "HTTP header: '%s: %s'" _ - h->key.data _ h->value.data); + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http header: \"%s: %s\"'", + h->key.data, h->value.data); if (cscf->large_client_header && r->header_in->pos == r->header_in->last) @@ -631,7 +635,8 @@ static void ngx_http_process_request_headers(ngx_event_t *rev) /* a whole header has been parsed successfully */ - ngx_log_debug(r->connection->log, "HTTP header done"); + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http header done"); rc = ngx_http_process_request_header(r); @@ -746,10 +751,10 @@ static ssize_t ngx_http_read_request_header(ngx_http_request_t *r) } -static int ngx_http_process_request_header(ngx_http_request_t *r) +static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r) { - int i; size_t len; + ngx_int_t i; ngx_http_server_name_t *name; ngx_http_core_loc_conf_t *clcf; @@ -828,13 +833,16 @@ static int ngx_http_process_request_header(ngx_http_request_t *r) void ngx_http_finalize_request(ngx_http_request_t *r, int rc) { + ngx_http_core_loc_conf_t *clcf; + /* r can be already destroyed when rc == NGX_DONE */ if (rc == NGX_DONE || r->main) { return; } - ngx_log_debug(r->connection->log, "finalize http request"); + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http finalize request"); if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { @@ -868,10 +876,12 @@ void ngx_http_finalize_request(ngx_http_request_t *r, int rc) ngx_del_timer(r->connection->write); } - if (r->keepalive != 0) { + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + + if (r->keepalive != 0 && clcf->keepalive_timeout > 0) { ngx_http_set_keepalive(r); - } else if (r->lingering_close) { + } else if (r->lingering_close && clcf->lingering_timeout > 0) { ngx_http_set_lingering_close(r); } else { @@ -916,7 +926,7 @@ void ngx_http_writer(ngx_event_t *wev) ngx_http_request_t *r; ngx_http_core_loc_conf_t *clcf; - ngx_log_debug(wev->log, "http writer handler"); + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, "http writer handler"); c = wev->data; r = c->data; @@ -934,7 +944,8 @@ void ngx_http_writer(ngx_event_t *wev) rc = ngx_http_output_filter(r, NULL); - ngx_log_debug(c->log, "writer output filter: %d" _ rc); + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, + "http writer output filter: %d", rc); if (rc == NGX_AGAIN) { if (!wev->ready) { @@ -951,7 +962,7 @@ void ngx_http_writer(ngx_event_t *wev) return; } - ngx_log_debug(c->log, "http writer done"); + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http writer done"); ngx_http_finalize_request(r, rc); } @@ -962,7 +973,7 @@ static void ngx_http_block_read(ngx_event_t *rev) ngx_connection_t *c; ngx_http_request_t *r; - ngx_log_debug(rev->log, "http read blocked"); + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http read blocked"); /* aio does not call this handler */ @@ -986,7 +997,7 @@ int ngx_http_discard_body(ngx_http_request_t *r) rev = r->connection->read; - ngx_log_debug(rev->log, "set discard body"); + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body"); if (rev->timer_set) { ngx_del_timer(rev); diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h index 82e8bf79b..785c8e16e 100644 --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -217,6 +217,8 @@ struct ngx_http_request_s { ngx_array_t cleanup; + size_t header_size; + char *discarded_buffer; void **err_ctx; int err_status; diff --git a/src/os/unix/ngx_errno.c b/src/os/unix/ngx_errno.c new file mode 100644 index 000000000..e94f2c9b0 --- /dev/null +++ b/src/os/unix/ngx_errno.c @@ -0,0 +1,24 @@ +#include <ngx_config.h> +#include <ngx_core.h> + + +ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size) +{ + size_t len; + + if (size == 0) { + return 0; + } + + errstr[0] = '\0'; + + strerror_r(err, errstr, size); + + for (len = 0; len < size; len++) { + if (errstr[len] == '\0') { + break; + } + } + + return len; +} diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h index a7326b613..f9e68b4ea 100644 --- a/src/os/unix/ngx_errno.h +++ b/src/os/unix/ngx_errno.h @@ -29,12 +29,17 @@ typedef int ngx_err_t; #define ngx_set_errno(err) errno = err #define ngx_set_socket_errno(err) errno = err -#if 0 -#define ngx_strerror(err) strerror(err) -#endif + +#if (HAVE_STRERROR_R) + +ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size); + +#else #define ngx_strerror_r(err, errstr, size) \ ngx_cpystrn(errstr, strerror(err), size) - (errstr) +#endif + #endif /* _NGX_ERRNO_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_os.h b/src/os/unix/ngx_os.h index a106514d1..cc693fa7d 100644 --- a/src/os/unix/ngx_os.h +++ b/src/os/unix/ngx_os.h @@ -49,6 +49,7 @@ extern int ngx_max_sockets; extern int ngx_inherited_nonblocking; +extern int done; extern int restart; extern int rotate; diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c index 7550af0d8..9ebc3d17c 100644 --- a/src/os/unix/ngx_posix_init.c +++ b/src/os/unix/ngx_posix_init.c @@ -7,47 +7,65 @@ int ngx_max_sockets; int ngx_inherited_nonblocking; +void ngx_signal_handler(int signo); +void ngx_exit_signal_handler(int signo); void ngx_restart_signal_handler(int signo); void ngx_rotate_signal_handler(int signo); -int ngx_posix_init(ngx_log_t *log) -{ - struct rlimit rlmt; - struct sigaction sa; - - 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; - } +typedef struct { + int signo; + char *signame; + char *action; + void (*handler)(int signo); +} ngx_signal_t; - ngx_memzero(&sa, sizeof(struct sigaction)); - sa.sa_handler = ngx_sigchld_handler; - sigemptyset(&sa.sa_mask); - if (sigaction(SIGCHLD, &sa, NULL) == -1) { - ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, - "sigaction(SIGCHLD) failed"); - return NGX_ERROR; - } - sa.sa_handler = ngx_restart_signal_handler; - if (sigaction(ngx_signal_value(NGX_RESTART_SIGNAL), &sa, NULL) == -1) { - ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, - "sigaction(SIG" ngx_value(NGX_RESTART_SIGNAL) ") failed"); - return NGX_ERROR; - } +ngx_signal_t signals[] = { + { ngx_signal_value(NGX_RESTART_SIGNAL), + "SIG" ngx_value(NGX_RESTART_SIGNAL), + "restarting", + ngx_signal_handler }, - sa.sa_handler = ngx_rotate_signal_handler; - if (sigaction(ngx_signal_value(NGX_ROTATE_SIGNAL), &sa, NULL) == -1) { - ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, - "sigaction(SIG" ngx_value(NGX_ROTATE_SIGNAL) ") failed"); - return NGX_ERROR; - } + { ngx_signal_value(NGX_ROTATE_SIGNAL), + "SIG" ngx_value(NGX_ROTATE_SIGNAL), + "reopen logs", + ngx_signal_handler }, + { ngx_signal_value(NGX_INTERRUPT_SIGNAL), + "SIG" ngx_value(NGX_INTERRUPT_SIGNAL), + "exiting", + ngx_signal_handler }, + + { ngx_signal_value(NGX_SHUTDOWN_SIGNAL), + "SIG" ngx_value(NGX_SHUTDOWN_SIGNAL), + "shutdowning", + ngx_signal_handler }, + + { SIGCHLD, "SIGCHLD", NULL, ngx_sigchld_handler }, + + { SIGPIPE, "SIGPIPE, SIG_IGN", NULL, SIG_IGN }, + + { 0, NULL, NULL, NULL } +}; + + +int ngx_posix_init(ngx_log_t *log) +{ + ngx_signal_t *sig; + struct rlimit rlmt; + struct sigaction sa; + + for (sig = signals; sig->signo != 0; sig++) { + ngx_memzero(&sa, sizeof(struct sigaction)); + sa.sa_handler = sig->handler; + sigemptyset(&sa.sa_mask); + if (sigaction(sig->signo, &sa, NULL) == -1) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, + "sigaction(%s) failed", sig->signame); + return NGX_ERROR; + } + } if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) { ngx_log_error(NGX_LOG_ALERT, log, errno, @@ -71,6 +89,56 @@ int ngx_posix_init(ngx_log_t *log) } +void ngx_signal_handler(int signo) +{ + char *name; + ngx_signal_t *sig; + + for (sig = signals; sig->signo != 0; sig++) { + if (sig->signo == signo) { + break; + } + } + + /* STUB */ + name = strsignal(signo); + ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0, + "signal #%d (%s: %s) received, %s", + signo, sig->signame, name, sig->action); + + switch (signo) { + + /* STUB */ + case SIGQUIT: + case SIGABRT: + + case ngx_signal_value(NGX_SHUTDOWN_SIGNAL): + case ngx_signal_value(NGX_INTERRUPT_SIGNAL): + done = 1; + break; + + case ngx_signal_value(NGX_RESTART_SIGNAL): + restart = 1; + break; + + case ngx_signal_value(NGX_ROTATE_SIGNAL): + rotate = 1; + break; + } +} + + +void ngx_exit_signal_handler(int signo) +{ + char *s; + + s = strsignal(signo); + ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0, + "%s signal received, exiting", s); + done = 1; +} + + void ngx_restart_signal_handler(int signo) { restart = 1; diff --git a/src/os/win32/ngx_time.c b/src/os/win32/ngx_time.c index 435f43015..43d2c41cb 100644 --- a/src/os/win32/ngx_time.c +++ b/src/os/win32/ngx_time.c @@ -19,6 +19,8 @@ void ngx_gettimeofday(struct timeval *tp) * 134744 days, * 11644473600 seconds or * 11644473600,000,000,0 100-nanosecond intervals. + * + * See also MSKB Q167296. */ intervals = ((uint64_t) ft.dwHighDateTime << 32) | ft.dwLowDateTime; diff --git a/src/os/win32/ngx_win32_init.c b/src/os/win32/ngx_win32_init.c index 3c3509c02..aaeca21b8 100644 --- a/src/os/win32/ngx_win32_init.c +++ b/src/os/win32/ngx_win32_init.c @@ -52,6 +52,8 @@ int ngx_os_init(ngx_log_t *log) } /* + * Windows 3.1 Win32s 0xxxxx + * * Windows 95 140000 * Windows 98 141000 * Windows ME 149000 @@ -61,6 +63,8 @@ int ngx_os_init(ngx_log_t *log) * Windows 2000 250000 * Windows XP 250100 * Windows 2003 250200 + * + * Windows CE x.x 3xxxxx */ ngx_win32_version = osvi.dwPlatformId * 100000 @@ -84,7 +88,7 @@ int ngx_os_init(ngx_log_t *log) #endif } else { - if (osvi.dwPlatformId == 1) { + if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { /* Win9x build */ @@ -96,6 +100,14 @@ int ngx_os_init(ngx_log_t *log) osvi.szCSDVersion); } else { + + /* + * VER_PLATFORM_WIN32_NT + * + * we do not currently support VER_PLATFORM_WIN32_CE + * and we do not support VER_PLATFORM_WIN32s at all + */ + ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %u build:%u, \"%s\"", ngx_win32_version, osvi.dwBuildNumber, osvi.szCSDVersion); |