chiark / gitweb /
[PATCH] restore OWNER/GROUP assignment in rule coming from RESULT
[elogind.git] / klibc / klibc / syslog.c
index b031d4f0e7946ac45356220445ca9df7df3f7153..e9d84d9ddc8f1cf5bab1d2a28ccf5e7e8e4dbf29 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];
@@ -40,20 +40,15 @@ void openlog(const char *ident, int option, int facility)
   id[MAXID] = '\0';            /* Make sure it's null-terminated */
 }
 
-void syslog(int prio, const char *format, ...)
+void vsyslog(int prio, const char *format, va_list ap)
 {
-  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,14 +56,25 @@ void syslog(int prio, const char *format, ...)
 
   if ( *id )
     len += sprintf(buf+3, "%s: ", id);
-  
-  va_start(ap, format);
-  rv = vsnprintf(buf+len, BUFLEN-len, format, ap);
-  va_end(ap);
 
-  len += rv;
+  len += vsnprintf(buf+len, BUFLEN-len, format, ap);
+
   if ( len > BUFLEN-1 ) len = BUFLEN-1;
-  buf[len] = '\n';
+  if (buf[len-1] != '\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, ...)
+{
+  va_list ap;
+
+  va_start(ap, format);
+  vsyslog(prio, format, ap);
+  va_end(ap);
 }