diff options
-rw-r--r-- | auto/sources | 2 | ||||
-rw-r--r-- | src/core/ngx_conf_file.c | 19 | ||||
-rw-r--r-- | src/core/ngx_core.h | 1 | ||||
-rw-r--r-- | src/core/ngx_cycle.c | 108 | ||||
-rw-r--r-- | src/core/ngx_cycle.h | 2 | ||||
-rw-r--r-- | src/core/ngx_list.c | 36 | ||||
-rw-r--r-- | src/core/ngx_list.h | 48 |
7 files changed, 213 insertions, 3 deletions
diff --git a/auto/sources b/auto/sources index 8cbef9e42..dc8cbc95a 100644 --- a/auto/sources +++ b/auto/sources @@ -9,6 +9,7 @@ CORE_DEPS="src/core/nginx.h \ src/core/ngx_log.h \ src/core/ngx_palloc.h \ src/core/ngx_array.h \ + src/core/ngx_list.h \ src/core/ngx_table.h \ src/core/ngx_buf.h \ src/core/ngx_string.h \ @@ -28,6 +29,7 @@ CORE_SRCS="src/core/nginx.c \ src/core/ngx_log.c \ src/core/ngx_palloc.c \ src/core/ngx_array.c \ + src/core/ngx_list.c \ src/core/ngx_buf.c \ src/core/ngx_output_chain.c \ src/core/ngx_string.c \ diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c index 742809603..d546fe667 100644 --- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -572,11 +572,28 @@ static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name) { ngx_uint_t i; + ngx_list_part_t *part; ngx_open_file_t *file; if (name) { + part = &cycle->open_files.part; + file = part->elts; + + for (i = 0; /* void */ ; i++) { + + if (i >= part->nelts) { + if (part->next == NULL) { + break; + } + part = part->next; + file = part->elts; + i = 0; + } + +#if 0 file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { +#endif if (name->len != file[i].name.len) { continue; } @@ -587,7 +604,7 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name) } } - if (!(file = ngx_push_array(&cycle->open_files))) { + if (!(file = ngx_push_list(&cycle->open_files))) { return NULL; } diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h index 4c2712cfa..0a12fb21a 100644 --- a/src/core/ngx_core.h +++ b/src/core/ngx_core.h @@ -43,6 +43,7 @@ typedef void (*ngx_event_handler_pt)(ngx_event_t *ev); #include <ngx_palloc.h> #include <ngx_buf.h> #include <ngx_array.h> +#include <ngx_list.h> #include <ngx_table.h> #include <ngx_file.h> #include <ngx_files.h> diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c index fe6abc25f..05a3a78f1 100644 --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -34,6 +34,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) ngx_pool_t *pool; ngx_cycle_t *cycle, **old; ngx_socket_t fd; + ngx_list_part_t *part; ngx_open_file_t *file; ngx_listening_t *ls, *nls; ngx_core_module_t *module; @@ -68,6 +69,30 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) cycle->pathes.pool = pool; + if (old_cycle->open_files.part.nelts) { + n = old_cycle->open_files.part.nelts; + for (part = old_cycle->open_files.part.next; part; part = part->next) { + n += part->nelts; + } + + } else { + n = 20; + } + + cycle->open_files.part.elts = ngx_palloc(pool, n * sizeof(ngx_open_file_t)); + if (cycle->open_files.part.elts == NULL) { + ngx_destroy_pool(pool); + return NULL; + } + cycle->open_files.part.nelts = 0; + cycle->open_files.part.next = NULL; + cycle->open_files.last = &cycle->open_files.part; + cycle->open_files.size = sizeof(ngx_open_file_t); + cycle->open_files.nalloc = n; + cycle->open_files.pool = pool; + + +#if 0 n = old_cycle->open_files.nelts ? old_cycle->open_files.nelts : 20; cycle->open_files.elts = ngx_pcalloc(pool, n * sizeof(ngx_open_file_t)); if (cycle->open_files.elts == NULL) { @@ -78,6 +103,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) cycle->open_files.size = sizeof(ngx_open_file_t); cycle->open_files.nalloc = n; cycle->open_files.pool = pool; +#endif if (!(cycle->new_log = ngx_log_create_errlog(cycle, NULL))) { @@ -180,8 +206,26 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) if (!failed) { + + part = &cycle->open_files.part; + file = part->elts; + + for (i = 0; /* void */ ; i++) { + + if (i >= part->nelts) { + if (part->next == NULL) { + break; + } + part = part->next; + file = part->elts; + i = 0; + } + +#if 0 file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { +#endif + if (file[i].name.data == NULL) { continue; } @@ -190,6 +234,11 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) NGX_FILE_RDWR, NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); + log->log_level = NGX_LOG_DEBUG_ALL; + ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, + "log: %0X %d \"%s\"", + &file[i], file[i].fd, file[i].name.data); + if (file[i].fd == NGX_INVALID_FILE) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, ngx_open_file_n " \"%s\" failed", @@ -287,6 +336,12 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) #if !(WIN32) if (!failed && !ngx_test_config) { + + ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, + "dup2: %0X %d \"%s\"", + cycle->log->file, + cycle->log->file->fd, cycle->log->file->name.data); + if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDERR) failed"); @@ -300,8 +355,25 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) /* rollback the new cycle configuration */ + part = &cycle->open_files.part; + file = part->elts; + + for (i = 0; /* void */ ; i++) { + + if (i >= part->nelts) { + if (part->next == NULL) { + break; + } + part = part->next; + file = part->elts; + i = 0; + } + +#if 0 file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { +#endif + if (file[i].fd == NGX_INVALID_FILE) { continue; } @@ -320,7 +392,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) ls = cycle->listening.elts; for (i = 0; i < cycle->listening.nelts; i++) { - if (ls[i].new && ls[i].fd == -1) { + if (ls[i].fd == -1 || !ls[i].new) { continue; } @@ -370,8 +442,25 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) /* close the unneeded open files */ + part = &old_cycle->open_files.part; + file = part->elts; + + for (i = 0; /* void */ ; i++) { + + if (i >= part->nelts) { + if (part->next == NULL) { + break; + } + part = part->next; + file = part->elts; + i = 0; + } + +#if 0 file = old_cycle->open_files.elts; for (i = 0; i < old_cycle->open_files.nelts; i++) { +#endif + if (file[i].fd == NGX_INVALID_FILE) { continue; } @@ -534,10 +623,27 @@ void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user) { ngx_fd_t fd; ngx_uint_t i; + ngx_list_part_t *part; ngx_open_file_t *file; + part = &cycle->open_files.part; + file = part->elts; + + for (i = 0; /* void */ ; i++) { + + if (i >= part->nelts) { + if (part->next == NULL) { + break; + } + part = part->next; + i = 0; + } + +#if 0 file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { +#endif + if (file[i].name.data == NULL) { continue; } diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h index 84521898c..1b24dd333 100644 --- a/src/core/ngx_cycle.h +++ b/src/core/ngx_cycle.h @@ -14,8 +14,8 @@ struct ngx_cycle_s { ngx_log_t *new_log; ngx_array_t listening; - ngx_array_t open_files; ngx_array_t pathes; + ngx_list_t open_files; ngx_uint_t connection_n; ngx_connection_t *connections; diff --git a/src/core/ngx_list.c b/src/core/ngx_list.c new file mode 100644 index 000000000..10d79575f --- /dev/null +++ b/src/core/ngx_list.c @@ -0,0 +1,36 @@ + +#include <ngx_config.h> +#include <ngx_core.h> + + +void *ngx_push_list(ngx_list_t *l) +{ + void *elt; + ngx_list_part_t *last; + + last = l->last; + + if (last->nelts == l->nalloc) { + + /* the last part is full, allocate a new list part */ + + if (!(last = ngx_palloc(l->pool, sizeof(ngx_list_part_t)))) { + return NULL; + } + + if (!(last->elts = ngx_palloc(l->pool, l->nalloc * l->size))) { + return NULL; + } + + last->nelts = 0; + last->next = NULL; + + l->last->next = last; + l->last = last; + } + + elt = (char *) last->elts + l->size * last->nelts; + last->nelts++; + + return elt; +} diff --git a/src/core/ngx_list.h b/src/core/ngx_list.h new file mode 100644 index 000000000..4da8343fc --- /dev/null +++ b/src/core/ngx_list.h @@ -0,0 +1,48 @@ +#ifndef _NGX_LIST_H_INCLUDED_ +#define _NGX_LIST_H_INCLUDED_ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +typedef struct ngx_list_part_s ngx_list_part_t; + +struct ngx_list_part_s { + void *elts; + ngx_uint_t nelts; + ngx_list_part_t *next; +}; + + +typedef struct { + ngx_list_part_t *last; + ngx_list_part_t part; + size_t size; + ngx_uint_t nalloc; + ngx_pool_t *pool; +} ngx_list_t; + + +#define ngx_init_list(l, p, n, s, rc) \ + if (!(l.part.elts = ngx_palloc(p, n * s))) { \ + return rc; \ + } \ + l.part.nelts = 0; l.part.next = NULL; \ + l.last = &l.part; l.size = s; l.nalloc = n; l.pool = p; + + +#define ngx_iterate_list(p, i) \ + for ( ;; i++) { \ + if (i >= p->nelts) { \ + if (p->next == NULL) { \ + break; \ + } \ + p = p->next; i = 0; \ + } + + +void *ngx_push_list(ngx_list_t *list); + + +#endif /* _NGX_LIST_H_INCLUDED_ */ |