Remove building with NOCRYPTO option
[minix3.git] / lib / libwrap / diag.c
blobcaacb72ccb19fb003717b9bb33c9d52a4166e117
1 /* $NetBSD: diag.c,v 1.10 2012/03/22 22:58:15 joerg Exp $ */
3 /*
4 * Routines to report various classes of problems. Each report is decorated
5 * with the current context (file name and line number), if available.
6 *
7 * tcpd_warn() reports a problem and proceeds.
8 *
9 * tcpd_jump() reports a problem and jumps.
11 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
14 #include <sys/cdefs.h>
15 #ifndef lint
16 #if 0
17 static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
18 #else
19 __RCSID("$NetBSD: diag.c,v 1.10 2012/03/22 22:58:15 joerg Exp $");
20 #endif
21 #endif
23 /* System libraries */
25 #include <syslog.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <setjmp.h>
30 #include <string.h>
31 #include <errno.h>
33 /* Local stuff */
35 #include "tcpd.h"
37 struct tcpd_context tcpd_context;
38 jmp_buf tcpd_buf;
40 static void tcpd_diag(int, const char *, const char *, va_list)
41 __printflike(3,0);
43 /* tcpd_diag - centralize error reporter */
45 static void
46 tcpd_diag(int severity, const char *tag, const char *fmt, va_list ap)
48 char *buf;
49 int oerrno;
51 /* save errno in case we need it */
52 oerrno = errno;
54 if (vasprintf(&buf, fmt, ap) == -1)
55 buf = __UNCONST(fmt);
57 errno = oerrno;
59 /* contruct the tag for the log entry */
60 if (tcpd_context.file)
61 syslog(severity, "%s: %s, line %d: %s",
62 tag, tcpd_context.file, tcpd_context.line, buf);
63 else
64 syslog(severity, "%s: %s", tag, buf);
66 if (buf != fmt)
67 free(buf);
70 /* tcpd_warn - report problem of some sort and proceed */
72 void
73 tcpd_warn(const char *format, ...)
75 va_list ap;
77 va_start(ap, format);
78 tcpd_diag(LOG_ERR, "warning", format, ap);
79 va_end(ap);
82 /* tcpd_jump - report serious problem and jump */
84 void
85 tcpd_jump(const char *format, ...)
87 va_list ap;
89 va_start(ap, format);
90 tcpd_diag(LOG_ERR, "error", format, ap);
91 va_end(ap);
92 longjmp(tcpd_buf, AC_ERROR);