[nginx] Syslog: improved error handling of unix domain sockets.
Homutov Vladimir
vl at nginx.com
Wed Sep 24 16:03:49 UTC 2014
details: http://hg.nginx.org/nginx/rev/02c2352d5b01
branches:
changeset: 5858:02c2352d5b01
user: Vladimir Homutov <vl at nginx.com>
date: Tue Aug 26 14:56:54 2014 +0400
description:
Syslog: improved error handling of unix domain sockets.
If a syslog daemon is restarted and the unix socket is used, further logging
might stop to work. In case of send error, socket is closed, forcing
a reconnection at the next logging attempt.
diffstat:
src/core/ngx_syslog.c | 26 ++++++++++++++++++++++++--
1 files changed, 24 insertions(+), 2 deletions(-)
diffs (54 lines):
diff -r 2cb5275bf5e7 -r 02c2352d5b01 src/core/ngx_syslog.c
--- a/src/core/ngx_syslog.c Mon Sep 01 17:55:07 2014 +0400
+++ b/src/core/ngx_syslog.c Tue Aug 26 14:56:54 2014 +0400
@@ -261,6 +261,8 @@ ngx_syslog_writer(ngx_log_t *log, ngx_ui
ssize_t
ngx_syslog_send(ngx_syslog_peer_t *peer, u_char *buf, size_t len)
{
+ ssize_t n;
+
if (peer->conn.fd == (ngx_socket_t) -1) {
if (ngx_syslog_init_peer(peer) != NGX_OK) {
return NGX_ERROR;
@@ -271,12 +273,28 @@ ngx_syslog_send(ngx_syslog_peer_t *peer,
peer->conn.log = ngx_cycle->log;
if (ngx_send) {
- return ngx_send(&peer->conn, buf, len);
+ n = ngx_send(&peer->conn, buf, len);
} else {
/* event module has not yet set ngx_io */
- return ngx_os_io.send(&peer->conn, buf, len);
+ n = ngx_os_io.send(&peer->conn, buf, len);
}
+
+#if (NGX_HAVE_UNIX_DOMAIN)
+
+ if (n == NGX_ERROR && peer->server.sockaddr->sa_family == AF_UNIX) {
+
+ 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");
+ }
+
+ peer->conn.fd = (ngx_socket_t) -1;
+ }
+
+#endif
+
+ return n;
}
@@ -344,6 +362,10 @@ ngx_syslog_cleanup(void *data)
/* prevents further use of this peer */
peer->busy = 1;
+ if (peer->conn.fd == (ngx_socket_t) -1) {
+ return;
+ }
+
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");
More information about the nginx-devel
mailing list