diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2011-10-22 00:16:35 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2011-10-22 00:16:35 +0000 |
commit | 6603fc737046292e2c935fb184212e91746d4867 (patch) | |
tree | 68cf23e0bd390dca0798f6ce15b1d985f5638da3 /usr.sbin | |
parent | 026cde5447af561fc95b29550a4605285abfd894 (diff) |
Add a log_trace() call to toggle logging of specific debugging info in
verbose mode, and an associated -T command line option. Use it for
the imsg traces.
Requested by gilles@ who doesn't like verbose to be too verbose.
ok gilles@ chl@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/log.c | 14 | ||||
-rw-r--r-- | usr.sbin/smtpd/log.h | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.8 | 13 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.c | 28 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 5 |
5 files changed, 49 insertions, 15 deletions
diff --git a/usr.sbin/smtpd/log.c b/usr.sbin/smtpd/log.c index 03c36367403..c5738952527 100644 --- a/usr.sbin/smtpd/log.c +++ b/usr.sbin/smtpd/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.11 2011/09/11 21:45:16 chl Exp $ */ +/* $OpenBSD: log.c,v 1.12 2011/10/22 00:16:33 eric Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -148,6 +148,18 @@ log_debug(const char *emsg, ...) } void +log_trace(int mask, const char *emsg, ...) +{ + va_list ap; + + if (verbose & mask) { + va_start(ap, emsg); + vlog(LOG_DEBUG, emsg, ap); + va_end(ap); + } +} + +void fatal(const char *emsg) { if (emsg == NULL) diff --git a/usr.sbin/smtpd/log.h b/usr.sbin/smtpd/log.h index f899b58d33e..ce2e454eec8 100644 --- a/usr.sbin/smtpd/log.h +++ b/usr.sbin/smtpd/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.1 2010/11/28 13:56:43 gilles Exp $ */ +/* $OpenBSD: log.h,v 1.2 2011/10/22 00:16:33 eric Exp $ */ /* * Copyright (c) 2010 Gilles Chehade <gilles@openbsd.org> @@ -26,5 +26,7 @@ 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 *); __dead void fatalx(const char *); diff --git a/usr.sbin/smtpd/smtpd.8 b/usr.sbin/smtpd/smtpd.8 index 8f875874f01..dad4cfa99eb 100644 --- a/usr.sbin/smtpd/smtpd.8 +++ b/usr.sbin/smtpd/smtpd.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: smtpd.8,v 1.12 2010/05/24 19:44:23 jmc Exp $ +.\" $OpenBSD: smtpd.8,v 1.13 2011/10/22 00:16:33 eric Exp $ .\" .\" Copyright (c) 2008, Gilles Chehade <gilles@openbsd.org> .\" Copyright (c) 2008, Pierre-Yves Ritschard <pyr@openbsd.org> @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 24 2010 $ +.Dd $Mdocdate: October 22 2011 $ .Dt SMTPD 8 .Os .Sh NAME @@ -67,6 +67,15 @@ Specify an alternative configuration file. .It Fl n Configtest mode. Only check the configuration file for validity. +.It Fl T Ar trace +Show additionnal debug traces when one of the +.Fl v +or +.Fl d +flags is specified. The only accepted value is +.Ar imsg , +which displays the messages exchanged between the various +smtpd processes. .It Fl v Produce more verbose output. .El diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index dcfb03a841a..70be07c00ad 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.131 2011/10/09 18:39:54 eric Exp $ */ +/* $OpenBSD: smtpd.c,v 1.132 2011/10/22 00:16:33 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -442,11 +442,11 @@ main(int argc, char *argv[]) TAILQ_INIT(&queueing_q); - while ((c = getopt(argc, argv, "dD:nf:v")) != -1) { + while ((c = getopt(argc, argv, "dD:nf:T:v")) != -1) { switch (c) { case 'd': debug = 2; - verbose = 1; + verbose |= TRACE_VERBOSE; break; case 'D': if (cmdline_symset(optarg) < 0) @@ -460,15 +460,23 @@ main(int argc, char *argv[]) case 'f': conffile = optarg; break; + case 'T': + if (!strcmp(optarg, "imsg")) + verbose |= TRACE_IMSG; + else + log_warnx("unknown trace flag \"%s\"", optarg); + break; case 'v': - verbose = 1; - opts |= SMTPD_OPT_VERBOSE; + verbose |= TRACE_VERBOSE; break; default: usage(); } } + if (!(verbose & TRACE_VERBOSE)) + verbose = 0; + argv += optind; argc -= optind; @@ -1120,11 +1128,11 @@ const char * imsg_to_str(int); void log_imsg(int to, int from, struct imsg *imsg) { - log_debug("imsg: %s <- %s: %s (len=%zu)", - proc_to_str(to), - proc_to_str(from), - imsg_to_str(imsg->hdr.type), - imsg->hdr.len - IMSG_HEADER_SIZE); + log_trace(TRACE_IMSG, "imsg: %s <- %s: %s (len=%zu)", + proc_to_str(to), + proc_to_str(from), + imsg_to_str(imsg->hdr.type), + imsg->hdr.len - IMSG_HEADER_SIZE); } #define CASE(x) case x : return #x diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index da6d9713544..af037c663fc 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.241 2011/10/09 18:39:54 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.242 2011/10/22 00:16:34 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -651,6 +651,9 @@ struct smtpd { u_int64_t filtermask; }; +#define TRACE_VERBOSE 0x01 +#define TRACE_IMSG 0x02 + enum { STATS_SMTP_SESSION = 0, STATS_SMTP_SESSION_INET4, |