[git commit nptl] syslog: use send(MSG_NOSIGNAL) instead of write, thus no need to handle SIGPIPE

Denys Vlasenko vda.linux at googlemail.com
Mon Dec 14 16:03:34 UTC 2009


commit: http://git.uclibc.org/uClibc/commit/?id=6732cb1ae137d7af17eb911004ba904badba1b85
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/nptl

Size changes by this and previous change:

text           data     bss     dec     hex filename
1151             13       2    1166     48e libc/misc/syslog/syslog.o
1093             10       2    1105     451 libc/misc/syslog/syslog.o
1047             10       2    1059     423 libc/misc/syslog/syslog.o

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 libc/misc/syslog/syslog.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/libc/misc/syslog/syslog.c b/libc/misc/syslog/syslog.c
index f66ba8f..b10a556 100644
--- a/libc/misc/syslog/syslog.c
+++ b/libc/misc/syslog/syslog.c
@@ -85,6 +85,10 @@
 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
 
 
+/* !glibc_compat: glibc uses argv[0] by default
+ * (default: if there was no openlog or if openlog passed NULL),
+ * not string "syslog"
+ */
 static const char *LogTag = "syslog";   /* string to tag the entry with */
 static int       LogFile = -1;          /* fd for log */
 static smalluint connected;             /* have done connect */
@@ -188,16 +192,11 @@ vsyslog(int pri, const char *fmt, va_list ap)
 	int fd, saved_errno;
 	int rc;
 	char tbuf[1024]; /* syslogd is unable to handle longer messages */
-	struct sigaction action;
 
 	/* Just throw out this message if pri has bad bits. */
 	if ((pri & ~(LOG_PRIMASK|LOG_FACMASK)) != 0)
 		return;
 
-	memset(&action, 0, sizeof(action));
-	action.sa_handler = closelog_intern;
-	sigaction(SIGPIPE, &action, &action);
-
 	saved_errno = errno;
 
 	__UCLIBC_MUTEX_LOCK(mylock);
@@ -268,7 +267,8 @@ vsyslog(int pri, const char *fmt, va_list ap)
 	*last_chr = '\0';
 	if (LogFile >= 0) {
 		do {
-			rc = write(LogFile, p, last_chr + 1 - p);
+			/* can't just use write, it can result in SIGPIPE */
+			rc = send(LogFile, p, last_chr + 1 - p, MSG_NOSIGNAL);
 			if (rc < 0) {
 				/* I don't think looping forever on EAGAIN is a good idea.
 				 * Imagine that syslogd is SIGSTOPed... */
@@ -302,7 +302,6 @@ vsyslog(int pri, const char *fmt, va_list ap)
 
  getout:
 	__UCLIBC_MUTEX_UNLOCK(mylock);
-	sigaction(SIGPIPE, &action, NULL);
 }
 libc_hidden_def(vsyslog)
 
-- 
1.6.3.3



More information about the uClibc-cvs mailing list