about summary refs log tree commit diff
path: root/src/misc/syslog.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-13 17:24:25 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-13 17:24:25 -0400
commita444ee34103bb06dbcf6ddfa10abd7712982b090 (patch)
treea9ce323590a3f13eba1aa3eb03bd6a7de0c4a3e9 /src/misc/syslog.c
parent07e865cc5afb11e6e882e998306ab0f7fb64357e (diff)
downloadmusl-a444ee34103bb06dbcf6ddfa10abd7712982b090.tar.gz
musl-a444ee34103bb06dbcf6ddfa10abd7712982b090.tar.xz
musl-a444ee34103bb06dbcf6ddfa10abd7712982b090.zip
fix syslog (corrected SIGPIPE blocking, and using dgram instead of stream)
it actually appears the hacks to block SIGPIPE are probably not
necessary, and potentially harmful. if i can confirm this, i'll remove
them.
Diffstat (limited to 'src/misc/syslog.c')
-rw-r--r--src/misc/syslog.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/misc/syslog.c b/src/misc/syslog.c
index 4809d2da..6fc6f4d8 100644
--- a/src/misc/syslog.c
+++ b/src/misc/syslog.c
@@ -49,7 +49,7 @@ static void __openlog(const char *ident, int opt, int facility)
 
 	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);
@@ -65,7 +65,7 @@ void openlog(const char *ident, int opt, int facility)
 
 void syslog(int priority, const char *message, ...)
 {
-	struct sigaction sa;
+	sigset_t set, oldset;
 	va_list ap;
 	char timebuf[16];
 	time_t now;
@@ -83,13 +83,9 @@ void syslog(int priority, const char *message, ...)
 		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);
@@ -109,7 +105,9 @@ void syslog(int priority, const char *message, ...)
 	// 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);
 }