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