summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/smtpd/ca.c4
-rw-r--r--usr.sbin/smtpd/control.c29
-rw-r--r--usr.sbin/smtpd/filter.c4
-rw-r--r--usr.sbin/smtpd/lka.c6
-rw-r--r--usr.sbin/smtpd/log.c139
-rw-r--r--usr.sbin/smtpd/log.h45
-rw-r--r--usr.sbin/smtpd/makemap.c4
-rw-r--r--usr.sbin/smtpd/mta.c4
-rw-r--r--usr.sbin/smtpd/pony.c5
-rw-r--r--usr.sbin/smtpd/queue.c4
-rw-r--r--usr.sbin/smtpd/scheduler_ramqueue.c8
-rw-r--r--usr.sbin/smtpd/smtpctl.c4
-rw-r--r--usr.sbin/smtpd/smtpd.c49
-rw-r--r--usr.sbin/smtpd/smtpd.h4
-rw-r--r--usr.sbin/smtpd/util.c26
15 files changed, 188 insertions, 147 deletions
diff --git a/usr.sbin/smtpd/ca.c b/usr.sbin/smtpd/ca.c
index a7e7b03013a..b287f8ac3a4 100644
--- a/usr.sbin/smtpd/ca.c
+++ b/usr.sbin/smtpd/ca.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ca.c,v 1.25 2016/09/08 12:06:43 eric Exp $ */
+/* $OpenBSD: ca.c,v 1.26 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org>
@@ -248,7 +248,7 @@ ca_imsg(struct mproc *p, struct imsg *imsg)
m_msg(&m, imsg);
m_get_int(&m, &v);
m_end(&m);
- log_verbose(v);
+ log_trace_verbose(v);
return;
case IMSG_CTL_PROFILE:
m_msg(&m, imsg);
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c
index f5ea8296c75..6e4c6e98cf3 100644
--- a/usr.sbin/smtpd/control.c
+++ b/usr.sbin/smtpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.117 2016/09/08 12:06:43 eric Exp $ */
+/* $OpenBSD: control.c,v 1.118 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2012 Gilles Chehade <gilles@poolp.org>
@@ -504,14 +504,13 @@ control_dispatch_ext(struct mproc *p, struct imsg *imsg)
if (c->euid)
goto badcred;
- if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(verbose))
+ if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v))
goto badcred;
memcpy(&v, imsg->data, sizeof(v));
- verbose = v;
- log_verbose(verbose);
+ log_trace_verbose(v);
- control_broadcast_verbose(IMSG_CTL_VERBOSE, verbose);
+ control_broadcast_verbose(IMSG_CTL_VERBOSE, v);
m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
return;
@@ -520,14 +519,14 @@ control_dispatch_ext(struct mproc *p, struct imsg *imsg)
if (c->euid)
goto badcred;
- if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(verbose))
+ if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v))
goto badcred;
memcpy(&v, imsg->data, sizeof(v));
- verbose |= v;
- log_verbose(verbose);
+ tracing |= v;
+ log_trace_verbose(tracing);
- control_broadcast_verbose(IMSG_CTL_VERBOSE, verbose);
+ control_broadcast_verbose(IMSG_CTL_VERBOSE, tracing);
m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
return;
@@ -536,14 +535,14 @@ control_dispatch_ext(struct mproc *p, struct imsg *imsg)
if (c->euid)
goto badcred;
- if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(verbose))
+ if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v))
goto badcred;
memcpy(&v, imsg->data, sizeof(v));
- verbose &= ~v;
- log_verbose(verbose);
+ tracing &= ~v;
+ log_trace_verbose(tracing);
- control_broadcast_verbose(IMSG_CTL_VERBOSE, verbose);
+ control_broadcast_verbose(IMSG_CTL_VERBOSE, tracing);
m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
return;
@@ -552,7 +551,7 @@ control_dispatch_ext(struct mproc *p, struct imsg *imsg)
if (c->euid)
goto badcred;
- if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(verbose))
+ if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v))
goto badcred;
memcpy(&v, imsg->data, sizeof(v));
@@ -567,7 +566,7 @@ control_dispatch_ext(struct mproc *p, struct imsg *imsg)
if (c->euid)
goto badcred;
- if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(verbose))
+ if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v))
goto badcred;
memcpy(&v, imsg->data, sizeof(v));
diff --git a/usr.sbin/smtpd/filter.c b/usr.sbin/smtpd/filter.c
index 76f194fffae..fcbdaec7e06 100644
--- a/usr.sbin/smtpd/filter.c
+++ b/usr.sbin/smtpd/filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: filter.c,v 1.24 2016/11/30 11:52:48 eric Exp $ */
+/* $OpenBSD: filter.c,v 1.25 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
@@ -197,7 +197,7 @@ filter_postfork(void)
p->proc = PROC_FILTER;
p->name = xstrdup(filter->name, "filter_postfork");
p->data = proc;
- if (verbose & TRACE_DEBUG)
+ if (tracing & TRACE_DEBUG)
filter_add_arg(filter, "-v");
if (foreground_log)
filter_add_arg(filter, "-d");
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c
index 4c553fd9d18..db9d42aea41 100644
--- a/usr.sbin/smtpd/lka.c
+++ b/usr.sbin/smtpd/lka.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka.c,v 1.197 2016/09/08 12:06:43 eric Exp $ */
+/* $OpenBSD: lka.c,v 1.198 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -321,7 +321,7 @@ lka_imsg(struct mproc *p, struct imsg *imsg)
return;
case IMSG_CONF_END:
- if (verbose & TRACE_TABLES)
+ if (tracing & TRACE_TABLES)
table_dump_all();
/* fork & exec tables that need it */
@@ -354,7 +354,7 @@ lka_imsg(struct mproc *p, struct imsg *imsg)
m_msg(&m, imsg);
m_get_int(&m, &v);
m_end(&m);
- log_verbose(v);
+ log_trace_verbose(v);
return;
case IMSG_CTL_PROFILE:
diff --git a/usr.sbin/smtpd/log.c b/usr.sbin/smtpd/log.c
index ec30321df32..b4094db8030 100644
--- a/usr.sbin/smtpd/log.c
+++ b/usr.sbin/smtpd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.17 2015/12/28 22:08:30 jung Exp $ */
+/* $OpenBSD: log.c,v 1.18 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -11,50 +11,66 @@
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
- * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
-#include <sys/socket.h>
-
-#include <errno.h>
-#include <pwd.h>
-#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <string.h>
#include <syslog.h>
+#include <errno.h>
#include <time.h>
-#include "log.h"
-
-#define TRACE_DEBUG 0x1
-
-static int foreground;
-static int verbose;
-
-void vlog(int, const char *, va_list);
-void logit(int, const char *, ...)
- __attribute__((format (printf, 2, 3)));
-
+int debug;
+int verbose;
+const char *log_procname;
+
+void log_init(int, int);
+void log_procinit(const char *);
+void log_verbose(int);
+void log_warn(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_warnx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_info(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_debug(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void logit(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+void vlog(int, const char *, va_list)
+ __attribute__((__format__ (printf, 2, 0)));
+__dead void fatal(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+__dead void fatalx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
void
-log_init(int n_foreground)
+log_init(int n_debug, int facility)
{
extern char *__progname;
- foreground = n_foreground;
- if (!foreground)
- openlog(__progname, LOG_PID | LOG_NDELAY, LOG_MAIL);
+ debug = n_debug;
+ verbose = n_debug;
+ log_procinit(__progname);
+
+ if (!debug)
+ openlog(__progname, LOG_PID | LOG_NDELAY, facility);
tzset();
}
void
+log_procinit(const char *procname)
+{
+ if (procname != NULL)
+ log_procname = procname;
+}
+
+void
log_verbose(int v)
{
verbose = v;
@@ -74,8 +90,9 @@ void
vlog(int pri, const char *fmt, va_list ap)
{
char *nfmt;
+ int saved_errno = errno;
- if (foreground) {
+ if (debug) {
/* best effort in out of mem situations */
if (asprintf(&nfmt, "%s\n", fmt) == -1) {
vfprintf(stderr, fmt, ap);
@@ -87,31 +104,36 @@ vlog(int pri, const char *fmt, va_list ap)
fflush(stderr);
} else
vsyslog(pri, fmt, ap);
-}
+ errno = saved_errno;
+}
void
log_warn(const char *emsg, ...)
{
- char *nfmt;
- va_list ap;
+ char *nfmt;
+ va_list ap;
+ int saved_errno = errno;
/* best effort to even work in out of memory situations */
if (emsg == NULL)
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
else {
va_start(ap, emsg);
- if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) {
+ if (asprintf(&nfmt, "%s: %s", emsg,
+ strerror(saved_errno)) == -1) {
/* we tried it... */
vlog(LOG_CRIT, emsg, ap);
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
} else {
vlog(LOG_CRIT, nfmt, ap);
free(nfmt);
}
va_end(ap);
}
+
+ errno = saved_errno;
}
void
@@ -139,19 +161,7 @@ log_debug(const char *emsg, ...)
{
va_list ap;
- if (verbose & TRACE_DEBUG) {
- va_start(ap, emsg);
- vlog(LOG_DEBUG, emsg, ap);
- va_end(ap);
- }
-}
-
-void
-log_trace(int mask, const char *emsg, ...)
-{
- va_list ap;
-
- if (verbose & mask) {
+ if (verbose > 1) {
va_start(ap, emsg);
vlog(LOG_DEBUG, emsg, ap);
va_end(ap);
@@ -159,23 +169,23 @@ log_trace(int mask, const char *emsg, ...)
}
static void
-fatal_arg(const char *emsg, va_list ap)
+vfatalc(int code, const char *emsg, va_list ap)
{
-#define FATALBUFSIZE 1024
- static char ebuffer[FATALBUFSIZE];
-
- if (emsg == NULL)
- (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
- (void)vsnprintf(ebuffer, sizeof ebuffer, emsg, ap);
+ static char s[BUFSIZ];
+ const char *sep;
+
+ if (emsg != NULL) {
+ (void)vsnprintf(s, sizeof(s), emsg, ap);
+ sep = ": ";
+ } else {
+ s[0] = '\0';
+ sep = "";
}
- logit(LOG_CRIT, "fatal: %s", ebuffer);
+ if (code)
+ logit(LOG_CRIT, "%s: %s%s%s",
+ log_procname, s, sep, strerror(code));
+ else
+ logit(LOG_CRIT, "%s%s%s", log_procname, sep, s);
}
void
@@ -184,7 +194,7 @@ fatal(const char *emsg, ...)
va_list ap;
va_start(ap, emsg);
- fatal_arg(emsg, ap);
+ vfatalc(errno, emsg, ap);
va_end(ap);
exit(1);
}
@@ -194,9 +204,8 @@ fatalx(const char *emsg, ...)
{
va_list ap;
- errno = 0;
va_start(ap, emsg);
- fatal_arg(emsg, ap);
+ vfatalc(0, emsg, ap);
va_end(ap);
exit(1);
}
diff --git a/usr.sbin/smtpd/log.h b/usr.sbin/smtpd/log.h
index 6009af2738f..4b2bbe840bb 100644
--- a/usr.sbin/smtpd/log.h
+++ b/usr.sbin/smtpd/log.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.5 2014/07/08 10:30:52 eric Exp $ */
+/* $OpenBSD: log.h,v 1.6 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2010 Gilles Chehade <gilles@poolp.org>
@@ -16,19 +16,30 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-void log_init(int);
-void log_verbose(int);
-void log_warn(const char *, ...)
- __attribute__((format (printf, 1, 2)));
-void log_warnx(const char *, ...)
- __attribute__((format (printf, 1, 2)));
-void log_info(const char *, ...)
- __attribute__((format (printf, 1, 2)));
-void log_debug(const char *, ...)
- __attribute__((format (printf, 1, 2)));
-void log_trace(int, const char *, ...)
- __attribute__((format (printf, 2, 3)));
-__dead void fatal(const char *, ...)
- __attribute__((format (printf, 1, 2)));
-__dead void fatalx(const char *, ...)
- __attribute__((format (printf, 1, 2)));
+#include <syslog.h>
+
+/* log.c */
+void log_init(int, int);
+void log_procinit(const char *);
+void log_verbose(int);
+void log_warn(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_warnx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_info(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_debug(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void logit(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+void vlog(int, const char *, va_list)
+ __attribute__((__format__ (printf, 2, 0)));
+__dead void fatal(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+__dead void fatalx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+
+/* util.c */
+void log_trace_verbose(int);
+void log_trace(int, const char *, ...)
+ __attribute__((format (printf, 2, 3)));
diff --git a/usr.sbin/smtpd/makemap.c b/usr.sbin/smtpd/makemap.c
index 408b2f70d96..af24a8c0ade 100644
--- a/usr.sbin/smtpd/makemap.c
+++ b/usr.sbin/smtpd/makemap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: makemap.c,v 1.65 2016/03/17 19:40:43 krw Exp $ */
+/* $OpenBSD: makemap.c,v 1.66 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -96,7 +96,7 @@ makemap(int argc, char *argv[])
char *p;
int fd = -1;
- log_init(1);
+ log_init(1, LOG_MAIL);
mode = strcmp(__progname, "newaliases") ? P_MAKEMAP : P_NEWALIASES;
conf = CONF_FILE;
diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c
index ba3a4cefd9b..08630cc6bd8 100644
--- a/usr.sbin/smtpd/mta.c
+++ b/usr.sbin/smtpd/mta.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mta.c,v 1.202 2016/09/03 22:59:06 giovanni Exp $ */
+/* $OpenBSD: mta.c,v 1.203 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -400,7 +400,7 @@ mta_imsg(struct mproc *p, struct imsg *imsg)
m_msg(&m, imsg);
m_get_int(&m, &v);
m_end(&m);
- log_verbose(v);
+ log_trace_verbose(v);
return;
case IMSG_CTL_PROFILE:
diff --git a/usr.sbin/smtpd/pony.c b/usr.sbin/smtpd/pony.c
index 3817074349a..c057a6df32a 100644
--- a/usr.sbin/smtpd/pony.c
+++ b/usr.sbin/smtpd/pony.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pony.c,v 1.16 2016/09/08 12:06:43 eric Exp $ */
+/* $OpenBSD: pony.c,v 1.17 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2014 Gilles Chehade <gilles@poolp.org>
@@ -66,7 +66,7 @@ pony_imsg(struct mproc *p, struct imsg *imsg)
m_msg(&m, imsg);
m_get_int(&m, &v);
m_end(&m);
- log_verbose(v);
+ log_trace_verbose(v);
return;
case IMSG_CTL_PROFILE:
m_msg(&m, imsg);
@@ -170,7 +170,6 @@ pony(void)
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
fatal("pony: cannot drop privileges");
-
imsg_callback = pony_imsg;
event_init();
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c
index 0fdf346a34f..b826523fb9a 100644
--- a/usr.sbin/smtpd/queue.c
+++ b/usr.sbin/smtpd/queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue.c,v 1.182 2016/09/08 12:06:43 eric Exp $ */
+/* $OpenBSD: queue.c,v 1.183 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -491,7 +491,7 @@ queue_imsg(struct mproc *p, struct imsg *imsg)
m_msg(&m, imsg);
m_get_int(&m, &v);
m_end(&m);
- log_verbose(v);
+ log_trace_verbose(v);
return;
case IMSG_CTL_PROFILE:
diff --git a/usr.sbin/smtpd/scheduler_ramqueue.c b/usr.sbin/smtpd/scheduler_ramqueue.c
index d8d7c05ed8f..ffc0b3e642f 100644
--- a/usr.sbin/smtpd/scheduler_ramqueue.c
+++ b/usr.sbin/smtpd/scheduler_ramqueue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scheduler_ramqueue.c,v 1.42 2015/10/29 10:25:36 sunil Exp $ */
+/* $OpenBSD: scheduler_ramqueue.c,v 1.43 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2012 Gilles Chehade <gilles@poolp.org>
@@ -255,12 +255,12 @@ scheduler_ram_commit(uint32_t msgid)
update = tree_xpop(&updates, msgid);
r = update->evpcount;
- if (verbose & TRACE_SCHEDULER)
+ if (tracing & TRACE_SCHEDULER)
rq_queue_dump(update, "update to commit");
rq_queue_merge(&ramqueue, update);
- if (verbose & TRACE_SCHEDULER)
+ if (tracing & TRACE_SCHEDULER)
rq_queue_dump(&ramqueue, "resulting queue");
rq_queue_schedule(&ramqueue);
@@ -481,7 +481,7 @@ scheduler_ram_batch(int mask, int *delay, size_t *count, uint64_t *evpids, int *
currtime = time(NULL);
rq_queue_schedule(&ramqueue);
- if (verbose & TRACE_SCHEDULER)
+ if (tracing & TRACE_SCHEDULER)
rq_queue_dump(&ramqueue, "scheduler_ram_batch()");
i = 0;
diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
index 526b128bf8f..412aebd6589 100644
--- a/usr.sbin/smtpd/smtpctl.c
+++ b/usr.sbin/smtpd/smtpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpctl.c,v 1.151 2016/09/04 09:33:49 eric Exp $ */
+/* $OpenBSD: smtpctl.c,v 1.152 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@@ -730,7 +730,7 @@ do_show_queue(int argc, struct parameter *argv)
now = time(NULL);
if (!srv_connect()) {
- log_init(1);
+ log_init(1, LOG_MAIL);
queue_init("fs", 0);
if (chroot(PATH_SPOOL) == -1 || chdir("/") == -1)
err(1, "%s", PATH_SPOOL);
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index d428db9d1cd..533cd70ecf7 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.287 2016/10/19 14:06:07 jmc Exp $ */
+/* $OpenBSD: smtpd.c,v 1.288 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -139,10 +139,8 @@ const char *backend_scheduler = "ramqueue";
const char *backend_stat = "ram";
int profiling = 0;
-int verbose = 0;
int debug = 0;
int foreground = 0;
-int foreground_log = 0;
int control_socket = -1;
struct tree children;
@@ -248,7 +246,7 @@ parent_imsg(struct mproc *p, struct imsg *imsg)
m_msg(&m, imsg);
m_get_int(&m, &v);
m_end(&m);
- log_verbose(v);
+ log_trace_verbose(v);
return;
case IMSG_CTL_PROFILE:
@@ -456,9 +454,9 @@ main(int argc, char *argv[])
flags = 0;
opts = 0;
debug = 0;
- verbose = 0;
+ tracing = 0;
- log_init(1);
+ log_init(1, LOG_MAIL);
TAILQ_INIT(&offline_q);
@@ -503,41 +501,41 @@ main(int argc, char *argv[])
case 'T':
if (!strcmp(optarg, "imsg"))
- verbose |= TRACE_IMSG;
+ tracing |= TRACE_IMSG;
else if (!strcmp(optarg, "io"))
- verbose |= TRACE_IO;
+ tracing |= TRACE_IO;
else if (!strcmp(optarg, "smtp"))
- verbose |= TRACE_SMTP;
+ tracing |= TRACE_SMTP;
else if (!strcmp(optarg, "mfa") ||
!strcmp(optarg, "filter") ||
!strcmp(optarg, "filters"))
- verbose |= TRACE_FILTERS;
+ tracing |= TRACE_FILTERS;
else if (!strcmp(optarg, "mta") ||
!strcmp(optarg, "transfer"))
- verbose |= TRACE_MTA;
+ tracing |= TRACE_MTA;
else if (!strcmp(optarg, "bounce") ||
!strcmp(optarg, "bounces"))
- verbose |= TRACE_BOUNCE;
+ tracing |= TRACE_BOUNCE;
else if (!strcmp(optarg, "scheduler"))
- verbose |= TRACE_SCHEDULER;
+ tracing |= TRACE_SCHEDULER;
else if (!strcmp(optarg, "lookup"))
- verbose |= TRACE_LOOKUP;
+ tracing |= TRACE_LOOKUP;
else if (!strcmp(optarg, "stat") ||
!strcmp(optarg, "stats"))
- verbose |= TRACE_STAT;
+ tracing |= TRACE_STAT;
else if (!strcmp(optarg, "rules"))
- verbose |= TRACE_RULES;
+ tracing |= TRACE_RULES;
else if (!strcmp(optarg, "mproc"))
- verbose |= TRACE_MPROC;
+ tracing |= TRACE_MPROC;
else if (!strcmp(optarg, "expand"))
- verbose |= TRACE_EXPAND;
+ tracing |= TRACE_EXPAND;
else if (!strcmp(optarg, "table") ||
!strcmp(optarg, "tables"))
- verbose |= TRACE_TABLES;
+ tracing |= TRACE_TABLES;
else if (!strcmp(optarg, "queue"))
- verbose |= TRACE_QUEUE;
+ tracing |= TRACE_QUEUE;
else if (!strcmp(optarg, "all"))
- verbose |= ~TRACE_DEBUG;
+ tracing |= ~TRACE_DEBUG;
else if (!strcmp(optarg, "profstat"))
profiling |= PROFILE_TOSTAT;
else if (!strcmp(optarg, "profile-imsg"))
@@ -557,7 +555,7 @@ main(int argc, char *argv[])
flags |= SMTPD_MDA_PAUSED;
break;
case 'v':
- verbose |= TRACE_DEBUG;
+ tracing |= TRACE_DEBUG;
break;
case 'x':
rexec = optarg;
@@ -601,9 +599,8 @@ main(int argc, char *argv[])
if (geteuid())
errx(1, "need root privileges");
- log_init(foreground_log);
- log_verbose(verbose);
-
+ log_init(foreground_log, LOG_MAIL);
+ log_trace_verbose(tracing);
load_pki_tree();
load_pki_keys();
@@ -874,6 +871,8 @@ setup_proc(void)
struct imsg imsg;
int setup = 1;
+ log_procinit(proc_title(smtpd_process));
+
p_parent = calloc(1, sizeof(*p_parent));
if (p_parent == NULL)
fatal("calloc");
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 9bfcfe93360..1c3b4533132 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.527 2016/11/30 18:38:32 eric Exp $ */
+/* $OpenBSD: smtpd.h,v 1.528 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -1018,7 +1018,7 @@ struct msg {
extern enum smtp_proc_type smtpd_process;
-extern int verbose;
+extern int tracing;
extern int foreground_log;
extern int profiling;
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index cee21ddd6ac..c4d4824fdc2 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.130 2016/11/30 18:38:32 eric Exp $ */
+/* $OpenBSD: util.c,v 1.131 2017/01/09 09:53:23 reyk Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -55,6 +55,9 @@ const char *log_in6addr(const struct in6_addr *);
const char *log_sockaddr(struct sockaddr *);
static int parse_mailname_file(char *, size_t);
+int tracing = 0;
+int foreground_log = 0;
+
void *
xmalloc(size_t size, const char *where)
{
@@ -790,3 +793,24 @@ base64_decode(char const *src, unsigned char *dest, size_t destsize)
{
return __b64_pton(src, dest, destsize);
}
+
+void
+log_trace(int mask, const char *emsg, ...)
+{
+ va_list ap;
+
+ if (tracing & mask) {
+ va_start(ap, emsg);
+ vlog(LOG_DEBUG, emsg, ap);
+ va_end(ap);
+ }
+}
+
+void
+log_trace_verbose(int v)
+{
+ tracing = v;
+
+ /* Set debug logging in log.c */
+ log_verbose(v & TRACE_DEBUG ? 2 : foreground_log);
+}