summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2009-01-04 19:37:42 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2009-01-04 19:37:42 +0000
commit5f61b60a6b0e894f17c28cac99a3482809e5c91c (patch)
tree3e4780b60352ac89371bc06211486df130824e86 /usr.sbin
parent199a745fdcd9bc8c19dce443d37061a3fc8dc147 (diff)
- runner is now capable of pausing/resuming the scheduling of deliveries
for both mda and mta batches. - smtpctl can be used to disable/enable deliveries at runtime using the pause/resume commands. ok jacekm@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/control.c47
-rw-r--r--usr.sbin/smtpd/parser.c20
-rw-r--r--usr.sbin/smtpd/parser.h8
-rw-r--r--usr.sbin/smtpd/runner.c22
-rw-r--r--usr.sbin/smtpd/smtpctl.c18
-rw-r--r--usr.sbin/smtpd/smtpd.h10
6 files changed, 116 insertions, 9 deletions
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c
index 04370e980fc..a1905876d4d 100644
--- a/usr.sbin/smtpd/control.c
+++ b/usr.sbin/smtpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.5 2009/01/01 16:15:47 jacekm Exp $ */
+/* $OpenBSD: control.c,v 1.6 2009/01/04 19:37:41 gilles Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -311,6 +311,51 @@ control_dispatch_ext(int fd, short event, void *arg)
env->sc_flags |= SMTPD_EXITING;
imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
+ case IMSG_RUNNER_PAUSE_MDA:
+ if (env->sc_flags & SMTPD_MDA_PAUSED) {
+ imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ NULL, 0);
+ break;
+ }
+ env->sc_flags |= SMTPD_MDA_PAUSED;
+ imsg_compose(env->sc_ibufs[PROC_RUNNER], IMSG_RUNNER_PAUSE_MDA,
+ 0, 0, -1, NULL, 0);
+ imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ break;
+ case IMSG_RUNNER_PAUSE_MTA:
+ if (env->sc_flags & SMTPD_MTA_PAUSED) {
+ imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ NULL, 0);
+ break;
+ }
+ env->sc_flags |= SMTPD_MTA_PAUSED;
+ imsg_compose(env->sc_ibufs[PROC_RUNNER], IMSG_RUNNER_PAUSE_MTA,
+ 0, 0, -1, NULL, 0);
+ imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ break;
+ case IMSG_RUNNER_RESUME_MDA:
+ if (! (env->sc_flags & SMTPD_MDA_PAUSED)) {
+ imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ NULL, 0);
+ break;
+ }
+ env->sc_flags &= ~SMTPD_MDA_PAUSED;
+ imsg_compose(env->sc_ibufs[PROC_RUNNER], IMSG_RUNNER_RESUME_MDA,
+ 0, 0, -1, NULL, 0);
+ imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ break;
+ case IMSG_RUNNER_RESUME_MTA:
+ if (!(env->sc_flags & SMTPD_MTA_PAUSED)) {
+ imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ NULL, 0);
+ break;
+ }
+ env->sc_flags &= ~SMTPD_MTA_PAUSED;
+ imsg_compose(env->sc_ibufs[PROC_RUNNER], IMSG_RUNNER_RESUME_MTA,
+ 0, 0, -1, NULL, 0);
+ imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ break;
+
default:
log_debug("control_dispatch_ext: "
"error handling imsg %d", imsg.hdr.type);
diff --git a/usr.sbin/smtpd/parser.c b/usr.sbin/smtpd/parser.c
index 6ade78d00dd..291d2bc5272 100644
--- a/usr.sbin/smtpd/parser.c
+++ b/usr.sbin/smtpd/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.3 2008/12/27 16:45:01 jacekm Exp $ */
+/* $OpenBSD: parser.c,v 1.4 2009/01/04 19:37:41 gilles Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -56,12 +56,16 @@ struct token {
static const struct token t_main[];
static const struct token t_show[];
+static const struct token t_pause[];
+static const struct token t_resume[];
static const struct token t_main[] = {
{KEYWORD, "show", NONE, t_show},
{KEYWORD, "monitor", MONITOR, NULL},
+ {KEYWORD, "pause", NONE, t_pause},
{KEYWORD, "reload", RELOAD, NULL},
- {KEYWORD, "stop", SHUTDOWN, NULL},
+ {KEYWORD, "resume", NONE, t_resume},
+ {KEYWORD, "stop", SHUTDOWN, NULL},
{ENDTOKEN, "", NONE, NULL}
};
@@ -71,6 +75,18 @@ static const struct token t_show[] = {
{ENDTOKEN, "", NONE, NULL}
};
+static const struct token t_pause[] = {
+ {KEYWORD, "local", PAUSE_MDA, NULL},
+ {KEYWORD, "outgoing", PAUSE_MTA, NULL},
+ {ENDTOKEN, "", NONE, NULL}
+};
+
+static const struct token t_resume[] = {
+ {KEYWORD, "local", RESUME_MDA, NULL},
+ {KEYWORD, "outgoing", RESUME_MTA, NULL},
+ {ENDTOKEN, "", NONE, NULL}
+};
+
static struct parse_result res;
struct parse_result *
diff --git a/usr.sbin/smtpd/parser.h b/usr.sbin/smtpd/parser.h
index f4d5351b1eb..0b10607ef8a 100644
--- a/usr.sbin/smtpd/parser.h
+++ b/usr.sbin/smtpd/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.3 2008/12/27 16:45:01 jacekm Exp $ */
+/* $OpenBSD: parser.h,v 1.4 2009/01/04 19:37:41 gilles Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -22,7 +22,11 @@ enum actions {
RELOAD,
MONITOR,
SHOW_QUEUE,
- SHOW_RUNQUEUE
+ SHOW_RUNQUEUE,
+ PAUSE_MDA,
+ PAUSE_MTA,
+ RESUME_MDA,
+ RESUME_MTA,
};
struct parse_result {
diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c
index 31996f7b898..3d22e04550c 100644
--- a/usr.sbin/smtpd/runner.c
+++ b/usr.sbin/smtpd/runner.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: runner.c,v 1.15 2009/01/04 19:26:30 jacekm Exp $ */
+/* $OpenBSD: runner.c,v 1.16 2009/01/04 19:37:41 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -72,6 +72,10 @@ void runner_purge_message(char *);
struct batch *batch_record(struct smtpd *, struct message *);
struct batch *batch_lookup(struct smtpd *, struct message *);
+#define RUNNER_MDA 0x1
+#define RUNNER_MTA 0x2
+u_int8_t runstates = RUNNER_MDA|RUNNER_MTA;
+
void
runner_sig_handler(int sig, short event, void *p)
{
@@ -121,6 +125,18 @@ runner_dispatch_control(int sig, short event, void *p)
break;
switch (imsg.hdr.type) {
+ case IMSG_RUNNER_PAUSE_MDA:
+ runstates &= ~RUNNER_MDA;
+ break;
+ case IMSG_RUNNER_PAUSE_MTA:
+ runstates &= ~RUNNER_MTA;
+ break;
+ case IMSG_RUNNER_RESUME_MDA:
+ runstates |= RUNNER_MDA;
+ break;
+ case IMSG_RUNNER_RESUME_MTA:
+ runstates |= RUNNER_MTA;
+ break;
default:
log_debug("queue_dispatch_control: unexpected imsg %d",
imsg.hdr.type);
@@ -719,6 +735,10 @@ runner_message_schedule(struct message *messagep, time_t tm)
if (messagep->flags & (F_MESSAGE_SCHEDULED|F_MESSAGE_PROCESSING))
return 0;
+ if (((messagep->type & T_MDA_MESSAGE) && !(runstates & RUNNER_MDA)) ||
+ ((messagep->type & T_MTA_MESSAGE) && !(runstates & RUNNER_MTA)))
+ return 0;
+
/* Batch has been in the queue for too long and expired */
if (tm - messagep->creation >= SMTPD_QUEUE_EXPIRY) {
queue_remove_envelope(messagep);
diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
index 92dd314eb71..51a3c2c586e 100644
--- a/usr.sbin/smtpd/smtpctl.c
+++ b/usr.sbin/smtpd/smtpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpctl.c,v 1.3 2008/12/27 16:45:01 jacekm Exp $ */
+/* $OpenBSD: smtpctl.c,v 1.4 2009/01/04 19:37:41 gilles Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -138,6 +138,18 @@ connected:
case RELOAD:
imsg_compose(ibuf, IMSG_CONF_RELOAD, 0, 0, -1, NULL, 0);
break;
+ case PAUSE_MDA:
+ imsg_compose(ibuf, IMSG_RUNNER_PAUSE_MDA, 0, 0, -1, NULL, 0);
+ break;
+ case PAUSE_MTA:
+ imsg_compose(ibuf, IMSG_RUNNER_PAUSE_MTA, 0, 0, -1, NULL, 0);
+ break;
+ case RESUME_MDA:
+ imsg_compose(ibuf, IMSG_RUNNER_RESUME_MDA, 0, 0, -1, NULL, 0);
+ break;
+ case RESUME_MTA:
+ imsg_compose(ibuf, IMSG_RUNNER_RESUME_MTA, 0, 0, -1, NULL, 0);
+ break;
case MONITOR:
/* XXX */
break;
@@ -163,6 +175,10 @@ connected:
switch(res->action) {
case RELOAD:
case SHUTDOWN:
+ case PAUSE_MDA:
+ case PAUSE_MTA:
+ case RESUME_MDA:
+ case RESUME_MTA:
done = show_command_output(&imsg);
break;
case NONE:
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 5d6136e89f9..6ab7fb8122c 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.42 2009/01/04 19:25:19 jacekm Exp $ */
+/* $OpenBSD: smtpd.h,v 1.43 2009/01/04 19:37:41 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -190,8 +190,12 @@ enum imsg_type {
IMSG_PARENT_MESSAGE_OPEN,
IMSG_PARENT_MAILBOX_RENAME,
- IMSG_PARENT_AUTHENTICATE
+ IMSG_PARENT_AUTHENTICATE,
+ IMSG_RUNNER_PAUSE_MDA,
+ IMSG_RUNNER_PAUSE_MTA,
+ IMSG_RUNNER_RESUME_MDA,
+ IMSG_RUNNER_RESUME_MTA
};
#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
@@ -586,6 +590,8 @@ struct smtpd {
u_int32_t sc_opts;
#define SMTPD_CONFIGURING 0x00000001
#define SMTPD_EXITING 0x00000002
+#define SMTPD_MDA_PAUSED 0x00000004
+#define SMTPD_MTA_PAUSED 0x00000008
u_int32_t sc_flags;
struct timeval sc_qintval;
struct event sc_ev;