# HG changeset patch # User Igor Sysoev # Date 1055701933 0 # Node ID 00bee6e7b485f3e23a226b1c8d729dbafcf21e16 # Parent 7db96f59bc29474e14b63f937a988f5ebc5289db nginx-0.0.1-2003-06-15-22:32:13 import diff --git a/src/core/nginx.c b/src/core/nginx.c --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -41,6 +41,7 @@ int main(int argc, char *const *argv) /* STUB */ ngx_log.log_level = NGX_LOG_DEBUG; #endif + log = ngx_log_init_errlog(); if (ngx_os_init(log) == NGX_ERROR) { @@ -230,6 +231,9 @@ static int ngx_open_listening_sockets(ng } if (failed) { + + /* TODO: configurable */ + ngx_log_error(NGX_LOG_EMERG, log, 0, "can not bind(), exiting"); return NGX_ERROR; } diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h --- a/src/core/ngx_conf_file.h +++ b/src/core/ngx_conf_file.h @@ -102,6 +102,11 @@ struct ngx_conf_s { conf = default; \ } +#define ngx_conf_init_unsigned_value(conf, default) \ + if (conf == (unsigned) NGX_CONF_UNSET) { \ + conf = default; \ + } + #define ngx_conf_init_size_value(conf, default) \ if (conf == NGX_CONF_UNSET) { \ conf = default; \ diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -219,6 +219,7 @@ static char *ngx_set_error_log(ngx_conf_ ngx_log_t *ngx_log_init_errlog() { #if (WIN32) + ngx_log.fd = GetStdHandle(STD_ERROR_HANDLE); if (ngx_log.fd == NGX_INVALID_FILE) { @@ -231,7 +232,9 @@ ngx_log_t *ngx_log_init_errlog() } #else + ngx_log.fd = STDERR_FILENO; + #endif ngx_log.log_level = NGX_LOG_INFO; diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h --- a/src/core/ngx_log.h +++ b/src/core/ngx_log.h @@ -68,10 +68,12 @@ typedef struct { ngx_fd_t fd; void *data; size_t (*handler)(void *ctx, char *buf, size_t len); +#if 0 /* STUB */ char *action; char *context; /* */ +#endif } ngx_log_t; #define MAX_ERROR_STR 2048 @@ -161,6 +163,9 @@ void ngx_assert_core(ngx_log_t *log, con #endif /* VARIADIC MACROS */ +#define ngx_log_alloc_log(pool, log) ngx_palloc(pool, log, sizeof(ngx_log_t)) +#define ngx_log_copy_log(new, old) ngx_memcpy(new, old, sizeof(ngx_log_t)) + ngx_log_t *ngx_log_init_errlog(); char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log); diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -11,8 +11,8 @@ typedef struct { - int changes; - int events; + u_int changes; + u_int events; } ngx_kqueue_conf_t; @@ -27,11 +27,10 @@ static void *ngx_kqueue_create_conf(ngx_ static char *ngx_kqueue_init_conf(ngx_pool_t *pool, void *conf); -int ngx_kqueue; +int ngx_kqueue = -1; static struct kevent *change_list, *event_list; -static u_int max_changes, nchanges; -static int nevents; +static u_int max_changes, nchanges, nevents; static ngx_str_t kqueue_name = ngx_string("kqueue"); @@ -86,6 +85,7 @@ ngx_module_t ngx_kqueue_module = { static int ngx_kqueue_init(ngx_log_t *log) { + struct timespec ts; ngx_kqueue_conf_t *kcf; kcf = ngx_event_get_conf(ngx_kqueue_module); @@ -93,28 +93,57 @@ static int ngx_kqueue_init(ngx_log_t *lo ngx_log_debug(log, "CH: %d" _ kcf->changes); ngx_log_debug(log, "EV: %d" _ kcf->events); + if (ngx_kqueue == -1) { + ngx_kqueue = kqueue(); + + if (ngx_kqueue == -1) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "kqueue() failed"); + return NGX_ERROR; + } + } + + if (max_changes < kcf->changes) { + if (nchanges) { + ts.tv_sec = 0; + ts.tv_nsec = 0; + + if (kevent(ngx_kqueue, change_list, nchanges, NULL, 0, &ts) == -1) { + ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kevent() failed"); + return NGX_ERROR; + } + } + + if (change_list) { + ngx_free(change_list); + } + + ngx_test_null(change_list, + ngx_alloc(kcf->changes * sizeof(struct kevent), log), + NGX_ERROR); + } + max_changes = kcf->changes; - nevents = kcf->events; nchanges = 0; - ngx_kqueue = kqueue(); + if (nevents < kcf->events) { + if (event_list) { + ngx_free(event_list); + } - if (ngx_kqueue == -1) { - ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "kqueue() failed"); - return NGX_ERROR; + ngx_test_null(event_list, + ngx_alloc(kcf->events * sizeof(struct kevent), log), + NGX_ERROR); } - ngx_test_null(change_list, - ngx_alloc(kcf->changes * sizeof(struct kevent), log), - NGX_ERROR); - ngx_test_null(event_list, - ngx_alloc(kcf->events * sizeof(struct kevent), log), - NGX_ERROR); + nevents = kcf->events; if (ngx_event_timer_init(log) == NGX_ERROR) { return NGX_ERROR; } + /* TODO: re-add active events with new udata + if ecf->connections was increased */ + ngx_event_actions = ngx_kqueue_module_ctx.actions; ngx_event_flags = NGX_HAVE_LEVEL_EVENT @@ -139,10 +168,18 @@ static void ngx_kqueue_done(ngx_log_t *l ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kqueue close() failed"); } + ngx_kqueue = -1; + ngx_event_timer_done(log); ngx_free(change_list); ngx_free(event_list); + + change_list = NULL; + event_list = NULL; + max_changes = 0; + nchanges = 0; + nevents = 0; } @@ -209,8 +246,8 @@ static int ngx_kqueue_del_event(ngx_even static int ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags) { - struct timespec ts; - ngx_connection_t *c; + struct timespec ts; + ngx_connection_t *c; c = ev->data; @@ -227,7 +264,7 @@ static int ngx_kqueue_set_event(ngx_even ts.tv_nsec = 0; if (kevent(ngx_kqueue, change_list, nchanges, NULL, 0, &ts) == -1) { - ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, "kevent failed"); + ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, "kevent() failed"); return NGX_ERROR; } @@ -295,7 +332,7 @@ static int ngx_kqueue_process_events(ngx events = kevent(ngx_kqueue, change_list, nchanges, event_list, nevents, tp); if (events == -1) { - ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kevent failed"); + ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kevent() failed"); return NGX_ERROR; } @@ -313,7 +350,7 @@ static int ngx_kqueue_process_events(ngx } else { if (events == 0) { ngx_log_error(NGX_LOG_ALERT, log, 0, - "kevent returns no events without timeout"); + "kevent() returned no events without timeout"); return NGX_ERROR; } } @@ -342,7 +379,7 @@ static int ngx_kqueue_process_events(ngx if (event_list[i].flags & EV_ERROR) { ngx_log_error(NGX_LOG_ALERT, log, event_list[i].data, - "kevent error on %d", event_list[i].ident); + "kevent() error on %d", event_list[i].ident); continue; } @@ -414,8 +451,8 @@ static char *ngx_kqueue_init_conf(ngx_po { ngx_kqueue_conf_t *kcf = conf; - ngx_conf_init_value(kcf->changes, 512); - ngx_conf_init_value(kcf->events, 512); + ngx_conf_init_unsigned_value(kcf->changes, 512); + ngx_conf_init_unsigned_value(kcf->events, 512); return NGX_CONF_OK; } diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -42,7 +42,6 @@ static int ngx_event_connections; static ngx_str_t events_name = ngx_string("events"); -static ngx_str_t event_name = ngx_string("event"); static ngx_command_t ngx_events_commands[] = { @@ -66,6 +65,7 @@ ngx_module_t ngx_events_module = { }; +static ngx_str_t event_name = ngx_string("event"); static ngx_command_t ngx_event_commands[] = { diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c --- a/src/event/ngx_event_timer.c +++ b/src/event/ngx_event_timer.c @@ -12,20 +12,33 @@ static int ngx_timer_queue_num int ngx_event_timer_init(ngx_log_t *log) { int i; + ngx_event_t *new_queue; ngx_event_conf_t *ecf; ecf = ngx_event_get_conf(ngx_event_module); - ngx_timer_queue_num = ecf->timer_queues; - ngx_timer_cur_queue = 0; + if (ngx_timer_queue_num < ecf->timer_queues) { + ngx_test_null(new_queue, + ngx_alloc(ecf->timer_queues * sizeof(ngx_event_t), log), + NGX_ERROR); + + for (i = 0; i < ngx_timer_queue_num; i++) { + new_queue[i] = ngx_timer_queue[i]; + } - ngx_test_null(ngx_timer_queue, - ngx_alloc(ngx_timer_queue_num * sizeof(ngx_event_t), log), - NGX_ERROR); + if (ngx_timer_queue) { + ngx_free(ngx_timer_queue); + } + + ngx_timer_queue = new_queue; - for (i = 0; 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]; + 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]; + } } return NGX_OK;; @@ -35,6 +48,7 @@ int ngx_event_timer_init(ngx_log_t *log) void ngx_event_timer_done(ngx_log_t *log) { ngx_free(ngx_timer_queue); + ngx_timer_queue = NULL; } diff --git a/src/http/ngx_http_cache.c b/src/http/ngx_http_cache.c --- a/src/http/ngx_http_cache.c +++ b/src/http/ngx_http_cache.c @@ -2,7 +2,7 @@ /* * small file in malloc()ed memory, mmap()ed file, file descriptor only, - * file access time only (to estimate can pages pages still be in memory), + * file access time only (to estimate could pages still be in memory), * translated URI (ngx_http_index_hanlder), * compiled script (ngx_http_ssi_filter). */ @@ -14,7 +14,9 @@ /* "/" -> "/index.html" in ngx_http_index_handler */ #define NGX_HTTP_CACHE_ENTRY_URI 0x00000004 -/* complied script */ +/* 301 location "/dir" -> "dir/" in ngx_http_core_handler */ + +/* compiled script in ngx_http_ssi_filter */ #define NGX_HTTP_CACHE_ENTRY_SCRIPT 0x00000008 #define NGX_HTTP_CACHE_FILTER_FLAGS 0xFFFF0000 diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -359,6 +359,8 @@ ngx_log_debug(r->connection->log, "HTTP } } +ngx_log_debug(r->connection->log, "FILE: %d" _ r->file.fd); + if (!r->file.info_valid) { if (ngx_stat_fd(r->file.fd, &r->file.info) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, diff --git a/src/os/unix/ngx_daemon.c b/src/os/unix/ngx_daemon.c --- a/src/os/unix/ngx_daemon.c +++ b/src/os/unix/ngx_daemon.c @@ -1,9 +1,7 @@ #include #include -#include -/* daemon in Linux */ int ngx_daemon(ngx_log_t *log) { @@ -26,27 +24,8 @@ int ngx_daemon(ngx_log_t *log) return NGX_ERROR; } -#if (__SVR4 || linux) - - /* need HUP IGN ? check in Solaris and Linux */ - - switch (fork()) { - case -1: - ngx_log_error(NGX_LOG_EMERG, log, errno, "fork() failed"); - return NGX_ERROR; - - case 0: - break; - - default: - exit(0); - } - -#endif - umask(0); -#if 0 fd = open("/dev/null", O_RDWR); if (fd == -1) { ngx_log_error(NGX_LOG_EMERG, log, errno, "open(\"/dev/null\") failed"); @@ -63,10 +42,12 @@ int ngx_daemon(ngx_log_t *log) return NGX_ERROR; } +#if 0 if (dup2(fd, STDERR_FILENO) == -1) { ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDERR) failed"); return NGX_ERROR; } +#endif if (fd > STDERR_FILENO) { if (close(fd) == -1) { @@ -74,7 +55,6 @@ int ngx_daemon(ngx_log_t *log) return NGX_ERROR; } } -#endif return NGX_OK; } diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h --- a/src/os/unix/ngx_freebsd_config.h +++ b/src/os/unix/ngx_freebsd_config.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include /* TCP_NOPUSH */