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