Reapply formatting cleanup

This commit is contained in:
joerg 2011-09-16 15:36:00 +00:00
parent 9438a85a85
commit 6a878ae49f
1 changed files with 21 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: log.c,v 1.5 2011/09/07 17:49:19 christos Exp $ */
/* $NetBSD: log.c,v 1.6 2011/09/16 15:36:00 joerg Exp $ */
/* $OpenBSD: log.c,v 1.42 2011/06/17 21:44:30 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@ -36,7 +36,7 @@
*/
#include "includes.h"
__RCSID("$NetBSD: log.c,v 1.5 2011/09/07 17:49:19 christos Exp $");
__RCSID("$NetBSD: log.c,v 1.6 2011/09/16 15:36:00 joerg Exp $");
#include <sys/types.h>
#include <sys/uio.h>
@ -325,8 +325,10 @@ do_log(LogLevel level, const char *fmt, va_list args)
#ifdef SYSLOG_DATA_INIT
struct syslog_data sdata = SYSLOG_DATA_INIT;
#endif
char msgbuf[MSGBUFSIZ];
char msgbuf[MSGBUFSIZ], *msgbufp;
char visbuf[MSGBUFSIZ * 4 + 1];
size_t len, len2;
int len3;
const char *txt = NULL;
int pri = LOG_INFO;
int saved_errno = errno;
@ -369,13 +371,19 @@ do_log(LogLevel level, const char *fmt, va_list args)
pri = LOG_ERR;
break;
}
len = sizeof(msgbuf);
msgbufp = msgbuf;
if (txt != NULL && log_handler == NULL) {
snprintf(visbuf, sizeof(visbuf), "%s: %s", txt, fmt);
vsnprintf(msgbuf, sizeof(msgbuf), visbuf, args);
} else {
vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
len2 = strlen(txt);
if (len2 >= len)
len2 = len - 1;
memcpy(msgbufp, txt, len2);
msgbufp += len2;
*msgbufp++ = '\0';
len -= len2 + 1;
}
strnvis(visbuf, sizeof(visbuf), msgbuf, VIS_SAFE|VIS_OCTAL);
vsnprintf(msgbufp, len, fmt, args);
len3 = strnvis(visbuf, sizeof(visbuf), msgbuf, VIS_SAFE|VIS_OCTAL);
if (log_handler != NULL) {
/* Avoid recursion */
tmp_handler = log_handler;
@ -383,8 +391,11 @@ do_log(LogLevel level, const char *fmt, va_list args)
tmp_handler(level, visbuf, log_handler_ctx);
log_handler = tmp_handler;
} else if (log_on_stderr) {
snprintf(msgbuf, sizeof msgbuf, "%s\r\n", visbuf);
write(STDERR_FILENO, msgbuf, strlen(msgbuf));
struct iovec iov[] = {
{ visbuf, len3 },
{ __UNCONST("\r\n"), 2 },
};
writev(STDERR_FILENO, iov, __arraycount(iov));
} else {
#ifdef SYSLOG_DATA_INIT
openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata);