summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2012-01-13 14:01:59 +0000
committerEric Faurot <eric@cvs.openbsd.org>2012-01-13 14:01:59 +0000
commit455ed08623a520380394beebd1db9431a107c733 (patch)
tree454cf0ea6e99369619d4460a67040d067c3acac4 /usr.sbin
parent03f8509651d44f20f3bdec67d3f229743a48c988 (diff)
Stop using envelope->status to report delivery outcome to the
runner/queue. Instead, replace IMSG_QUEUE_MESSAGE_UPDATE with three messages: - IMSG_QUEUE_DELIVERY_OK - IMSG_QUEUE_DELIVERY_TEMPFAIL - IMSG_QUEUE_DELIVERY_PERMFAIL 1) it's less confusing as status is also used by smtp 2) it's easier to see what happens just looking at imsg traces 3) it makes the code path generally easier to follow 4) it's safer because it enforces clear semantics and intent, whereas the status field is loosely defined and could carry bogus values. ok gilles@ chl@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/mda.c16
-rw-r--r--usr.sbin/smtpd/mta.c20
-rw-r--r--usr.sbin/smtpd/queue.c10
-rw-r--r--usr.sbin/smtpd/runner.c54
-rw-r--r--usr.sbin/smtpd/smtpd.c7
-rw-r--r--usr.sbin/smtpd/smtpd.h6
6 files changed, 56 insertions, 57 deletions
diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c
index b5b74144352..8ebe76d607a 100644
--- a/usr.sbin/smtpd/mda.c
+++ b/usr.sbin/smtpd/mda.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mda.c,v 1.66 2012/01/12 20:59:07 eric Exp $ */
+/* $OpenBSD: mda.c,v 1.67 2012/01/13 14:01:57 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -58,6 +58,7 @@ mda_imsg(struct imsgev *iev, struct imsg *imsg)
struct delivery_mda *d_mda;
struct mailaddr *maddr;
struct envelope *ep;
+ u_int16_t msg;
log_imsg(PROC_MDA, iev->proc, imsg);
@@ -70,7 +71,6 @@ mda_imsg(struct imsgev *iev, struct imsg *imsg)
fatal(NULL);
msgbuf_init(&s->w);
s->msg = *(struct envelope *)imsg->data;
- s->msg.status = DS_TEMPFAILURE;
s->id = mda_id++;
s->datafp = fdopen(imsg->fd, "r");
if (s->datafp == NULL)
@@ -198,13 +198,13 @@ mda_imsg(struct imsgev *iev, struct imsg *imsg)
}
/* update queue entry */
- if (error == NULL)
- s->msg.status = DS_ACCEPTED;
- else
+ msg = IMSG_QUEUE_DELIVERY_OK;
+ if (error) {
+ msg = IMSG_QUEUE_DELIVERY_TEMPFAIL;
envelope_set_errormsg(&s->msg, "%s", error);
- imsg_compose_event(env->sc_ievs[PROC_QUEUE],
- IMSG_QUEUE_MESSAGE_UPDATE, 0, 0, -1, &s->msg,
- sizeof s->msg);
+ }
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE], msg,
+ 0, 0, -1, &s->msg, sizeof s->msg);
/*
* XXX: which struct path gets used for logging depends
diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c
index a7cc927861f..9e0a06dd5c7 100644
--- a/usr.sbin/smtpd/mta.c
+++ b/usr.sbin/smtpd/mta.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mta.c,v 1.122 2012/01/11 22:12:07 eric Exp $ */
+/* $OpenBSD: mta.c,v 1.123 2012/01/13 14:01:57 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -704,20 +704,22 @@ mta_message_log(struct mta_session *s, struct envelope *e)
static void
mta_message_done(struct mta_session *s, struct envelope *e)
{
+ u_int16_t msg;
+
switch (e->errorline[0]) {
- case '6':
- case '5':
- e->status = DS_PERMFAILURE;
- break;
case '2':
- e->status = DS_ACCEPTED;
+ msg = IMSG_QUEUE_DELIVERY_OK;
+ break;
+ case '5':
+ case '6':
+ msg = IMSG_QUEUE_DELIVERY_PERMFAIL;
break;
default:
- e->status = DS_TEMPFAILURE;
+ msg = IMSG_QUEUE_DELIVERY_TEMPFAIL;
break;
}
- imsg_compose_event(env->sc_ievs[PROC_QUEUE],
- IMSG_QUEUE_MESSAGE_UPDATE, 0, 0, -1, e, sizeof(*e));
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE], msg,
+ 0, 0, -1, e, sizeof(*e));
TAILQ_REMOVE(&s->recipients, e, entry);
free(e);
}
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c
index 1e7cd1c331d..d23902c18ad 100644
--- a/usr.sbin/smtpd/queue.c
+++ b/usr.sbin/smtpd/queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue.c,v 1.114 2012/01/11 17:46:36 eric Exp $ */
+/* $OpenBSD: queue.c,v 1.115 2012/01/13 14:01:57 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -145,7 +145,9 @@ queue_imsg(struct imsgev *iev, struct imsg *imsg)
fd, rq_batch, sizeof *rq_batch);
return;
- case IMSG_QUEUE_MESSAGE_UPDATE:
+ case IMSG_QUEUE_DELIVERY_OK:
+ case IMSG_QUEUE_DELIVERY_TEMPFAIL:
+ case IMSG_QUEUE_DELIVERY_PERMFAIL:
case IMSG_BATCH_DONE:
queue_pass_to_runner(iev, imsg);
return;
@@ -154,7 +156,9 @@ queue_imsg(struct imsgev *iev, struct imsg *imsg)
if (iev->proc == PROC_MDA) {
switch (imsg->hdr.type) {
- case IMSG_QUEUE_MESSAGE_UPDATE:
+ case IMSG_QUEUE_DELIVERY_OK:
+ case IMSG_QUEUE_DELIVERY_TEMPFAIL:
+ case IMSG_QUEUE_DELIVERY_PERMFAIL:
case IMSG_MDA_SESS_NEW:
queue_pass_to_runner(iev, imsg);
return;
diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c
index 6c29360970c..aa32883d9ed 100644
--- a/usr.sbin/smtpd/runner.c
+++ b/usr.sbin/smtpd/runner.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: runner.c,v 1.131 2012/01/12 23:17:02 gilles Exp $ */
+/* $OpenBSD: runner.c,v 1.132 2012/01/13 14:01:58 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -61,7 +61,7 @@ static int runner_force_message_to_ramqueue(struct ramqueue *, u_int32_t);
void
runner_imsg(struct imsgev *iev, struct imsg *imsg)
{
- struct envelope *e;
+ struct envelope *e, bounce;
log_imsg(PROC_RUNNER, iev->proc, imsg);
@@ -73,42 +73,30 @@ runner_imsg(struct imsgev *iev, struct imsg *imsg)
runner_reset_events();
return;
- case IMSG_QUEUE_MESSAGE_UPDATE:
+ case IMSG_QUEUE_DELIVERY_OK:
+ stat_decrement(STATS_RUNNER);
e = imsg->data;
- e->retry++;
+ queue_envelope_delete(Q_QUEUE, e);
+ return;
+
+ case IMSG_QUEUE_DELIVERY_TEMPFAIL:
stat_decrement(STATS_RUNNER);
+ e = imsg->data;
+ e->retry++;
+ queue_envelope_update(Q_QUEUE, e);
+ ramqueue_insert(&env->sc_rqueue, e, time(NULL));
+ runner_reset_events();
+ return;
- /* temporary failure, message remains in queue,
- * gets reinserted in ramqueue
- */
- if (e->status & DS_TEMPFAILURE) {
- log_debug("TEMPFAIL: %016" PRIx64, e->id);
- queue_envelope_update(Q_QUEUE, e);
- ramqueue_insert(&env->sc_rqueue, e, time(NULL));
+ case IMSG_QUEUE_DELIVERY_PERMFAIL:
+ stat_decrement(STATS_RUNNER);
+ e = imsg->data;
+ if (e->type != D_BOUNCE && e->sender.user[0] != '\0') {
+ log_debug("PERMFAIL #2: %016" PRIx64, e->id);
+ bounce_record_message(e, &bounce);
+ ramqueue_insert(&env->sc_rqueue, &bounce, time(NULL));
runner_reset_events();
- return;
}
-
- /* permanent failure, eventually generate a
- * bounce (and insert bounce in ramqueue).
- */
- if (e->status & DS_PERMFAILURE) {
- struct envelope bounce;
- log_debug("PERMFAIL: %016" PRIx64, e->id);
- if (e->type != D_BOUNCE &&
- e->sender.user[0] != '\0') {
- log_debug("PERMFAIL #2: %016" PRIx64, e->id);
- bounce_record_message(e, &bounce);
- ramqueue_insert(&env->sc_rqueue, &bounce, time(NULL));
- runner_reset_events();
- }
- }
-
- /* successful delivery or permanent failure,
- * remove envelope from queue.
- */
- log_debug("#### %s: queue_envelope_delete: %016" PRIx64,
- __func__, e->id);
queue_envelope_delete(Q_QUEUE, e);
return;
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index 3197f8ac759..4a97c923f04 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.146 2012/01/12 18:06:18 eric Exp $ */
+/* $OpenBSD: smtpd.c,v 1.147 2012/01/13 14:01:58 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -1199,7 +1199,10 @@ imsg_to_str(int type)
CASE(IMSG_QUEUE_RESUME_MDA);
CASE(IMSG_QUEUE_RESUME_MTA);
- CASE(IMSG_QUEUE_MESSAGE_UPDATE);
+ CASE(IMSG_QUEUE_DELIVERY_OK);
+ CASE(IMSG_QUEUE_DELIVERY_TEMPFAIL);
+ CASE(IMSG_QUEUE_DELIVERY_PERMFAIL);
+
CASE(IMSG_QUEUE_MESSAGE_FD);
CASE(IMSG_QUEUE_MESSAGE_FILE);
CASE(IMSG_QUEUE_SCHEDULE);
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 80bbcf7c985..27a7696a890 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.276 2012/01/12 20:59:07 eric Exp $ */
+/* $OpenBSD: smtpd.h,v 1.277 2012/01/13 14:01:58 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -148,7 +148,9 @@ enum imsg_type {
IMSG_QUEUE_RESUME_MDA,
IMSG_QUEUE_RESUME_MTA,
- IMSG_QUEUE_MESSAGE_UPDATE,
+ IMSG_QUEUE_DELIVERY_OK,
+ IMSG_QUEUE_DELIVERY_TEMPFAIL,
+ IMSG_QUEUE_DELIVERY_PERMFAIL,
IMSG_QUEUE_MESSAGE_FD,
IMSG_QUEUE_MESSAGE_FILE,
IMSG_QUEUE_SCHEDULE,