# HG changeset patch # User Igor Sysoev # Date 1057331433 0 # Node ID d7f606e25b998093536573fd726fcfa01efc6858 # Parent da763a85be6688f193b312e548c4ce515145d114 nginx-0.0.1-2003-07-04-19:10:33 import diff --git a/src/core/nginx.c b/src/core/nginx.c --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -15,7 +15,7 @@ void ****ngx_conf_ctx; ngx_os_io_t ngx_io; -ngx_cycle_t *cycle; +ngx_cycle_t ngx_cycle; int ngx_max_module; @@ -30,7 +30,7 @@ int main(int argc, char *const *argv) { int i; ngx_log_t *log; - ngx_cycle_t *new_cycle; + ngx_cycle_t *cycle; /* TODO */ ngx_max_sockets = -1; @@ -50,23 +50,27 @@ int main(int argc, char *const *argv) return 1; } + ngx_cycle = *cycle; + /* daemon */ /* life cycle */ for ( ;; ) { - /* STUB */ cycle->log->file->fd = log->file->fd; - /* STUB */ cycle->log->log_level = NGX_LOG_DEBUG; - - /* STUB */ - ngx_io = ngx_os_io; + /* STUB */ ngx_cycle.log->log_level = NGX_LOG_DEBUG; /* forks */ ngx_init_temp_number(); - /* STUB */ - ngx_pre_thread(&cycle->listening, cycle->pool, cycle->log); + for (i = 0; ngx_modules[i]; i++) { + if (ngx_modules[i]->init_child) { + if (ngx_modules[i]->init_child(&ngx_cycle) == NGX_ERROR) { + /* fatal */ + exit(1); + } + } + } /* threads */ @@ -76,27 +80,29 @@ int main(int argc, char *const *argv) for ( ;; ) { for ( ;; ) { - ngx_log_debug(cycle->log, "worker cycle"); + ngx_log_debug(ngx_cycle.log, "worker cycle"); - ngx_process_events(cycle->log); + ngx_process_events(ngx_cycle.log); if (rotate) { - ngx_log_debug(cycle->log, "rotate"); + ngx_log_debug(ngx_cycle.log, "rotate"); } if (restart) { - ngx_log_debug(cycle->log, "restart"); + ngx_log_debug(ngx_cycle.log, "restart"); break; } } - new_cycle = ngx_init_cycle(cycle, cycle->log); - if (new_cycle == NULL) { + cycle = ngx_init_cycle(&ngx_cycle, ngx_cycle.log); + if (cycle == NULL) { continue; } - cycle = new_cycle; +ngx_log_debug(ngx_cycle.log, "OPEN: %d" _ cycle->log->file->fd); + ngx_cycle = *cycle; +ngx_log_debug(ngx_cycle.log, "OPEN: %d" _ ngx_cycle.log->file->fd); break; } } @@ -187,38 +193,32 @@ static ngx_cycle_t *ngx_init_cycle(ngx_c failed = 0; - for (i = 0; ngx_modules[i]; i++) { - if (ngx_modules[i]->init_module) { - if (ngx_modules[i]->init_module(cycle, log) == NGX_ERROR) - { - failed = 1; - break; - } +ngx_log_debug(log, "OPEN: %d" _ cycle->log->file->fd); + + file = cycle->open_files.elts; + for (i = 0; i < cycle->open_files.nelts; i++) { + if (file->name.data == NULL) { + continue; } + + file->fd = ngx_open_file(file->name.data, + NGX_FILE_RDWR, + NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); + + if (file->fd == NGX_INVALID_FILE) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, + ngx_open_file_n " \"%s\" failed", + file->name.data); + failed = 1; + break; + } + + /* TODO: Win32 append */ } - if (!failed) { - file = cycle->open_files.elts; - for (i = 0; i < cycle->open_files.nelts; i++) { - if (file->name.data == NULL) { - continue; - } - - file->fd = ngx_open_file(file->name.data, - NGX_FILE_RDWR, - NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); - - if (file->fd == NGX_INVALID_FILE) { - ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, - ngx_open_file_n " \"%s\" failed", - file->name.data); - failed = 1; - break; - } - - /* TODO: Win32 append */ - } - } +ngx_log_debug(log, "OPEN: %d" _ cycle->log->file->fd); + /* STUB */ cycle->log->log_level = NGX_LOG_DEBUG; +ngx_log_debug(cycle->log, "TEST"); if (!failed) { if (old_cycle) { @@ -254,12 +254,6 @@ static ngx_cycle_t *ngx_init_cycle(ngx_c /* rollback the new cycle configuration */ - for (i = 0; ngx_modules[i]; i++) { - if (ngx_modules[i]->rollback_module) { - ngx_modules[i]->rollback_module(cycle, log); - } - } - file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { if (file->fd == NGX_INVALID_FILE) { @@ -292,14 +286,17 @@ static ngx_cycle_t *ngx_init_cycle(ngx_c /* commit the new cycle configuration */ + pool->log = cycle->log; + for (i = 0; ngx_modules[i]; i++) { - if (ngx_modules[i]->commit_module) { - ngx_modules[i]->commit_module(cycle, log); + if (ngx_modules[i]->init_module) { + if (ngx_modules[i]->init_module(cycle) == NGX_ERROR) { + /* fatal */ + exit(1); + } } } - pool->log = cycle->log; - if (old_cycle == NULL) { return cycle; } 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 @@ -79,9 +79,8 @@ struct ngx_module_s { void *ctx; ngx_command_t *commands; int type; - int (*init_module)(ngx_cycle_t *cycle, ngx_log_t *log); - int (*commit_module)(ngx_cycle_t *cycle, ngx_log_t *log); - int (*rollback_module)(ngx_cycle_t *cycle, ngx_log_t *log); + int (*init_module)(ngx_cycle_t *cycle); + int (*init_child)(ngx_cycle_t *cycle); }; @@ -114,7 +113,7 @@ struct ngx_conf_s { }; -#define ngx_get_conf(module) ngx_conf_ctx[module.index] +#define ngx_get_conf(conf_ctx, module) conf_ctx[module.index] #define ngx_conf_init_value(conf, default) \ @@ -179,7 +178,7 @@ char *ngx_conf_set_time_slot(ngx_conf_t extern ngx_module_t *ngx_modules[]; -extern void ****ngx_conf_ctx; +extern ngx_cycle_t ngx_cycle; #endif /* _NGX_HTTP_CONF_FILE_H_INCLUDED_ */ diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h --- a/src/core/ngx_core.h +++ b/src/core/ngx_core.h @@ -58,10 +58,4 @@ typedef struct ngx_connection_s ngx_con */ -#if 0 -/* STUB */ -extern ngx_log_t ngx_log; -#endif - - #endif /* _NGX_CORE_H_INCLUDED_ */ 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 @@ -210,12 +210,6 @@ void ngx_log_stderr(ngx_event_t *ev) #endif -static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) -{ - return ngx_log_set_errlog(cf, cmd, &ngx_log); -} - - ngx_log_t *ngx_log_init_errlog() { @@ -252,11 +246,31 @@ ngx_log_t *ngx_log_create_errlog(ngx_cyc ngx_test_null(log, ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)), NULL); ngx_test_null(log->file, ngx_push_array(&cycle->open_files), NULL); + log->file->fd = NGX_INVALID_FILE; return log; } +static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + ngx_str_t *value; + + value = cf->args->elts; + + if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) { + cf->cycle->log->file = &ngx_stderr; + + } else { + cf->cycle->log->file->name = value[1]; + } + + return NGX_CONF_OK; +} + + +#if 0 + char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log) { int len; @@ -297,3 +311,5 @@ char *ngx_log_set_errlog(ngx_conf_t *cf, return NGX_CONF_OK; } + +#endif 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 @@ -170,8 +170,6 @@ void ngx_assert_core(ngx_log_t *log, con ngx_log_t *ngx_log_init_errlog(); ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle); -char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log); - extern ngx_module_t ngx_errlog_module; 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,16 +11,13 @@ typedef struct { - int kqueue; - struct kevent *change_list; u_int changes; - struct kevent *event_list; u_int events; } ngx_kqueue_conf_t; -static int ngx_kqueue_init(ngx_log_t *log); -static void ngx_kqueue_done(ngx_log_t *log); +static int ngx_kqueue_init(ngx_cycle_t *cycle); +static void ngx_kqueue_done(ngx_cycle_t *cycle); 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); @@ -72,10 +69,6 @@ ngx_event_module_t ngx_kqueue_module_ct NULL, /* delete an connection */ ngx_kqueue_process_events, /* process the events */ ngx_kqueue_init, /* init the events */ -#if 0 - ngx_kqueue_commit, /* commit the events */ - ngx_kqueue_rollback, /* rollback the events */ -#endif ngx_kqueue_done /* done the events */ } @@ -87,158 +80,27 @@ ngx_module_t ngx_kqueue_module = { ngx_kqueue_commands, /* module directives */ NGX_EVENT_MODULE, /* module type */ NULL, /* init module */ - NULL, /* commit module */ - NULL, /* rollback module */ -#if 0 NULL /* init child */ -#endif }; -#if 0 -static int ngx_kqueue_init(ngx_cycle_t *cycle, ngx_log_t *log) +static int ngx_kqueue_init(ngx_cycle_t *cycle) { struct timespec ts; ngx_kqueue_conf_t *kcf; kcf = ngx_event_get_conf(cycle->conf_ctx, ngx_kqueue_module); -ngx_log_debug(log, "CH: %d" _ kcf->changes); -ngx_log_debug(log, "EV: %d" _ kcf->events); - - if (ngx_kqueue == -1) { - kcf->kqueue = kqueue(); - - if (kcf->kqueue == -1) { - ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "kqueue() failed"); - return NGX_ERROR; - } - - } else { - kcf->kqueue = ngx_kqueue; - } - - 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; - } - - nchanges = 0; - } - - ngx_test_null(kcf->change_list, - ngx_alloc(kcf->changes * sizeof(struct kevent), log), - NGX_ERROR); - - } else { - kcf->change_list = change_list; - } - - if (nevents < kcf->events) { - ngx_test_null(kcf->event_list, - ngx_alloc(kcf->events * sizeof(struct kevent), log), - NGX_ERROR); - } else { - kcf->event_list = event_list; - } - - if (ngx_event_timer_init(cycle, log) == NGX_ERROR) { - return NGX_ERROR; - } - - return NGX_OK; -} - - -static void ngx_kqueue_commit(ngx_cycle_t *cycle, ngx_log_t *log) -{ - ngx_kqueue_conf_t *kcf; - - kcf = ngx_event_get_conf(cycle->conf_ctx, ngx_kqueue_module); - - ngx_kqueue = kcf->kqueue; - - if (change_list != kcf->change_list) { - ngx_free(change_list); - change_list = kcf->change_list; - } - - max_changes = kcf->changes; - - if (event_list != kcf->event_list) { - ngx_free(event_list); - event_list = kcf->event_list; - } - - nevents = kcf->events; - - ngx_event_timer_commit(cycle, log); - - ngx_event_actions = ngx_kqueue_module_ctx.actions; - ngx_io = ngx_os_io; - - ngx_event_flags = NGX_HAVE_LEVEL_EVENT - |NGX_HAVE_ONESHOT_EVENT -#if (HAVE_CLEAR_EVENT) - |NGX_HAVE_CLEAR_EVENT -#else - |NGX_USE_LEVEL_EVENT -#endif -#if (HAVE_LOWAT_EVENT) - |NGX_HAVE_LOWAT_EVENT -#endif - |NGX_HAVE_KQUEUE_EVENT; -} - - -static void ngx_kqueue_rollback(ngx_cycle_t *cycle, ngx_log_t *log) -{ - ngx_kqueue_conf_t *kcf; - - kcf = ngx_event_get_conf(cycle->conf_ctx, ngx_kqueue_module); - - if (ngx_kqueue == -1) { - if (close(kcf->kqueue) == -1) { - ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, - "kqueue close() failed"); - } - } - - if (change_list != kcf->change_list) { - ngx_free(kcf->change_list); - } - - if (event_list != kcf->event_list) { - ngx_free(kcf->event_list); - } - - ngx_event_timer_rollback(cycle, log); -} - -#endif - - -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); - -ngx_log_debug(log, "CH: %d" _ kcf->changes); -ngx_log_debug(log, "EV: %d" _ kcf->events); +ngx_log_debug(cycle->log, "CH: %d" _ kcf->changes); +ngx_log_debug(cycle->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"); + ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, + "kqueue() failed"); return NGX_ERROR; } } @@ -249,9 +111,11 @@ ngx_log_debug(log, "EV: %d" _ kcf->event 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"); + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "kevent() failed"); return NGX_ERROR; } + nchanges = 0; } if (change_list) { @@ -259,12 +123,12 @@ ngx_log_debug(log, "EV: %d" _ kcf->event } ngx_test_null(change_list, - ngx_alloc(kcf->changes * sizeof(struct kevent), log), + ngx_alloc(kcf->changes * sizeof(struct kevent), + cycle->log), NGX_ERROR); } max_changes = kcf->changes; - nchanges = 0; if (nevents < kcf->events) { if (event_list) { @@ -272,18 +136,18 @@ ngx_log_debug(log, "EV: %d" _ kcf->event } ngx_test_null(event_list, - ngx_alloc(kcf->events * sizeof(struct kevent), log), + ngx_alloc(kcf->events * sizeof(struct kevent), + cycle->log), NGX_ERROR); } nevents = kcf->events; - if (ngx_event_timer_init(log) == NGX_ERROR) { + if (ngx_event_timer_init(cycle) == NGX_ERROR) { return NGX_ERROR; } - /* TODO: re-add active events with new udata - if ecf->connections was increased */ + ngx_io = ngx_os_io; ngx_event_actions = ngx_kqueue_module_ctx.actions; @@ -303,15 +167,16 @@ ngx_log_debug(log, "EV: %d" _ kcf->event } -static void ngx_kqueue_done(ngx_log_t *log) +static void ngx_kqueue_done(ngx_cycle_t *cycle) { if (close(ngx_kqueue) == -1) { - ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kqueue close() failed"); + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "kqueue close() failed"); } ngx_kqueue = -1; - ngx_event_timer_done(log); + ngx_event_timer_done(cycle); ngx_free(change_list); ngx_free(event_list); 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 @@ -4,7 +4,7 @@ #include -#define DEF_CONNECTIONS 512 +#define DEFAULT_CONNECTIONS 512 extern ngx_module_t ngx_select_module; @@ -21,6 +21,9 @@ extern ngx_module_t ngx_devpoll_module; #include #endif +static int ngx_event_init_module(ngx_cycle_t *cycle); +static int ngx_event_init_child(ngx_cycle_t *cycle); +static int ngx_event_init(ngx_cycle_t *cycle); static char *ngx_events_block(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); @@ -31,15 +34,14 @@ static char *ngx_event_init_conf(ngx_poo int ngx_event_flags; ngx_event_actions_t ngx_event_actions; +int ngx_max_connections; ngx_connection_t *ngx_connections; ngx_event_t *ngx_read_events, *ngx_write_events; -static int ngx_event_max_module; +static int ngx_event_max_module; -static int ngx_event_connections; - static ngx_str_t events_name = ngx_string("events"); @@ -61,7 +63,8 @@ ngx_module_t ngx_events_module = { &events_name, /* module context */ ngx_events_commands, /* module directives */ NGX_CORE_MODULE, /* module type */ - NULL /* init module */ + NULL, /* init module */ + NULL /* init child */ }; @@ -109,17 +112,15 @@ ngx_module_t ngx_event_core_module = { ngx_event_core_commands, /* module directives */ NGX_EVENT_MODULE, /* module type */ ngx_event_init_module, /* init module */ - ngx_event_commit, /* commit module */ - ngx_event_rollback, /* rollback module */ ngx_event_init_child /* init child */ }; -static int ngx_event_init_module(ngx_cycle_t *cycle, ngx_log_t *log) +static int ngx_event_init_module(ngx_cycle_t *cycle) { if (cycle->one_process) { - return ngx_event_init(cycle, log); + return ngx_event_init(cycle); } return NGX_OK; @@ -128,18 +129,15 @@ static int ngx_event_init_module(ngx_cyc static int ngx_event_init_child(ngx_cycle_t *cycle) { - if (!cycle->one_process) { - if (ngx_event_init(cycle, cycle->log) == NGX_ERROR) { - return NGX_ERROR; - } - ngx_event_commit(cycle, cycle->log); + if (cycle->one_process) { + return NGX_OK; } - return NGX_OK; + return ngx_event_init(cycle); } -static int ngx_event_init(ngx_cycle_t *cycle, ngx_log_t *log) +static int ngx_event_init(ngx_cycle_t *cycle) { int m, i, fd; ngx_event_t *rev, *wev; @@ -153,8 +151,8 @@ static int ngx_event_init(ngx_cycle_t *c ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); -ngx_log_debug(log, "CONN: %d" _ ecf->connections); -ngx_log_debug(log, "TYPE: %d" _ ecf->use); +ngx_log_debug(cycle->log, "CONN: %d" _ ecf->connections); +ngx_log_debug(cycle->log, "TYPE: %d" _ ecf->use); for (m = 0; ngx_modules[m]; m++) { if (ngx_modules[m]->type != NGX_EVENT_MODULE) { @@ -163,31 +161,37 @@ ngx_log_debug(log, "TYPE: %d" _ ecf->use if (ngx_modules[m]->ctx_index == ecf->use) { module = ngx_modules[m]->ctx; - if (module->actions.init(log) == NGX_ERROR) { + if (module->actions.init(cycle) == NGX_ERROR) { return NGX_ERROR; } break; } } - if (ecf->connections) { + if (ngx_max_connections && ngx_max_connections < ecf->connections) { + /* TODO: push into delayed array and temporary pool */ + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "NOT READY"); + exit(1); } + ngx_max_connections = ecf->connections; + ngx_test_null(ngx_connections, - ngx_alloc(sizeof(ngx_connection_t) * ecf->connections, log), + ngx_alloc(sizeof(ngx_connection_t) * ecf->connections, + cycle->log), NGX_ERROR); ngx_test_null(ngx_read_events, - ngx_alloc(sizeof(ngx_event_t) * ecf->connections, log), + ngx_alloc(sizeof(ngx_event_t) * ecf->connections, cycle->log), NGX_ERROR); ngx_test_null(ngx_write_events, - ngx_alloc(sizeof(ngx_event_t) * ecf->connections, log), + ngx_alloc(sizeof(ngx_event_t) * ecf->connections, cycle->log), NGX_ERROR); /* for each listening socket */ - for (s = ls->elts, i = 0; i < ls->nelts; i++) { + for (s = cycle->listening.elts, i = 0; i < cycle->listening.nelts; i++) { fd = s[i].fd; @@ -216,7 +220,8 @@ ngx_log_debug(log, "TYPE: %d" _ ecf->use c->servers = s[i].servers; c->log = s[i].log; - ngx_test_null(rev->log, ngx_palloc(pool, sizeof(ngx_log_t)), NGX_ERROR); + ngx_test_null(rev->log, ngx_palloc(cycle->pool, sizeof(ngx_log_t)), + NGX_ERROR); ngx_memcpy(rev->log, c->log, sizeof(ngx_log_t)); c->read = rev; @@ -264,26 +269,6 @@ ngx_log_debug(log, "TYPE: %d" _ ecf->use } -static void ngx_event_commit(ngx_cycle_t *cycle, ngx_log_t *log) -{ -} - - -static void ngx_event_rollback(ngx_cycle_t *cycle, ngx_log_t *log) -{ -} - - -void ngx_worker(ngx_cycle_t *cycle) -{ - for ( ;; ) { - ngx_log_debug(cycle->log, "ngx_worker cycle"); - - ngx_process_events(cycle->log); - } -} - - static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { int m; @@ -407,18 +392,18 @@ static char *ngx_event_init_conf(ngx_poo #if (HAVE_KQUEUE) - ngx_conf_init_value(ecf->connections, DEF_CONNECTIONS); + ngx_conf_init_value(ecf->connections, DEFAULT_CONNECTIONS); ngx_conf_init_value(ecf->use, ngx_kqueue_module.ctx_index); #elif (HAVE_DEVPOLL) - ngx_conf_init_value(ecf->connections, DEF_CONNECTIONS); + ngx_conf_init_value(ecf->connections, DEFAULT_CONNECTIONS); ngx_conf_init_value(ecf->use, ngx_devpoll_module.ctx_index); #else /* HAVE_SELECT */ ngx_conf_init_value(ecf->connections, - FD_SETSIZE < DEF_CONNECTIONS ? FD_SETSIZE : DEF_CONNECTIONS); + FD_SETSIZE < DEFAULT_CONNECTIONS ? FD_SETSIZE : DEFAULT_CONNECTIONS); ngx_conf_init_value(ecf->use, ngx_select_module.ctx_index); diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -151,8 +151,8 @@ typedef struct { int (*del_conn)(ngx_connection_t *c); int (*process)(ngx_log_t *log); - int (*init)(ngx_log_t *log); - void (*done)(ngx_log_t *log); + int (*init)(ngx_cycle_t *cycle); + void (*done)(ngx_cycle_t *cycle); } ngx_event_actions_t; @@ -348,8 +348,8 @@ extern ngx_module_t ngx_events_mo extern ngx_module_t ngx_event_core_module; -#define ngx_event_get_conf(module) \ - (*(ngx_get_conf(ngx_events_module))) [module.ctx_index]; +#define ngx_event_get_conf(conf_ctx, module) \ + (*(ngx_get_conf(conf_ctx, ngx_events_module))) [module.ctx_index]; diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -17,7 +17,7 @@ void ngx_event_accept(ngx_event_t *ev) ngx_connection_t *c, *ls; ngx_event_conf_t *ecf; - ecf = ngx_event_get_conf(ngx_event_core_module); + ecf = ngx_event_get_conf(ngx_cycle.conf_ctx, ngx_event_core_module); ls = ev->data; 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 @@ -9,17 +9,18 @@ static int ngx_timer_cur_queue static int ngx_timer_queue_num; -int ngx_event_timer_init(ngx_log_t *log) +int ngx_event_timer_init(ngx_cycle_t *cycle) { int i; ngx_event_t *new_queue; ngx_event_conf_t *ecf; - ecf = ngx_event_get_conf(ngx_event_core_module); + 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), log), + ngx_alloc(ecf->timer_queues * sizeof(ngx_event_t), + cycle->log), NGX_ERROR); for (i = 0; i < ngx_timer_queue_num; i++) { @@ -39,16 +40,22 @@ int ngx_event_timer_init(ngx_log_t *log) 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"); + exit(1); } return NGX_OK;; } -void ngx_event_timer_done(ngx_log_t *log) +void ngx_event_timer_done(ngx_cycle_t *cycle) { ngx_free(ngx_timer_queue); ngx_timer_queue = NULL; + ngx_timer_queue_num = 0; } diff --git a/src/event/ngx_event_timer.h b/src/event/ngx_event_timer.h --- a/src/event/ngx_event_timer.h +++ b/src/event/ngx_event_timer.h @@ -7,8 +7,8 @@ #include -int ngx_event_timer_init(ngx_log_t *log); -void ngx_event_timer_done(ngx_log_t *log); +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_expire_timers(ngx_msec_t timer); diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c --- a/src/http/modules/ngx_http_charset_filter.c +++ b/src/http/modules/ngx_http_charset_filter.c @@ -9,10 +9,10 @@ typedef struct { } ngx_http_charset_loc_conf_t; +static int ngx_http_charset_filter_init(ngx_cycle_t *cycle); static void *ngx_http_charset_create_loc_conf(ngx_pool_t *pool); static char *ngx_http_charset_merge_loc_conf(ngx_pool_t *pool, void *parent, void *child); -static int ngx_http_charset_filter_init(ngx_cycle_t *cycle, ngx_log_t *log); static ngx_command_t ngx_http_charset_filter_commands[] = { @@ -46,8 +46,7 @@ ngx_module_t ngx_http_charset_filter_mo ngx_http_charset_filter_commands, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_charset_filter_init, /* init module */ - NULL, /* commit module */ - NULL /* rollback module */ + NULL /* init child */ }; @@ -87,7 +86,7 @@ static int ngx_http_charset_body_filter( #endif -static int ngx_http_charset_filter_init(ngx_cycle_t *cycle, ngx_log_t *log) +static int ngx_http_charset_filter_init(ngx_cycle_t *cycle) { next_header_filter = ngx_http_top_header_filter; ngx_http_top_header_filter = ngx_http_charset_header_filter; diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter.c --- a/src/http/modules/ngx_http_chunked_filter.c +++ b/src/http/modules/ngx_http_chunked_filter.c @@ -4,7 +4,7 @@ #include -static int ngx_http_chunked_filter_init(ngx_cycle_t *cycle, ngx_log_t *log); +static int ngx_http_chunked_filter_init(ngx_cycle_t *cycle); static ngx_http_module_t ngx_http_chunked_filter_module_ctx = { @@ -25,8 +25,7 @@ ngx_module_t ngx_http_chunked_filter_mo NULL, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_chunked_filter_init, /* init module */ - NULL, /* commit module */ - NULL /* rollback module */ + NULL /* init child */ }; @@ -119,7 +118,7 @@ static int ngx_http_chunked_body_filter( } -static int ngx_http_chunked_filter_init(ngx_cycle_t *cycle, ngx_log_t *log) +static int ngx_http_chunked_filter_init(ngx_cycle_t *cycle) { next_header_filter = ngx_http_top_header_filter; ngx_http_top_header_filter = ngx_http_chunked_header_filter; diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c --- a/src/http/modules/ngx_http_index_handler.c +++ b/src/http/modules/ngx_http_index_handler.c @@ -14,7 +14,7 @@ typedef struct { static int ngx_http_index_test_dir(ngx_http_request_t *r); -static int ngx_http_index_init(ngx_cycle_t *cycle, ngx_log_t *log); +static int ngx_http_index_init(ngx_cycle_t *cycle); static void *ngx_http_index_create_conf(ngx_pool_t *pool); static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, void *child); @@ -53,8 +53,7 @@ ngx_module_t ngx_http_index_module = { ngx_http_index_commands, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_index_init, /* init module */ - NULL, /* commit module */ - NULL /* rollback module */ + NULL /* init child */ }; @@ -204,7 +203,7 @@ ngx_log_debug(r->connection->log, "IS_DI } -static int ngx_http_index_init(ngx_cycle_t *cycle, ngx_log_t *log) +static int ngx_http_index_init(ngx_cycle_t *cycle) { ngx_http_handler_pt *h; ngx_http_conf_ctx_t *ctx; diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -9,7 +9,7 @@ typedef struct { } ngx_http_range_filter_ctx_t; -static int ngx_http_range_filter_init(ngx_cycle_t *cycle, ngx_log_t *log); +static int ngx_http_range_filter_init(ngx_cycle_t *cycle); static ngx_http_module_t ngx_http_range_filter_module_ctx = { @@ -30,8 +30,7 @@ ngx_module_t ngx_http_range_filter_modu NULL, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_range_filter_init, /* init module */ - NULL, /* commit module */ - NULL /* rollback module */ + NULL /* init child */ }; @@ -356,7 +355,7 @@ static int ngx_http_range_body_filter(ng } -static int ngx_http_range_filter_init(ngx_cycle_t *cycle, ngx_log_t *log) +static int ngx_http_range_filter_init(ngx_cycle_t *cycle) { next_header_filter = ngx_http_top_header_filter; ngx_http_top_header_filter = ngx_http_range_header_filter; diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -464,7 +464,7 @@ static char *ngx_http_block(ngx_conf_t * ls->nonblocking = 1; ls->handler = ngx_http_init_connection; - ls->log = cf->log; + ls->log = cf->cycle->log; cscf = in_addr[a].core_srv_conf; ls->pool_size = cscf->connection_pool_size; 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 @@ -20,7 +20,7 @@ static void *ngx_http_core_create_loc_co static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool, void *parent, void *child); -static int ngx_http_core_init(ngx_cycle_t *cycle, ngx_log_t *log); +static int ngx_http_core_init(ngx_cycle_t *cycle); static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); static int ngx_cmp_locations(const void *first, const void *second); static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, @@ -187,8 +187,7 @@ ngx_module_t ngx_http_core_module = { ngx_http_core_commands, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_core_init, /* init module */ - NULL, /* commit module */ - NULL /* rollback module */ + NULL /* init child */ }; @@ -529,7 +528,7 @@ int ngx_http_internal_redirect(ngx_http_ } -static int ngx_http_core_init(ngx_cycle_t *cycle, ngx_log_t *log) +static int ngx_http_core_init(ngx_cycle_t *cycle) { ngx_http_handler_pt *h; ngx_http_conf_ctx_t *ctx; diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c --- a/src/http/ngx_http_header_filter.c +++ b/src/http/ngx_http_header_filter.c @@ -11,7 +11,7 @@ -static int ngx_http_header_filter_init(ngx_cycle_t *cycle, ngx_log_t *log); +static int ngx_http_header_filter_init(ngx_cycle_t *cycle); static int ngx_http_header_filter(ngx_http_request_t *r); @@ -33,8 +33,7 @@ ngx_module_t ngx_http_header_filter_mod NULL, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_header_filter_init, /* init module */ - NULL, /* commit module */ - NULL /* rollback module */ + NULL /* init child */ }; @@ -389,7 +388,7 @@ static int ngx_http_header_filter(ngx_ht } -static int ngx_http_header_filter_init(ngx_cycle_t *cycle, ngx_log_t *log) +static int ngx_http_header_filter_init(ngx_cycle_t *cycle) { ngx_http_top_header_filter = ngx_http_header_filter; return NGX_OK; diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c --- a/src/http/ngx_http_write_filter.c +++ b/src/http/ngx_http_write_filter.c @@ -18,7 +18,7 @@ typedef struct { static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool); static char *ngx_http_write_filter_merge_conf(ngx_pool_t *pool, void *parent, void *child); -static int ngx_http_write_filter_init(ngx_cycle_t *cycle, ngx_log_t *log); +static int ngx_http_write_filter_init(ngx_cycle_t *cycle); static ngx_command_t ngx_http_write_filter_commands[] = { @@ -52,8 +52,7 @@ ngx_module_t ngx_http_write_filter_modu ngx_http_write_filter_commands, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_write_filter_init, /* init module */ - NULL, /* commit module */ - NULL /* rollback module */ + NULL /* init child */ }; @@ -189,7 +188,7 @@ static char *ngx_http_write_filter_merge } -static int ngx_http_write_filter_init(ngx_cycle_t *cycle, ngx_log_t *log) +static int ngx_http_write_filter_init(ngx_cycle_t *cycle) { ngx_http_top_body_filter = ngx_http_write_filter;