chiark / gitweb /
[PATCH] Remove the last klibc specific line from the main udev code
[elogind.git] / klibc / klibc / syslog.c
index 10a2dce40543dd5c647f61f0b02b1cb0288db02b..592992ba6b2a82e710307c8f298cdebada689db0 100644 (file)
@@ -18,7 +18,7 @@
 #define LOGDEV "/dev/kmsg"
 
 /* Max length of ID string */
-#define MAXID 31
+#define MAXID 31               /* MAXID+6 must be < BUFLEN */
 
 int __syslog_fd = -1;
 static char id[MAXID+1];
@@ -43,16 +43,12 @@ void openlog(const char *ident, int option, int facility)
 void vsyslog(int prio, const char *format, va_list ap)
 {
   char buf[BUFLEN];
-  int rv, len;
+  int len;
   int fd;
 
   if ( __syslog_fd == -1 )
     openlog(NULL, 0, 0);
 
-  fd = __syslog_fd;
-  if ( fd == -1 )
-    fd = 2;                    /* Failed to open log, write to stderr */
-
   buf[0] = '<';
   buf[1] = LOG_PRI(prio)+'0';
   buf[2] = '>';
@@ -61,13 +57,16 @@ void vsyslog(int prio, const char *format, va_list ap)
   if ( *id )
     len += sprintf(buf+3, "%s: ", id);
 
-  rv = vsnprintf(buf+len, BUFLEN-len, format, ap);
+  len += vsnprintf(buf+len, BUFLEN-len, format, ap);
 
-  len += rv;
   if ( len > BUFLEN-1 ) len = BUFLEN-1;
-  buf[len] = '\n';
+  buf[len++] = '\n';
+
+  fd = __syslog_fd;
+  if ( fd == -1 )
+    fd = 2;                    /* Failed to open log, write to stderr */
 
-  write(fd, buf, len+1);
+  write(fd, buf, len);
 }
 
 void syslog(int prio, const char *format, ...)