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