#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
#else
__RCSID("$NetBSD: diag.c,v 1.18 2024/02/09 22:08:31 andvar Exp $");
#endif
#endif
#include <syslog.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>
#include <errno.h>
#include "tcpd.h"
#include "expandm.h"
struct tcpd_context tcpd_context;
jmp_buf tcpd_buf;
static void tcpd_diag(int, const char *, const char *, va_list)
__sysloglike(3,0);
static void
tcpd_diag(int severity, const char *tag, const char *fmt, va_list ap)
{
char *buf, *bufx;
if (vasprintf(&buf, expandm(fmt, NULL, &bufx), ap) == -1)
buf = __UNCONST(fmt);
free(bufx);
if (tcpd_context.file)
syslog(severity, "%s: %s, line %d: %s",
tag, tcpd_context.file, tcpd_context.line, buf);
else
syslog(severity, "%s: %s", tag, buf);
if (buf != fmt)
free(buf);
}
void
tcpd_warn(const char *format, ...)
{
va_list ap;
va_start(ap, format);
tcpd_diag(LOG_ERR, "warning", format, ap);
va_end(ap);
}
void
tcpd_jump(const char *format, ...)
{
va_list ap;
va_start(ap, format);
tcpd_diag(LOG_ERR, "error", format, ap);
va_end(ap);
longjmp(tcpd_buf, AC_ERROR);
}