details: http://hg.nginx.org/nginx/rev/2cb5275bf5e7 branches: changeset: 5857:2cb5275bf5e7 user: Vladimir Homutov <v...@nginx.com> date: Mon Sep 01 17:55:07 2014 +0400 description: Syslog: enabled logging of send errors.
The ngx_cycle->log is used when sending the message. This allows to log syslog send errors in another log. Logging to syslog after its cleanup handler has been executed was prohibited. Previously, this was possible from ngx_destroy_pool(), which resulted in error messages caused by attempts to write into the closed socket. The "processing" flag is renamed to "busy" to better match its semantics. diffstat: src/core/ngx_syslog.c | 13 +++++++++---- src/core/ngx_syslog.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diffs (66 lines): diff -r 1b8459a53e4b -r 2cb5275bf5e7 src/core/ngx_syslog.c --- a/src/core/ngx_syslog.c Wed Sep 17 22:52:02 2014 +0800 +++ b/src/core/ngx_syslog.c Mon Sep 01 17:55:07 2014 +0400 @@ -234,11 +234,11 @@ ngx_syslog_writer(ngx_log_t *log, ngx_ui peer = log->wdata; - if (peer->processing) { + if (peer->busy) { return; } - peer->processing = 1; + peer->busy = 1; peer->severity = level - 1; p = ngx_syslog_add_header(peer, msg); @@ -254,7 +254,7 @@ ngx_syslog_writer(ngx_log_t *log, ngx_ui (void) ngx_syslog_send(peer, msg, p - msg); - peer->processing = 0; + peer->busy = 0; } @@ -267,6 +267,9 @@ ngx_syslog_send(ngx_syslog_peer_t *peer, } } + /* log syslog socket events with valid log */ + peer->conn.log = ngx_cycle->log; + if (ngx_send) { return ngx_send(&peer->conn, buf, len); @@ -285,7 +288,6 @@ ngx_syslog_init_peer(ngx_syslog_peer_t * peer->conn.read = &ngx_syslog_dummy_event; peer->conn.write = &ngx_syslog_dummy_event; - peer->conn.log = &ngx_syslog_dummy_log; ngx_syslog_dummy_event.log = &ngx_syslog_dummy_log; @@ -339,6 +341,9 @@ ngx_syslog_cleanup(void *data) { ngx_syslog_peer_t *peer = data; + /* prevents further use of this peer */ + peer->busy = 1; + if (ngx_close_socket(peer->conn.fd) == -1) { ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno, ngx_close_socket_n " failed"); diff -r 1b8459a53e4b -r 2cb5275bf5e7 src/core/ngx_syslog.h --- a/src/core/ngx_syslog.h Wed Sep 17 22:52:02 2014 +0800 +++ b/src/core/ngx_syslog.h Mon Sep 01 17:55:07 2014 +0400 @@ -16,7 +16,7 @@ typedef struct { ngx_addr_t server; ngx_connection_t conn; - ngx_uint_t processing; /* unsigned processing:1; */ + ngx_uint_t busy; /* unsigned busy:1; */ } ngx_syslog_peer_t; _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel