From 26489b16e5abc76eb1b72e37651d01a1e1a657cb Mon Sep 17 00:00:00 2001 From: Vladimir Homutov Date: Tue, 4 Jun 2013 11:27:36 +0400 Subject: [PATCH] Core: fixed handling of "stderr" in error_log. If "stderr" was specified in one of the "error_log" directives, stderr is not redirected to the first error_log on startup, configuration reload, and reopening log files. --- src/core/nginx.c | 2 +- src/core/ngx_cycle.c | 7 ++++--- src/core/ngx_cycle.h | 2 ++ src/core/ngx_log.c | 1 + src/http/ngx_http_core_module.c | 1 + 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/nginx.c b/src/core/nginx.c index 94df9bf74..796717ab9 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -387,7 +387,7 @@ main(int argc, char *const *argv) return 1; } - if (cycle->log->file->fd != ngx_stderr) { + if (!cycle->log_use_stderr && cycle->log->file->fd != ngx_stderr) { if (ngx_set_stderr(cycle->log->file->fd) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c index 40b8562b4..de817750c 100644 --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -582,8 +582,9 @@ ngx_init_cycle(ngx_cycle_t *old_cycle) /* commit the new cycle configuration */ - if (!ngx_use_stderr && cycle->log->file->fd != ngx_stderr) { - + if (!ngx_use_stderr && !cycle->log_use_stderr + && cycle->log->file->fd != ngx_stderr) + { if (ngx_set_stderr(cycle->log->file->fd) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, ngx_set_stderr_n " failed"); @@ -1228,7 +1229,7 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user) file[i].fd = fd; } - if (cycle->log->file->fd != ngx_stderr) { + if (!cycle->log_use_stderr && cycle->log->file->fd != ngx_stderr) { if (ngx_set_stderr(cycle->log->file->fd) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h index 2e4bc4ba2..21bf5ca3f 100644 --- a/src/core/ngx_cycle.h +++ b/src/core/ngx_cycle.h @@ -41,6 +41,8 @@ struct ngx_cycle_s { ngx_log_t *log; ngx_log_t new_log; + ngx_uint_t log_use_stderr; /* unsigned log_use_stderr:1; */ + ngx_connection_t **files; ngx_connection_t *free_connections; ngx_uint_t free_connection_n; diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c index d7830fb4b..20f50971d 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -438,6 +438,7 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) if (ngx_strcmp(value[1].data, "stderr") == 0) { ngx_str_null(&name); + cf->cycle->log_use_stderr = 1; } else { name = value[1]; diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 25d3dc97d..4403fa308 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -4898,6 +4898,7 @@ ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) if (ngx_strcmp(value[1].data, "stderr") == 0) { ngx_str_null(&name); + cf->cycle->log_use_stderr = 1; } else { name = value[1];