From 8cf3e882228d678c1829c62c4fd0d31dd7cb2d42 Mon Sep 17 00:00:00 2001 From: Kirill A. Korinskiy Date: Fri, 17 Apr 2009 19:26:33 +0400 Subject: [PATCH] Stop write log for some period after have a problems for write(3). MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Cc: catap@catap.ru Now we have a some issue — the I/O is a sync operation and we blocking every time to try write to full partition. This patch stop write a log for some period after problem. The period setting by second optional argument of error_log directive. --- src/core/ngx_log.c | 17 ++++++++++++++++- src/core/ngx_log.h | 3 +++ 2 files changed, 19 insertions(+), 1 deletions(-) diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c index f85fc62..186b400 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -150,7 +150,11 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, ngx_linefeed(p); - (void) ngx_write_fd(log->file->fd, errstr, p - errstr); + if ((!log->last_write_log_time || + ngx_time() - log->last_write_log_time > log->write_retry_period) + && ngx_write_fd(log->file->fd, errstr, p - errstr) == -1) { + log->last_write_log_time = ngx_time(); + } } @@ -335,6 +339,9 @@ ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) value = cf->args->elts; + cf->cycle->new_log->last_write_log_time = 0; + cf->cycle->new_log->write_retry_period = NGX_ERROR; + if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) { cf->cycle->new_log->file->fd = ngx_stderr.fd; cf->cycle->new_log->file->name.len = 0; @@ -350,5 +357,13 @@ ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } } + if (cf->args->nelts > 2) { + cf->cycle->new_log->write_retry_period = ngx_atoi(value[1].data, value[1].len); + } + + if (cf->cycle->new_log->write_retry_period == NGX_ERROR) { + cf->cycle->new_log->write_retry_period = 30; + } + return ngx_set_error_log_levels(cf, cf->cycle->new_log); } diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h index 53136d1..73a9366 100644 --- a/src/core/ngx_log.h +++ b/src/core/ngx_log.h @@ -60,6 +60,9 @@ struct ngx_log_s { */ char *action; + + time_t last_write_log_time; + ngx_int_t write_retry_period; }; -- 1.6.2