diff options
author | Rich Felker <dalias@aerifal.cx> | 2015-01-09 00:09:54 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2015-01-09 00:09:54 -0500 |
commit | c574321d75f035ff6d2c18dfb7e3f70db60ba7bd (patch) | |
tree | c6dd514c1945362eb72f30b78ea03d0a10f8a217 /src/misc | |
parent | 11ac2a6e811ff0860c7d3b3daf035dc6748fb4d4 (diff) | |
download | musl-c574321d75f035ff6d2c18dfb7e3f70db60ba7bd.tar.gz musl-c574321d75f035ff6d2c18dfb7e3f70db60ba7bd.tar.xz musl-c574321d75f035ff6d2c18dfb7e3f70db60ba7bd.zip |
check for connect failure in syslog log opening
based on patch by Dima Krasner, with minor improvements for code size. connect can fail if there is no listening syslogd, in which case a useless socket was kept open, preventing subsequent syslog call from attempting to connect again.
Diffstat (limited to 'src/misc')
-rw-r--r-- | src/misc/syslog.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/misc/syslog.c b/src/misc/syslog.c index fdf90ba9..fbce4bcd 100644 --- a/src/misc/syslog.c +++ b/src/misc/syslog.c @@ -46,8 +46,12 @@ void closelog(void) static void __openlog() { - log_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); - if (log_fd >= 0) connect(log_fd, (void *)&log_addr, sizeof log_addr); + int fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); + if (fd < 0) return; + if (connect(fd, (void *)&log_addr, sizeof log_addr) < 0) + close(fd); + else + log_fd = fd; } void openlog(const char *ident, int opt, int facility) |