summaryrefslogtreecommitdiff
path: root/klibc/klibc/syslog.c
diff options
context:
space:
mode:
Diffstat (limited to 'klibc/klibc/syslog.c')
-rw-r--r--klibc/klibc/syslog.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/klibc/klibc/syslog.c b/klibc/klibc/syslog.c
index 10a2dce405..592992ba6b 100644
--- a/klibc/klibc/syslog.c
+++ b/klibc/klibc/syslog.c
@@ -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, ...)