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