1 /* $NetBSD: diag.c,v 1.7 2001/09/24 17:55:47 atatat Exp $ */
4 * Routines to report various classes of problems. Each report is decorated
5 * with the current context (file name and line number), if available.
7 * tcpd_warn() reports a problem and proceeds.
9 * tcpd_jump() reports a problem and jumps.
11 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
14 #include <sys/cdefs.h>
17 static char sccsid
[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
19 __RCSID("$NetBSD: diag.c,v 1.7 2001/09/24 17:55:47 atatat Exp $");
23 /* System libraries */
36 struct tcpd_context tcpd_context
;
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
)
54 /* save errno in case we need it */
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
);
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'; ) {
68 if (o
< sizeof(fmt
) - 1)
72 if (o
< sizeof(fmt
) - 1)
76 /* append format and force null termination */
78 (void)strlcat(fmt
, format
, sizeof(fmt
) - o
);
81 vsyslog(severity
, fmt
, ap
);
84 /* tcpd_warn - report problem of some sort and proceed */
86 void VARARGS(tcpd_warn
, char *, format
)
90 VASTART(ap
, char *, format
);
91 tcpd_diag(LOG_ERR
, "warning", format
, ap
);
95 /* tcpd_jump - report serious problem and jump */
97 void VARARGS(tcpd_jump
, char *, format
)
101 VASTART(ap
, char *, format
);
102 tcpd_diag(LOG_ERR
, "error", format
, ap
);
104 longjmp(tcpd_buf
, AC_ERROR
);