Fix mdoc(7)/man(7) mix up.
[netbsd-mini2440.git] / lib / libwrap / diag.c
blob1990419ad529aed564d73dbe7687e68aac5dc254
1 /* $NetBSD: diag.c,v 1.7 2001/09/24 17:55:47 atatat 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.7 2001/09/24 17:55:47 atatat Exp $");
20 #endif
21 #endif
23 /* System libraries */
25 #include <syslog.h>
26 #include <stdio.h>
27 #include <setjmp.h>
28 #include <string.h>
29 #include <errno.h>
31 /* Local stuff */
33 #include "tcpd.h"
34 #include "mystdarg.h"
36 struct tcpd_context tcpd_context;
37 jmp_buf tcpd_buf;
39 static void tcpd_diag __P((int, char *, char *, va_list))
40 __attribute__((__format__(__printf__, 3, 0)));
42 /* tcpd_diag - centralize error reporter */
44 static void tcpd_diag(severity, tag, format, ap)
45 int severity;
46 char *tag;
47 char *format;
48 va_list ap;
50 char fmt[BUFSIZ];
51 char buf[BUFSIZ];
52 int i, o, oerrno;
54 /* save errno in case we need it */
55 oerrno = errno;
57 /* contruct the tag for the log entry */
58 if (tcpd_context.file)
59 (void)snprintf(buf, sizeof buf, "%s: %s, line %d: ",
60 tag, tcpd_context.file, tcpd_context.line);
61 else
62 (void)snprintf(buf, sizeof buf, "%s: ", tag);
64 /* change % to %% in tag before appending the format */
65 for (i = 0, o = 0; buf[i] != '\0'; ) {
66 if (buf[i] == '%') {
67 fmt[o] = '%';
68 if (o < sizeof(fmt) - 1)
69 o++;
71 fmt[o] = buf[i++];
72 if (o < sizeof(fmt) - 1)
73 o++;
76 /* append format and force null termination */
77 fmt[o] = '\0';
78 (void)strlcat(fmt, format, sizeof(fmt) - o);
80 errno = oerrno;
81 vsyslog(severity, fmt, ap);
84 /* tcpd_warn - report problem of some sort and proceed */
86 void VARARGS(tcpd_warn, char *, format)
88 va_list ap;
90 VASTART(ap, char *, format);
91 tcpd_diag(LOG_ERR, "warning", format, ap);
92 VAEND(ap);
95 /* tcpd_jump - report serious problem and jump */
97 void VARARGS(tcpd_jump, char *, format)
99 va_list ap;
101 VASTART(ap, char *, format);
102 tcpd_diag(LOG_ERR, "error", format, ap);
103 VAEND(ap);
104 longjmp(tcpd_buf, AC_ERROR);