Mercurial > hg > nginx-quic
comparison src/core/ngx_syslog.c @ 5857:2cb5275bf5e7
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.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Mon, 01 Sep 2014 17:55:07 +0400 |
parents | 44532046d9d7 |
children | 02c2352d5b01 |
comparison
equal
deleted
inserted
replaced
5856:1b8459a53e4b | 5857:2cb5275bf5e7 |
---|---|
232 ngx_uint_t head_len; | 232 ngx_uint_t head_len; |
233 ngx_syslog_peer_t *peer; | 233 ngx_syslog_peer_t *peer; |
234 | 234 |
235 peer = log->wdata; | 235 peer = log->wdata; |
236 | 236 |
237 if (peer->processing) { | 237 if (peer->busy) { |
238 return; | 238 return; |
239 } | 239 } |
240 | 240 |
241 peer->processing = 1; | 241 peer->busy = 1; |
242 peer->severity = level - 1; | 242 peer->severity = level - 1; |
243 | 243 |
244 p = ngx_syslog_add_header(peer, msg); | 244 p = ngx_syslog_add_header(peer, msg); |
245 head_len = p - msg; | 245 head_len = p - msg; |
246 | 246 |
252 | 252 |
253 p = ngx_snprintf(p, len, "%s", buf); | 253 p = ngx_snprintf(p, len, "%s", buf); |
254 | 254 |
255 (void) ngx_syslog_send(peer, msg, p - msg); | 255 (void) ngx_syslog_send(peer, msg, p - msg); |
256 | 256 |
257 peer->processing = 0; | 257 peer->busy = 0; |
258 } | 258 } |
259 | 259 |
260 | 260 |
261 ssize_t | 261 ssize_t |
262 ngx_syslog_send(ngx_syslog_peer_t *peer, u_char *buf, size_t len) | 262 ngx_syslog_send(ngx_syslog_peer_t *peer, u_char *buf, size_t len) |
265 if (ngx_syslog_init_peer(peer) != NGX_OK) { | 265 if (ngx_syslog_init_peer(peer) != NGX_OK) { |
266 return NGX_ERROR; | 266 return NGX_ERROR; |
267 } | 267 } |
268 } | 268 } |
269 | 269 |
270 /* log syslog socket events with valid log */ | |
271 peer->conn.log = ngx_cycle->log; | |
272 | |
270 if (ngx_send) { | 273 if (ngx_send) { |
271 return ngx_send(&peer->conn, buf, len); | 274 return ngx_send(&peer->conn, buf, len); |
272 | 275 |
273 } else { | 276 } else { |
274 /* event module has not yet set ngx_io */ | 277 /* event module has not yet set ngx_io */ |
283 ngx_socket_t fd; | 286 ngx_socket_t fd; |
284 ngx_pool_cleanup_t *cln; | 287 ngx_pool_cleanup_t *cln; |
285 | 288 |
286 peer->conn.read = &ngx_syslog_dummy_event; | 289 peer->conn.read = &ngx_syslog_dummy_event; |
287 peer->conn.write = &ngx_syslog_dummy_event; | 290 peer->conn.write = &ngx_syslog_dummy_event; |
288 peer->conn.log = &ngx_syslog_dummy_log; | |
289 | 291 |
290 ngx_syslog_dummy_event.log = &ngx_syslog_dummy_log; | 292 ngx_syslog_dummy_event.log = &ngx_syslog_dummy_log; |
291 | 293 |
292 fd = ngx_socket(peer->server.sockaddr->sa_family, SOCK_DGRAM, 0); | 294 fd = ngx_socket(peer->server.sockaddr->sa_family, SOCK_DGRAM, 0); |
293 if (fd == (ngx_socket_t) -1) { | 295 if (fd == (ngx_socket_t) -1) { |
337 static void | 339 static void |
338 ngx_syslog_cleanup(void *data) | 340 ngx_syslog_cleanup(void *data) |
339 { | 341 { |
340 ngx_syslog_peer_t *peer = data; | 342 ngx_syslog_peer_t *peer = data; |
341 | 343 |
344 /* prevents further use of this peer */ | |
345 peer->busy = 1; | |
346 | |
342 if (ngx_close_socket(peer->conn.fd) == -1) { | 347 if (ngx_close_socket(peer->conn.fd) == -1) { |
343 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno, | 348 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno, |
344 ngx_close_socket_n " failed"); | 349 ngx_close_socket_n " failed"); |
345 } | 350 } |
346 } | 351 } |