Home | History | Annotate | Line # | Download | only in libwrap
diag.c revision 1.3
      1 /*	$NetBSD: diag.c,v 1.3 1997/10/09 21:20:21 christos Exp $	*/
      2 
      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.
      6   *
      7   * tcpd_warn() reports a problem and proceeds.
      8   *
      9   * tcpd_jump() reports a problem and jumps.
     10   *
     11   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
     12   */
     13 
     14 #include <sys/cdefs.h>
     15 #ifndef lint
     16 #if 0
     17 static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
     18 #else
     19 __RCSID("$NetBSD: diag.c,v 1.3 1997/10/09 21:20:21 christos Exp $");
     20 #endif
     21 #endif
     22 
     23 /* System libraries */
     24 
     25 #include <syslog.h>
     26 #include <stdio.h>
     27 #include <setjmp.h>
     28 
     29 /* Local stuff */
     30 
     31 #include "tcpd.h"
     32 #include "mystdarg.h"
     33 
     34 struct tcpd_context tcpd_context;
     35 jmp_buf tcpd_buf;
     36 
     37 static void tcpd_diag __P((int, char *, char *, va_list));
     38 
     39 /* tcpd_diag - centralize error reporter */
     40 
     41 static void tcpd_diag(severity, tag, format, ap)
     42 int     severity;
     43 char   *tag;
     44 char   *format;
     45 va_list ap;
     46 {
     47     char    fmt[BUFSIZ];
     48 
     49     if (tcpd_context.file)
     50 	(void)snprintf(fmt, sizeof fmt, "%s: %s, line %d: %s",
     51 		tag, tcpd_context.file, tcpd_context.line, format);
     52     else
     53 	(void)snprintf(fmt, sizeof fmt, "%s: %s", tag, format);
     54     vsyslog(severity, fmt, ap);
     55 }
     56 
     57 /* tcpd_warn - report problem of some sort and proceed */
     58 
     59 void    VARARGS(tcpd_warn, char *, format)
     60 {
     61     va_list ap;
     62 
     63     VASTART(ap, char *, format);
     64     tcpd_diag(LOG_ERR, "warning", format, ap);
     65     VAEND(ap);
     66 }
     67 
     68 /* tcpd_jump - report serious problem and jump */
     69 
     70 void    VARARGS(tcpd_jump, char *, format)
     71 {
     72     va_list ap;
     73 
     74     VASTART(ap, char *, format);
     75     tcpd_diag(LOG_ERR, "error", format, ap);
     76     VAEND(ap);
     77     longjmp(tcpd_buf, AC_ERROR);
     78 }
     79