if (!(opt & LOG_NDELAY) || log_f) return;
- fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ fd = socket(AF_UNIX, SOCK_DGRAM, 0);
fcntl(fd, F_SETFD, FD_CLOEXEC);
if (connect(fd, (void *)&log_addr, sizeof(short) + sizeof "/dev/log") < 0)
close(fd);
void syslog(int priority, const char *message, ...)
{
- struct sigaction sa;
+ sigset_t set, oldset;
va_list ap;
char timebuf[16];
time_t now;
return;
}
- memset(&sa, 0, sizeof sa);
- sa.sa_handler = SIG_IGN;
- if (sigaction(SIGPIPE, &sa, &sa) < 0) {
- // we must abandon logging or we might cause SIGPIPE
- UNLOCK(&lock);
- return;
- }
+ sigemptyset(&set);
+ sigaddset(&set, SIGPIPE);
+ pthread_sigmask(SIG_BLOCK, &set, &oldset);
now = time(NULL);
gmtime_r(&now, &tm);
// Note: LOG_CONS is not supported because it is annoying!!
// syslogd will send messages to console if it deems them appropriate!
- sigaction(SIGPIPE, &sa, NULL);
+ /* Clear any possible SIGPIPE generated by the socket write. */
+ sigtimedwait(&set, 0, (struct timespec [1]){0}) || (perror("x"),1);
+ pthread_sigmask(SIG_SETMASK, &oldset, 0);
UNLOCK(&lock);
}