diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2004-09-05 19:54:02 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2004-09-05 19:54:02 +0000 |
| commit | 980a92472cc30271ad7e88eb2dcc43f00e984d4d (patch) | |
| tree | b8940cd9e6b8859c78e3c023c1373bae02371f2e /src/core | |
| parent | b9e344175f4e971284aa14c8fe685936a4957d52 (diff) | |
| download | nginx-980a92472cc30271ad7e88eb2dcc43f00e984d4d.tar.gz nginx-980a92472cc30271ad7e88eb2dcc43f00e984d4d.tar.bz2 | |
nginx-0.0.10-2004-09-05-23:54:02 import
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/ngx_array.h | 17 | ||||
| -rw-r--r-- | src/core/ngx_conf_file.c | 7 | ||||
| -rw-r--r-- | src/core/ngx_cycle.c | 65 | ||||
| -rw-r--r-- | src/core/ngx_list.h | 57 | ||||
| -rw-r--r-- | src/core/ngx_log.c | 15 |
5 files changed, 91 insertions, 70 deletions
diff --git a/src/core/ngx_array.h b/src/core/ngx_array.h index f54517fd5..79a86e643 100644 --- a/src/core/ngx_array.h +++ b/src/core/ngx_array.h @@ -20,6 +20,23 @@ void ngx_destroy_array(ngx_array_t *a); void *ngx_push_array(ngx_array_t *a); +ngx_inline static ngx_int_t ngx_init_array0(ngx_array_t *array, ngx_pool_t *pool, + ngx_uint_t n, size_t size) +{ + if (!(array->elts = ngx_palloc(pool, n * size))) { + return NGX_ERROR; + } + + array->nelts = 0; + array->size = size; + array->nalloc = n; + array->pool = pool; + + return NGX_OK; +} + + + #define ngx_init_array(a, p, n, s, rc) \ ngx_test_null(a.elts, ngx_palloc(p, n * s), rc); \ a.nelts = 0; a.size = s; a.nalloc = n; a.pool = p; diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c index d546fe667..ff236429d 100644 --- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -590,10 +590,6 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name) 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; } @@ -612,6 +608,9 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name) if (name) { file->name = *name; + } else { + file->name.len = 0; + file->name.data = NULL; } return file; diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c index 05a3a78f1..cc309e333 100644 --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -24,6 +24,8 @@ ngx_tls_key_t ngx_core_tls_key; static ngx_connection_t dumb; /* STUB */ +static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH); + ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) { @@ -79,31 +81,12 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) 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) { + if (ngx_init_list(&cycle->open_files, pool, n, sizeof(ngx_open_file_t)) + == NGX_ERROR) + { ngx_destroy_pool(pool); return NULL; } - cycle->open_files.nelts = 0; - 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))) { @@ -111,6 +94,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) return NULL; } + cycle->new_log->file->name = error_log; + n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10; cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t)); @@ -221,11 +206,6 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) 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; } @@ -234,7 +214,9 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) NGX_FILE_RDWR, NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); +#if 0 log->log_level = NGX_LOG_DEBUG_ALL; +#endif ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, "log: %0X %d \"%s\"", &file[i], file[i].fd, file[i].name.data); @@ -270,6 +252,10 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) cycle->log = cycle->new_log; pool->log = cycle->new_log; + if (cycle->log->log_level == 0) { + cycle->log->log_level = NGX_LOG_ERR; + } + if (!failed) { if (old_cycle->listening.nelts) { ls = old_cycle->listening.elts; @@ -335,7 +321,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) #if !(WIN32) - if (!failed && !ngx_test_config) { + if (!failed && !ngx_test_config && cycle->log->file->fd != STDERR_FILENO) { ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, "dup2: %0X %d \"%s\"", @@ -369,11 +355,6 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) 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; } @@ -456,11 +437,6 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) 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; } @@ -639,11 +615,6 @@ void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user) 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; } @@ -715,9 +686,11 @@ void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user) #if !(WIN32) - if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { - ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, - "dup2(STDERR) failed"); + if (cycle->log->file->fd != STDERR_FILENO) { + if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, + "dup2(STDERR) failed"); + } } #endif diff --git a/src/core/ngx_list.h b/src/core/ngx_list.h index 4da8343fc..757564f02 100644 --- a/src/core/ngx_list.h +++ b/src/core/ngx_list.h @@ -24,22 +24,47 @@ typedef struct { } 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; \ - } +ngx_inline static ngx_int_t ngx_init_list(ngx_list_t *list, ngx_pool_t *pool, + ngx_uint_t n, size_t size) +{ + if (!(list->part.elts = ngx_palloc(pool, n * size))) { + return NGX_ERROR; + } + + list->part.nelts = 0; + list->part.next = NULL; + list->last = &list->part; + list->size = size; + list->nalloc = n; + list->pool = pool; + + return NGX_OK; +} + + +/* + * + * the iteration through the list: + * + * part = &list.part; + * data = part->elts; + * + * for (i = 0 ;; i++) { + * + * if (i >= part->nelts) { + * if (part->next == NULL) { + * break; + * } + * + * part = part->next; + * data = part->elts; + * i = 0; + * } + * + * ... data[i] ... + * + * } + */ void *ngx_push_list(ngx_list_t *list); diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c index 7638b6a70..a3f6e77cb 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -37,8 +37,8 @@ ngx_module_t ngx_errlog_module = { }; -static ngx_open_file_t ngx_stderr; static ngx_log_t ngx_log; +static ngx_open_file_t ngx_stderr; static const char *err_levels[] = { @@ -296,8 +296,13 @@ ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args) name = NULL; } - ngx_test_null(log, ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)), NULL); - ngx_test_null(log->file, ngx_conf_open_file(cycle, name), NULL); + if (!(log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)))) { + return NULL; + } + + if (!(log->file = ngx_conf_open_file(cycle, name))) { + return NULL; + } return log; } @@ -363,7 +368,9 @@ static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) value = cf->args->elts; if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) { - cf->cycle->new_log->file = &ngx_stderr; + cf->cycle->new_log->file->fd = ngx_stderr.fd; + cf->cycle->new_log->file->name.len = 0; + cf->cycle->new_log->file->name.data = NULL; } else { cf->cycle->new_log->file->name = value[1]; |
