summaryrefslogtreecommitdiffstats
path: root/usr.sbin/smtpd/log.c
diff options
context:
space:
mode:
authoreric <eric@openbsd.org>2014-07-08 10:30:52 +0000
committereric <eric@openbsd.org>2014-07-08 10:30:52 +0000
commitbe216e8f9daa3f0825d392a21ae4dbaa63c501e6 (patch)
tree978bee9dd4ddb77c73760cf31cb74b1efb77b881 /usr.sbin/smtpd/log.c
parentStop using uvm_extern.h to fetch uvm_param.h; so define local versions (diff)
downloadwireguard-openbsd-be216e8f9daa3f0825d392a21ae4dbaa63c501e6.tar.xz
wireguard-openbsd-be216e8f9daa3f0825d392a21ae4dbaa63c501e6.zip
Change fatal/fatalx to use a format string. Expand in a static buffer
to cope with low-memory situations. ok gilles@ chl@
Diffstat (limited to 'usr.sbin/smtpd/log.c')
-rw-r--r--usr.sbin/smtpd/log.c43
1 files changed, 32 insertions, 11 deletions
diff --git a/usr.sbin/smtpd/log.c b/usr.sbin/smtpd/log.c
index b553f2a5160..8c20f3f5c02 100644
--- a/usr.sbin/smtpd/log.c
+++ b/usr.sbin/smtpd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.15 2013/05/24 17:03:14 eric Exp $ */
+/* $OpenBSD: log.c,v 1.16 2014/07/08 10:30:52 eric Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -158,24 +158,45 @@ log_trace(int mask, const char *emsg, ...)
}
}
-void
-fatal(const char *emsg)
+static void
+fatal_arg(const char *emsg, va_list ap)
{
+#define FATALBUFSIZE 1024
+ static char ebuffer[FATALBUFSIZE];
+
if (emsg == NULL)
- logit(LOG_CRIT, "fatal: %s", strerror(errno));
- else
- if (errno)
- logit(LOG_CRIT, "fatal: %s: %s",
- emsg, strerror(errno));
+ (void)strlcpy(ebuffer, strerror(errno), sizeof ebuffer);
+ else {
+ if (errno) {
+ (void)vsnprintf(ebuffer, sizeof ebuffer, emsg, ap);
+ (void)strlcat(ebuffer, ": ", sizeof ebuffer);
+ (void)strlcat(ebuffer, strerror(errno), sizeof ebuffer);
+ }
else
- logit(LOG_CRIT, "fatal: %s", emsg);
+ (void)vsnprintf(ebuffer, sizeof ebuffer, emsg, ap);
+ }
+ logit(LOG_CRIT, "fatal: %s", ebuffer);
+}
+void
+fatal(const char *emsg, ...)
+{
+ va_list ap;
+
+ va_start(ap, emsg);
+ fatal_arg(emsg, ap);
+ va_end(ap);
exit(1);
}
void
-fatalx(const char *emsg)
+fatalx(const char *emsg, ...)
{
+ va_list ap;
+
errno = 0;
- fatal(emsg);
+ va_start(ap, emsg);
+ fatal_arg(emsg, ap);
+ va_end(ap);
+ exit(1);
}