Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libwrap Rearrange the way syslog() is used. Some messag...



details:   https://anonhg.NetBSD.org/src/rev/699d9e8c3b16
branches:  trunk
changeset: 515428:699d9e8c3b16
user:      atatat <atatat%NetBSD.org@localhost>
date:      Mon Sep 24 17:55:47 2001 +0000

description:
Rearrange the way syslog() is used.  Some messages include %m which
syslog understands, but vsnprintf() does not.

diffstat:

 lib/libwrap/diag.c |  38 +++++++++++++++++++++++++++++++-------
 1 files changed, 31 insertions(+), 7 deletions(-)

diffs (70 lines):

diff -r 7dc7b7edd31c -r 699d9e8c3b16 lib/libwrap/diag.c
--- a/lib/libwrap/diag.c        Mon Sep 24 17:00:52 2001 +0000
+++ b/lib/libwrap/diag.c        Mon Sep 24 17:55:47 2001 +0000
@@ -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 @@
 #include <syslog.h>
 #include <stdio.h>
 #include <setjmp.h>
+#include <string.h>
+#include <errno.h>
 
 /* Local stuff */
 
@@ -47,15 +49,37 @@
 {
     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 */



Home | Main Index | Thread Index | Old Index