X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=klibc%2Fklibc%2Fsyslog.c;h=e9d84d9ddc8f1cf5bab1d2a28ccf5e7e8e4dbf29;hb=0ba5bb106b19d808c2e68af4ff34740854f78290;hp=b031d4f0e7946ac45356220445ca9df7df3f7153;hpb=a41a0e28c2ba0abf99b5e7ea17645ae0e4f05758;p=elogind.git diff --git a/klibc/klibc/syslog.c b/klibc/klibc/syslog.c index b031d4f0e..e9d84d9dd 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]; @@ -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); }