# HG changeset patch # User Igor Sysoev # Date 1241099622 0 # Node ID d478379e51ac235edeee3d3c697da12e1cb275cc # Parent c2230102df6fcd5ef302ea4f36d02dd95979f544 *) refactor error_log processing: listen socket log might inherit built-in error_log with zero level, and r2447, r2466, r2467 were not enough *) remove bogus "stderr" level *) some functions and fields renames diff -r c2230102df6f -r d478379e51ac src/core/ngx_conf_file.c --- a/src/core/ngx_conf_file.c Thu Apr 30 12:43:38 2009 +0000 +++ b/src/core/ngx_conf_file.c Thu Apr 30 13:53:42 2009 +0000 @@ -858,7 +858,7 @@ full.data = NULL; #endif - if (name && name->len) { + if (name->len) { full = *name; if (ngx_conf_full_name(cycle, &full, 0) != NGX_OK) { @@ -894,14 +894,13 @@ return NULL; } - if (name && name->len) { + if (name->len) { file->fd = NGX_INVALID_FILE; file->name = full; } else { file->fd = ngx_stderr; - file->name.len = 0; - file->name.data = NULL; + file->name = *name; } file->buffer = NULL; diff -r c2230102df6f -r d478379e51ac src/core/ngx_connection.c --- a/src/core/ngx_connection.c Thu Apr 30 12:43:38 2009 +0000 +++ b/src/core/ngx_connection.c Thu Apr 30 13:53:42 2009 +0000 @@ -248,6 +248,8 @@ continue; } + ls[i].log = *ls[i].logp; + if (ls[i].inherited) { /* TODO: close on exit */ diff -r c2230102df6f -r d478379e51ac src/core/ngx_connection.h --- a/src/core/ngx_connection.h Thu Apr 30 12:43:38 2009 +0000 +++ b/src/core/ngx_connection.h Thu Apr 30 13:53:42 2009 +0000 @@ -34,6 +34,7 @@ void *servers; /* array of ngx_http_in_addr_t, for example */ ngx_log_t log; + ngx_log_t *logp; size_t pool_size; /* should be here because of the AcceptEx() preread */ diff -r c2230102df6f -r d478379e51ac src/core/ngx_cycle.c --- a/src/core/ngx_cycle.c Thu Apr 30 12:43:38 2009 +0000 +++ b/src/core/ngx_cycle.c Thu Apr 30 13:53:42 2009 +0000 @@ -82,6 +82,7 @@ cycle->pool = pool; cycle->log = log; + cycle->new_log.log_level = NGX_LOG_ERR; cycle->old_cycle = old_cycle; cycle->conf_prefix.len = old_cycle->conf_prefix.len; @@ -165,14 +166,6 @@ return NULL; } - - cycle->new_log = ngx_log_create_errlog(cycle, &error_log); - if (cycle->new_log == NULL) { - ngx_destroy_pool(pool); - return NULL; - } - - n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10; cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t)); @@ -336,6 +329,13 @@ } + if (cycle->new_log.file == NULL) { + cycle->new_log.file = ngx_conf_open_file(cycle, &error_log); + if (cycle->new_log.file == NULL) { + goto failed; + } + } + /* open the new files */ part = &cycle->open_files.part; @@ -382,12 +382,8 @@ #endif } - cycle->log = cycle->new_log; - pool->log = cycle->new_log; - - if (cycle->log->log_level == 0) { - cycle->log->log_level = NGX_LOG_ERR; - } + cycle->log = &cycle->new_log; + pool->log = &cycle->new_log; /* create shared memory */ diff -r c2230102df6f -r d478379e51ac src/core/ngx_cycle.h --- a/src/core/ngx_cycle.h Thu Apr 30 12:43:38 2009 +0000 +++ b/src/core/ngx_cycle.h Thu Apr 30 13:53:42 2009 +0000 @@ -38,7 +38,7 @@ ngx_pool_t *pool; ngx_log_t *log; - ngx_log_t *new_log; + ngx_log_t new_log; ngx_connection_t **files; ngx_connection_t *free_connections; diff -r c2230102df6f -r d478379e51ac src/core/ngx_log.c --- a/src/core/ngx_log.c Thu Apr 30 12:43:38 2009 +0000 +++ b/src/core/ngx_log.c Thu Apr 30 13:53:42 2009 +0000 @@ -8,14 +8,14 @@ #include -static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +static char *ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static ngx_command_t ngx_errlog_commands[] = { {ngx_string("error_log"), NGX_MAIN_CONF|NGX_CONF_1MORE, - ngx_set_error_log, + ngx_error_log, 0, 0, NULL}, @@ -53,7 +53,7 @@ static ngx_str_t err_levels[] = { - ngx_string("stderr"), + ngx_null_string, ngx_string("emerg"), ngx_string("alert"), ngx_string("crit"), @@ -345,7 +345,7 @@ ngx_log_t * -ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name) +ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name) { ngx_log_t *log; @@ -364,7 +364,7 @@ char * -ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log) +ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log) { ngx_uint_t i, n, d; ngx_str_t *value; @@ -409,10 +409,7 @@ } } - if (log->log_level == 0) { - log->log_level = NGX_LOG_ERR; - - } else if (log->log_level == NGX_LOG_DEBUG) { + if (log->log_level == NGX_LOG_DEBUG) { log->log_level = NGX_LOG_DEBUG_ALL; } @@ -421,26 +418,35 @@ static char * -ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_str_t *value; + ngx_str_t *value, name; + + if (cf->cycle->new_log.file) { + return "is duplicate"; + } value = cf->args->elts; - if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) { - cf->cycle->new_log->file->fd = ngx_stderr; - cf->cycle->new_log->file->name.len = 0; - cf->cycle->new_log->file->name.data = NULL; + if (ngx_strcmp(value[1].data, "stderr") == 0) { + name.len = 0; + name.data = NULL; } else { - cf->cycle->new_log->file->name = value[1]; + name = value[1]; + } - if (ngx_conf_full_name(cf->cycle, &cf->cycle->new_log->file->name, 0) - != NGX_OK) - { - return NGX_CONF_ERROR; - } + cf->cycle->new_log.file = ngx_conf_open_file(cf->cycle, &name); + if (cf->cycle->new_log.file == NULL) { + return NULL; } - return ngx_set_error_log_levels(cf, cf->cycle->new_log); + if (cf->args->nelts == 2) { + cf->cycle->new_log.log_level = NGX_LOG_ERR; + return NGX_CONF_OK; + } + + cf->cycle->new_log.log_level = 0; + + return ngx_log_set_levels(cf, &cf->cycle->new_log); } diff -r c2230102df6f -r d478379e51ac src/core/ngx_log.h --- a/src/core/ngx_log.h Thu Apr 30 12:43:38 2009 +0000 +++ b/src/core/ngx_log.h Thu Apr 30 13:53:42 2009 +0000 @@ -196,8 +196,8 @@ /*********************************/ ngx_log_t *ngx_log_init(u_char *prefix); -ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name); -char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log); +ngx_log_t *ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name); +char *ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log); void ngx_cdecl ngx_log_abort(ngx_err_t err, const char *fmt, ...); void ngx_cdecl ngx_log_stderr(ngx_err_t err, const char *fmt, ...); u_char *ngx_log_errno(u_char *buf, u_char *last, ngx_err_t err); diff -r c2230102df6f -r d478379e51ac src/core/ngx_resolver.c --- a/src/core/ngx_resolver.c Thu Apr 30 12:43:38 2009 +0000 +++ b/src/core/ngx_resolver.c Thu Apr 30 13:53:42 2009 +0000 @@ -131,14 +131,14 @@ r->event->handler = ngx_resolver_resend_handler; r->event->data = r; - r->event->log = cf->cycle->new_log; + r->event->log = &cf->cycle->new_log; r->ident = -1; r->resend_timeout = 5; r->expire = 30; r->valid = 300; - r->log = cf->cycle->new_log; + r->log = &cf->cycle->new_log; r->log_level = NGX_LOG_ALERT; if (addr) { @@ -152,7 +152,7 @@ uc->sockaddr = addr->sockaddr; uc->socklen = addr->socklen; uc->server = addr->name; - uc->log = cf->cycle->new_log; + uc->log = &cf->cycle->new_log; } return r; diff -r c2230102df6f -r d478379e51ac src/http/ngx_http.c --- a/src/http/ngx_http.c Thu Apr 30 12:43:38 2009 +0000 +++ b/src/http/ngx_http.c Thu Apr 30 13:53:42 2009 +0000 @@ -1746,7 +1746,7 @@ clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index]; - ls->log = *clcf->err_log; + ls->logp = clcf->error_log; ls->log.data = &ls->addr_text; ls->log.handler = ngx_accept_log_error; diff -r c2230102df6f -r d478379e51ac src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c Thu Apr 30 12:43:38 2009 +0000 +++ b/src/http/ngx_http_core_module.c Thu Apr 30 13:53:42 2009 +0000 @@ -1292,10 +1292,10 @@ } if (r == r->main) { - r->connection->log->file = clcf->err_log->file; + r->connection->log->file = clcf->error_log->file; if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { - r->connection->log->log_level = clcf->err_log->log_level; + r->connection->log->log_level = clcf->error_log->log_level; } } @@ -2929,7 +2929,7 @@ * lcf->post_action = { 0, NULL }; * lcf->types = NULL; * lcf->default_type = { 0, NULL }; - * lcf->err_log = NULL; + * lcf->error_log = NULL; * lcf->error_pages = NULL; * lcf->try_files = NULL; * lcf->client_body_path = NULL; @@ -3109,11 +3109,11 @@ } } - if (conf->err_log == NULL) { - if (prev->err_log) { - conf->err_log = prev->err_log; + if (conf->error_log == NULL) { + if (prev->error_log) { + conf->error_log = prev->error_log; } else { - conf->err_log = cf->cycle->new_log; + conf->error_log = &cf->cycle->new_log; } } @@ -4104,14 +4104,23 @@ ngx_str_t *value; + if (lcf->error_log) { + return "is duplicate"; + } + value = cf->args->elts; - lcf->err_log = ngx_log_create_errlog(cf->cycle, &value[1]); - if (lcf->err_log == NULL) { + lcf->error_log = ngx_log_create(cf->cycle, &value[1]); + if (lcf->error_log == NULL) { return NGX_CONF_ERROR; } - return ngx_set_error_log_levels(cf, lcf->err_log); + if (cf->args->nelts == 2) { + lcf->error_log->log_level = NGX_LOG_ERR; + return NGX_CONF_OK; + } + + return ngx_log_set_levels(cf, lcf->error_log); } diff -r c2230102df6f -r d478379e51ac src/http/ngx_http_core_module.h --- a/src/http/ngx_http_core_module.h Thu Apr 30 12:43:38 2009 +0000 +++ b/src/http/ngx_http_core_module.h Thu Apr 30 13:53:42 2009 +0000 @@ -377,7 +377,7 @@ ngx_flag_t open_file_cache_errors; ngx_flag_t open_file_cache_events; - ngx_log_t *err_log; + ngx_log_t *error_log; ngx_uint_t types_hash_max_size; ngx_uint_t types_hash_bucket_size; diff -r c2230102df6f -r d478379e51ac src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c Thu Apr 30 12:43:38 2009 +0000 +++ b/src/http/ngx_http_request.c Thu Apr 30 13:53:42 2009 +0000 @@ -420,9 +420,9 @@ #endif clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); - c->log->file = clcf->err_log->file; + c->log->file = clcf->error_log->file; if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { - c->log->log_level = clcf->err_log->log_level; + c->log->log_level = clcf->error_log->log_level; } if (c->buffer == NULL) { @@ -1704,10 +1704,10 @@ r->loc_conf = cscf->ctx->loc_conf; clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); - r->connection->log->file = clcf->err_log->file; + r->connection->log->file = clcf->error_log->file; if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { - r->connection->log->log_level = clcf->err_log->log_level; + r->connection->log->log_level = clcf->error_log->log_level; } return NGX_OK; diff -r c2230102df6f -r d478379e51ac src/mail/ngx_mail.c --- a/src/mail/ngx_mail.c Thu Apr 30 12:43:38 2009 +0000 +++ b/src/mail/ngx_mail.c Thu Apr 30 13:53:42 2009 +0000 @@ -313,11 +313,10 @@ ls->handler = ngx_mail_init_connection; ls->pool_size = 256; - /* STUB */ - ls->log = *cf->cycle->new_log; + /* TODO: error_log directive */ + ls->logp = &cf->cycle->new_log; ls->log.data = &ls->addr_text; ls->log.handler = ngx_accept_log_error; - /**/ imip = ngx_palloc(cf->pool, sizeof(ngx_mail_in_port_t)); if (imip == NULL) {