- Fix indentation in VarFind()
[dragonfly.git] / contrib / tcp_wrappers / diag.c
1  /*
2   * Routines to report various classes of problems. Each report is decorated
3   * with the current context (file name and line number), if available.
4   * 
5   * tcpd_warn() reports a problem and proceeds.
6   * 
7   * tcpd_jump() reports a problem and jumps.
8   * 
9   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
10   */
11
12 #ifndef lint
13 static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
14 #endif
15
16 /* System libraries */
17
18 #include <syslog.h>
19 #include <stdio.h>
20 #include <setjmp.h>
21
22 /* Local stuff */
23
24 #include "tcpd.h"
25 #include "mystdarg.h"
26
27 struct tcpd_context tcpd_context;
28 jmp_buf tcpd_buf;
29
30 /* tcpd_diag - centralize error reporter */
31
32 static void tcpd_diag(severity, tag, format, ap)
33 int     severity;
34 char   *tag;
35 char   *format;
36 va_list ap;
37 {
38     char    fmt[BUFSIZ];
39
40     if (tcpd_context.file)
41         sprintf(fmt, "%s: %s, line %d: %s",
42                 tag, tcpd_context.file, tcpd_context.line, format);
43     else
44         sprintf(fmt, "%s: %s", tag, format);
45     vsyslog(severity, fmt, ap);
46 }
47
48 /* tcpd_warn - report problem of some sort and proceed */
49
50 void    VARARGS(tcpd_warn, char *, format)
51 {
52     va_list ap;
53
54     VASTART(ap, char *, format);
55     tcpd_diag(LOG_ERR, "warning", format, ap);
56     VAEND(ap);
57 }
58
59 /* tcpd_jump - report serious problem and jump */
60
61 void    VARARGS(tcpd_jump, char *, format)
62 {
63     va_list ap;
64
65     VASTART(ap, char *, format);
66     tcpd_diag(LOG_ERR, "error", format, ap);
67     VAEND(ap);
68     longjmp(tcpd_buf, AC_ERROR);
69 }