1 /* $NetBSD: diag.c,v 1.6 2000/10/04 16:24:49 sommerfeld 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.6 2000/10/04 16:24:49 sommerfeld 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 __attribute__((__format__(__printf__, 3, 0))); 39 40 /* tcpd_diag - centralize error reporter */ 41 42 static void tcpd_diag(severity, tag, format, ap) 43 int severity; 44 char *tag; 45 char *format; 46 va_list ap; 47 { 48 char fmt[BUFSIZ]; 49 char buf[BUFSIZ]; 50 51 vsnprintf(buf, sizeof(buf), format, ap); 52 53 if (tcpd_context.file) 54 (void)snprintf(fmt, sizeof fmt, "%s: %s, line %d", 55 tag, tcpd_context.file, tcpd_context.line); 56 else 57 (void)snprintf(fmt, sizeof fmt, "%s", tag); 58 syslog(severity, "%s: %s", fmt, buf); 59 } 60 61 /* tcpd_warn - report problem of some sort and proceed */ 62 63 void VARARGS(tcpd_warn, char *, format) 64 { 65 va_list ap; 66 67 VASTART(ap, char *, format); 68 tcpd_diag(LOG_ERR, "warning", format, ap); 69 VAEND(ap); 70 } 71 72 /* tcpd_jump - report serious problem and jump */ 73 74 void VARARGS(tcpd_jump, char *, format) 75 { 76 va_list ap; 77 78 VASTART(ap, char *, format); 79 tcpd_diag(LOG_ERR, "error", format, ap); 80 VAEND(ap); 81 longjmp(tcpd_buf, AC_ERROR); 82 } 83