Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1404909732-83885-1-git-send-email-clement.vasseur@gmail.com>
Date: Wed,  9 Jul 2014 14:42:12 +0200
From: Clément Vasseur <clement.vasseur@...il.com>
To: musl@...ts.openwall.com
Subject: [PATCH] implement the LOG_PERROR option in syslog

Since musl defines this option in its header file, maybe it should
actually do something.
---
 src/misc/syslog.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/misc/syslog.c b/src/misc/syslog.c
index 57f1d75..2b0c73b 100644
--- a/src/misc/syslog.c
+++ b/src/misc/syslog.c
@@ -79,7 +79,7 @@ static void _vsyslog(int priority, const char *message, va_list ap)
 	char buf[256];
 	int errno_save = errno;
 	int pid;
-	int l, l2;
+	int l, l1, l2, l3;
 
 	if (log_fd < 0) {
 		__openlog();
@@ -93,14 +93,16 @@ static void _vsyslog(int priority, const char *message, va_list ap)
 	strftime(timebuf, sizeof timebuf, "%b %e %T", &tm);
 
 	pid = (log_opt & LOG_PID) ? getpid() : 0;
-	l = snprintf(buf, sizeof buf, "<%d>%s %s%s%.0d%s: ",
-		priority, timebuf, log_ident, "["+!pid, pid, "]"+!pid);
+	l1 = snprintf(buf, sizeof buf, "<%d>%s ", priority, timebuf);
+	l2 = snprintf(buf+l1, sizeof buf - l1, "%s%s%.0d%s: ",
+		log_ident, "["+!pid, pid, "]"+!pid);
 	errno = errno_save;
-	l2 = vsnprintf(buf+l, sizeof buf - l, message, ap);
-	if (l2 >= 0) {
-		if (l2 >= sizeof buf - l) l = sizeof buf - 1;
-		else l += l2;
+	l3 = vsnprintf(buf+l1+l2, sizeof buf - (l1+l2), message, ap);
+	if (l3 >= 0) {
+		if (l3 >= sizeof buf - (l1+l2)) l = sizeof buf - 1;
+		else l = l1+l2+l3;
 		if (buf[l-1] != '\n') buf[l++] = '\n';
+		if (log_opt & LOG_PERROR) write(2, buf+l1, l-l1);
 		send(log_fd, buf, l, 0);
 	}
 }
-- 
2.0.1

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.