summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/smtpctl.c
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2012-11-12 14:58:54 +0000
committerEric Faurot <eric@cvs.openbsd.org>2012-11-12 14:58:54 +0000
commitb978afa593739cd00f56cc9f5737d18e8575bc8b (patch)
tree5c19c4f60f92f0ddd3977d36cea0a163bdb6e457 /usr.sbin/smtpd/smtpctl.c
parent98b597918008f218253c1c75aca5d02f8cccae79 (diff)
Cleanups and improvements:
* Log more events (especially client session) and use a better scheme for that: each messages is prefixed with a token to easily identify its class: - info/warn/debug: general server messages - smtp-in: smtp client connections - relay: status update for relayed messages - delivery: status update for local deliveries * Implement "smtpctl monitor" to display updates of selected internal counters. * When reloading the on-disk queue at startup do not commit a message if no envelope was submitted for that message. * Remove unused stuff in the config parser. ok gilles@
Diffstat (limited to 'usr.sbin/smtpd/smtpctl.c')
-rw-r--r--usr.sbin/smtpd/smtpctl.c62
1 files changed, 59 insertions, 3 deletions
diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
index da5f871e06a..757024da491 100644
--- a/usr.sbin/smtpd/smtpctl.c
+++ b/usr.sbin/smtpd/smtpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpctl.c,v 1.94 2012/10/26 19:16:42 chl Exp $ */
+/* $OpenBSD: smtpctl.c,v 1.95 2012/11/12 14:58:53 eric Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -56,6 +56,7 @@ static void getflag(uint *, int, char *, char *, size_t);
static void display(const char *);
static void show_envelope(const char *);
static void show_message(const char *);
+static void show_monitor(struct stat_digest *);
int proctype;
struct imsgbuf *ibuf;
@@ -228,7 +229,8 @@ connected:
break;
}
case MONITOR:
- /* XXX */
+ again:
+ imsg_compose(ibuf, IMSG_DIGEST, 0, 0, -1, NULL, 0);
break;
case LOG_VERBOSE:
verbose = 1;
@@ -280,7 +282,12 @@ connected:
case NONE:
break;
case UPDATE_MAP:
+ break;
case MONITOR:
+ show_monitor(imsg.data);
+ imsg_free(&imsg);
+ sleep(1);
+ goto again;
break;
default:
err(1, "unexpected reply (%d)", res->action);
@@ -351,7 +358,7 @@ again:
if (strcmp(kvp->key, "uptime") == 0) {
duration = time(NULL) - kvp->val.u.counter;
- printf("uptime=%zd\n", duration);
+ printf("uptime=%zd\n", (size_t)duration);
printf("uptime.human=%s\n",
duration_to_text(duration));
} else {
@@ -535,3 +542,52 @@ show_message(const char *s)
display(buf);
}
+
+static void
+show_monitor(struct stat_digest *d)
+{
+ static int init = 0;
+ static size_t count = 0;
+ static struct stat_digest last;
+
+ if (init == 0) {
+ init = 1;
+ bzero(&last, sizeof last);
+ }
+
+ if (count % 25 == 0) {
+ if (count != 0)
+ printf("\n");
+ printf("--- client --- "
+ "-- envelope -- "
+ "---- relay/delivery --- "
+ "------- misc -------\n"
+ "curr conn disc "
+ "curr enq deq "
+ "ok tmpfail prmfail loop "
+ "expire remove bounce\n");
+ }
+ printf("%4zu %4zu %4zu "
+ "%4zu %4zu %4zu "
+ "%4zu %4zu %4zu %4zu "
+ "%4zu %4zu %4zu\n",
+ d->clt_connect - d->clt_disconnect,
+ d->clt_connect - last.clt_connect,
+ d->clt_disconnect - last.clt_disconnect,
+
+ d->evp_enqueued - d->evp_dequeued,
+ d->evp_enqueued - last.evp_enqueued,
+ d->evp_dequeued - last.evp_dequeued,
+
+ d->dlv_ok - last.dlv_ok,
+ d->dlv_tempfail - last.dlv_tempfail,
+ d->dlv_permfail - last.dlv_permfail,
+ d->dlv_loop - last.dlv_loop,
+
+ d->evp_expired - last.evp_expired,
+ d->evp_removed - last.evp_removed,
+ d->evp_bounce - last.evp_bounce);
+
+ last = *d;
+ count++;
+}