[nginx] Syslog: install cleanup handler only once.

Vladimir Homutov vl at nginx.com
Wed May 23 12:18:33 UTC 2018


details:   http://hg.nginx.org/nginx/rev/7f9935f07fe9
branches:  
changeset: 7277:7f9935f07fe9
user:      Vladimir Homutov <vl at nginx.com>
date:      Mon May 14 22:50:57 2018 +0300
description:
Syslog: install cleanup handler only once.

If a socket was re-opened due to an error (02c2352d5b01 and fa0e093b64d7),
additional cleanup handler was installed each time.

diffstat:

 src/core/ngx_syslog.c |  32 ++++++++++++++++----------------
 src/core/ngx_syslog.h |   1 -
 2 files changed, 16 insertions(+), 17 deletions(-)

diffs (74 lines):

diff -r a90f7812de35 -r 7f9935f07fe9 src/core/ngx_syslog.c
--- a/src/core/ngx_syslog.c	Wed May 23 10:41:38 2018 +0300
+++ b/src/core/ngx_syslog.c	Mon May 14 22:50:57 2018 +0300
@@ -39,7 +39,8 @@ static ngx_event_t  ngx_syslog_dummy_eve
 char *
 ngx_syslog_process_conf(ngx_conf_t *cf, ngx_syslog_peer_t *peer)
 {
-    peer->pool = cf->pool;
+    ngx_pool_cleanup_t  *cln;
+
     peer->facility = NGX_CONF_UNSET_UINT;
     peer->severity = NGX_CONF_UNSET_UINT;
 
@@ -67,6 +68,19 @@ ngx_syslog_process_conf(ngx_conf_t *cf, 
 
     peer->conn.fd = (ngx_socket_t) -1;
 
+    peer->conn.read = &ngx_syslog_dummy_event;
+    peer->conn.write = &ngx_syslog_dummy_event;
+
+    ngx_syslog_dummy_event.log = &ngx_syslog_dummy_log;
+
+    cln = ngx_pool_cleanup_add(cf->pool, 0);
+    if (cln == NULL) {
+        return NGX_CONF_ERROR;
+    }
+
+    cln->data = peer;
+    cln->handler = ngx_syslog_cleanup;
+
     return NGX_CONF_OK;
 }
 
@@ -306,13 +320,7 @@ ngx_syslog_send(ngx_syslog_peer_t *peer,
 static ngx_int_t
 ngx_syslog_init_peer(ngx_syslog_peer_t *peer)
 {
-    ngx_socket_t         fd;
-    ngx_pool_cleanup_t  *cln;
-
-    peer->conn.read = &ngx_syslog_dummy_event;
-    peer->conn.write = &ngx_syslog_dummy_event;
-
-    ngx_syslog_dummy_event.log = &ngx_syslog_dummy_log;
+    ngx_socket_t  fd;
 
     fd = ngx_socket(peer->server.sockaddr->sa_family, SOCK_DGRAM, 0);
     if (fd == (ngx_socket_t) -1) {
@@ -333,14 +341,6 @@ ngx_syslog_init_peer(ngx_syslog_peer_t *
         goto failed;
     }
 
-    cln = ngx_pool_cleanup_add(peer->pool, 0);
-    if (cln == NULL) {
-        goto failed;
-    }
-
-    cln->data = peer;
-    cln->handler = ngx_syslog_cleanup;
-
     peer->conn.fd = fd;
 
     /* UDP sockets are always ready to write */
diff -r a90f7812de35 -r 7f9935f07fe9 src/core/ngx_syslog.h
--- a/src/core/ngx_syslog.h	Wed May 23 10:41:38 2018 +0300
+++ b/src/core/ngx_syslog.h	Mon May 14 22:50:57 2018 +0300
@@ -9,7 +9,6 @@
 
 
 typedef struct {
-    ngx_pool_t       *pool;
     ngx_uint_t        facility;
     ngx_uint_t        severity;
     ngx_str_t         tag;


More information about the nginx-devel mailing list