[BACK]Return to diag.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libwrap

Annotation of src/lib/libwrap/diag.c, Revision 1.8.50.2

1.8.50.2! riz         1: /*     $NetBSD: diag.c,v 1.8.50.1 2012/04/23 16:48:57 riz Exp $        */
1.3       christos    2:
1.1       mrg         3:  /*
                      4:   * Routines to report various classes of problems. Each report is decorated
                      5:   * with the current context (file name and line number), if available.
1.5       simonb      6:   *
1.1       mrg         7:   * tcpd_warn() reports a problem and proceeds.
1.5       simonb      8:   *
1.1       mrg         9:   * tcpd_jump() reports a problem and jumps.
1.5       simonb     10:   *
1.1       mrg        11:   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
                     12:   */
                     13:
1.3       christos   14: #include <sys/cdefs.h>
1.1       mrg        15: #ifndef lint
1.3       christos   16: #if 0
1.1       mrg        17: static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
1.3       christos   18: #else
1.8.50.2! riz        19: __RCSID("$NetBSD: diag.c,v 1.8.50.1 2012/04/23 16:48:57 riz Exp $");
1.3       christos   20: #endif
1.1       mrg        21: #endif
                     22:
                     23: /* System libraries */
                     24:
                     25: #include <syslog.h>
                     26: #include <stdio.h>
                     27: #include <setjmp.h>
1.7       atatat     28: #include <string.h>
                     29: #include <errno.h>
1.1       mrg        30:
                     31: /* Local stuff */
                     32:
                     33: #include "tcpd.h"
1.8.50.2! riz        34: #include "mystdarg.h"
1.1       mrg        35:
                     36: struct tcpd_context tcpd_context;
                     37: jmp_buf tcpd_buf;
1.3       christos   38:
1.8.50.2! riz        39: static void tcpd_diag __P((int, char *, char *, va_list))
1.6       sommerfe   40:        __attribute__((__format__(__printf__, 3, 0)));
1.1       mrg        41:
                     42: /* tcpd_diag - centralize error reporter */
                     43:
1.8.50.2! riz        44: static void tcpd_diag(severity, tag, format, ap)
        !            45: int     severity;
        !            46: char   *tag;
        !            47: char   *format;
        !            48: va_list ap;
1.1       mrg        49: {
                     50:     char    fmt[BUFSIZ];
1.6       sommerfe   51:     char    buf[BUFSIZ];
1.8.50.2! riz        52:     int     i, o, oerrno;
1.1       mrg        53:
1.7       atatat     54:     /* save errno in case we need it */
                     55:     oerrno = errno;
                     56:
                     57:     /* contruct the tag for the log entry */
1.1       mrg        58:     if (tcpd_context.file)
1.7       atatat     59:        (void)snprintf(buf, sizeof buf, "%s: %s, line %d: ",
1.6       sommerfe   60:                tag, tcpd_context.file, tcpd_context.line);
1.1       mrg        61:     else
1.7       atatat     62:        (void)snprintf(buf, sizeof buf, "%s: ", tag);
                     63:
                     64:     /* change % to %% in tag before appending the format */
                     65:     for (i = 0, o = 0; buf[i] != '\0'; ) {
                     66:        if (buf[i] == '%') {
                     67:            fmt[o] = '%';
                     68:            if (o < sizeof(fmt) - 1)
                     69:                o++;
                     70:        }
                     71:        fmt[o] = buf[i++];
                     72:        if (o < sizeof(fmt) - 1)
                     73:            o++;
                     74:     }
                     75:
                     76:     /* append format and force null termination */
                     77:     fmt[o] = '\0';
1.8       jrf        78:     (void)strlcat(fmt, format, sizeof(fmt) - o);
1.7       atatat     79:
                     80:     errno = oerrno;
                     81:     vsyslog(severity, fmt, ap);
1.1       mrg        82: }
                     83:
                     84: /* tcpd_warn - report problem of some sort and proceed */
                     85:
1.8.50.2! riz        86: void    VARARGS(tcpd_warn, char *, format)
1.1       mrg        87: {
                     88:     va_list ap;
                     89:
1.8.50.2! riz        90:     VASTART(ap, char *, format);
1.1       mrg        91:     tcpd_diag(LOG_ERR, "warning", format, ap);
1.8.50.2! riz        92:     VAEND(ap);
1.1       mrg        93: }
                     94:
                     95: /* tcpd_jump - report serious problem and jump */
                     96:
1.8.50.2! riz        97: void    VARARGS(tcpd_jump, char *, format)
1.1       mrg        98: {
                     99:     va_list ap;
                    100:
1.8.50.2! riz       101:     VASTART(ap, char *, format);
1.1       mrg       102:     tcpd_diag(LOG_ERR, "error", format, ap);
1.8.50.2! riz       103:     VAEND(ap);
1.1       mrg       104:     longjmp(tcpd_buf, AC_ERROR);
                    105: }

CVSweb <webmaster@jp.NetBSD.org>