Geal / rust-syslog

Send syslog messages from Rust
MIT License
110 stars 55 forks source link

Unix style logger (and possibly others) don't reconnect on send error #21

Open gclinch opened 7 years ago

gclinch commented 7 years ago

This library continues to attempt to send to a broken fd (for example if the syslogd is restarted, causing /dev/log to have a new inode), as seen in this strace snippet:

sendto(3, "<150>Jun 11 21:36:55 syslog-test"..., 47, 0, NULL, 0) = 47
nanosleep({1, 0}, 0x7ffca177d970)       = 0
sendto(3, "<150>Jun 11 21:36:56 syslog-test"..., 47, 0, NULL, 0) = 47
nanosleep({1, 0}, 0x7ffca177d970)       = 0
sendto(3, "<150>Jun 11 21:36:57 syslog-test"..., 47, 0, NULL, 0) = -1 ECONNREFUSED (Connection refused)
nanosleep({1, 0}, 0x7ffca177d970)       = 0
sendto(3, "<150>Jun 11 21:36:58 syslog-test"..., 47, 0, NULL, 0) = -1 ENOTCONN (Transport endpoint is not connected)
nanosleep({1, 0}, 0x7ffca177d970)       = 0
sendto(3, "<150>Jun 11 21:36:59 syslog-test"..., 47, 0, NULL, 0) = -1 ENOTCONN (Transport endpoint is not connected)

Whereas the libc syslog function automatically reconnects:

sendto(3, "<14>Jun 11 21:34:38 syslog-test."..., 47, MSG_NOSIGNAL, NULL, 0) = 47
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
sendto(3, "<14>Jun 11 21:34:39 syslog-test."..., 47, MSG_NOSIGNAL, NULL, 0) = 47
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
sendto(3, "<14>Jun 11 21:34:40 syslog-test."..., 47, MSG_NOSIGNAL, NULL, 0) = -1 ECONNREFUSED (Connection refused)
close(3)                                = 0
socket(PF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 3
connect(3, {sa_family=AF_LOCAL, sun_path="/dev/log"}, 110) = 0
sendto(3, "<14>Jun 11 21:34:40 syslog-test."..., 47, MSG_NOSIGNAL, NULL, 0) = 47
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
sendto(3, "<14>Jun 11 21:34:41 syslog-test."..., 47, MSG_NOSIGNAL, NULL, 0) = 47