Rearrange the way syslog() is used. Some messages include %m which
syslog understands, but vsnprintf() does not.
This commit is contained in:
parent
a5480e24b4
commit
349f0e356b
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: diag.c,v 1.6 2000/10/04 16:24:49 sommerfeld Exp $ */
|
||||
/* $NetBSD: diag.c,v 1.7 2001/09/24 17:55:47 atatat Exp $ */
|
||||
|
||||
/*
|
||||
* Routines to report various classes of problems. Each report is decorated
|
||||
@ -16,7 +16,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
|
||||
#else
|
||||
__RCSID("$NetBSD: diag.c,v 1.6 2000/10/04 16:24:49 sommerfeld Exp $");
|
||||
__RCSID("$NetBSD: diag.c,v 1.7 2001/09/24 17:55:47 atatat Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -25,6 +25,8 @@ __RCSID("$NetBSD: diag.c,v 1.6 2000/10/04 16:24:49 sommerfeld Exp $");
|
||||
#include <syslog.h>
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* Local stuff */
|
||||
|
||||
@ -47,15 +49,37 @@ va_list ap;
|
||||
{
|
||||
char fmt[BUFSIZ];
|
||||
char buf[BUFSIZ];
|
||||
int i, o, oerrno;
|
||||
|
||||
vsnprintf(buf, sizeof(buf), format, ap);
|
||||
|
||||
/* save errno in case we need it */
|
||||
oerrno = errno;
|
||||
|
||||
/* contruct the tag for the log entry */
|
||||
if (tcpd_context.file)
|
||||
(void)snprintf(fmt, sizeof fmt, "%s: %s, line %d",
|
||||
(void)snprintf(buf, sizeof buf, "%s: %s, line %d: ",
|
||||
tag, tcpd_context.file, tcpd_context.line);
|
||||
else
|
||||
(void)snprintf(fmt, sizeof fmt, "%s", tag);
|
||||
syslog(severity, "%s: %s", fmt, buf);
|
||||
(void)snprintf(buf, sizeof buf, "%s: ", tag);
|
||||
|
||||
/* change % to %% in tag before appending the format */
|
||||
for (i = 0, o = 0; buf[i] != '\0'; ) {
|
||||
if (buf[i] == '%') {
|
||||
fmt[o] = '%';
|
||||
if (o < sizeof(fmt) - 1)
|
||||
o++;
|
||||
}
|
||||
fmt[o] = buf[i++];
|
||||
if (o < sizeof(fmt) - 1)
|
||||
o++;
|
||||
}
|
||||
|
||||
/* append format and force null termination */
|
||||
fmt[o] = '\0';
|
||||
strncat(fmt, format, sizeof(fmt) - o);
|
||||
fmt[sizeof(fmt) - 1] = '\0';
|
||||
|
||||
errno = oerrno;
|
||||
vsyslog(severity, fmt, ap);
|
||||
}
|
||||
|
||||
/* tcpd_warn - report problem of some sort and proceed */
|
||||
|
Loading…
Reference in New Issue
Block a user