Klaus Demo nginx / 27fa312
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. Vladimir Homutov 6 years ago
1 changed file(s) with 25 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
260260 ssize_t
261261 ngx_syslog_send(ngx_syslog_peer_t *peer, u_char *buf, size_t len)
262262 {
263 ssize_t n;
264
263265 if (peer->conn.fd == (ngx_socket_t) -1) {
264266 if (ngx_syslog_init_peer(peer) != NGX_OK) {
265267 return NGX_ERROR;
270272 peer->conn.log = ngx_cycle->log;
271273
272274 if (ngx_send) {
273 return ngx_send(&peer->conn, buf, len);
275 n = ngx_send(&peer->conn, buf, len);
274276
275277 } else {
276278 /* event module has not yet set ngx_io */
277 return ngx_os_io.send(&peer->conn, buf, len);
278 }
279 n = ngx_os_io.send(&peer->conn, buf, len);
280 }
281
282 #if (NGX_HAVE_UNIX_DOMAIN)
283
284 if (n == NGX_ERROR && peer->server.sockaddr->sa_family == AF_UNIX) {
285
286 if (ngx_close_socket(peer->conn.fd) == -1) {
287 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
288 ngx_close_socket_n " failed");
289 }
290
291 peer->conn.fd = (ngx_socket_t) -1;
292 }
293
294 #endif
295
296 return n;
279297 }
280298
281299
343361 /* prevents further use of this peer */
344362 peer->busy = 1;
345363
364 if (peer->conn.fd == (ngx_socket_t) -1) {
365 return;
366 }
367
346368 if (ngx_close_socket(peer->conn.fd) == -1) {
347369 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
348370 ngx_close_socket_n " failed");