mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] implement the LOG_PERROR option in syslog
@ 2014-07-09 12:42 Clément Vasseur
  2014-07-11  4:49 ` Rich Felker
  0 siblings, 1 reply; 7+ messages in thread
From: Clément Vasseur @ 2014-07-09 12:42 UTC (permalink / raw)
  To: musl

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



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-07-12 13:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-09 12:42 [PATCH] implement the LOG_PERROR option in syslog Clément Vasseur
2014-07-11  4:49 ` Rich Felker
2014-07-12  0:55   ` Rich Felker
2014-07-12  1:08     ` Clément Vasseur
2014-07-12  1:15     ` Rich Felker
2014-07-12  8:33       ` Laurent Bercot
2014-07-12 13:58         ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).