summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/mda.c
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2009-03-15 19:15:26 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2009-03-15 19:15:26 +0000
commitb6b944aa351d07fa3a8e68b0f477b46eac779338 (patch)
tree34a243a8e3390113c9066069feb80e340281153a /usr.sbin/smtpd/mda.c
parentcba696bab4080fdc038f23657d90ba4a1ddd1f37 (diff)
the mda process no longer uses struct batch as its central structure to
deal with deliveries, it now uses struct session just like mta and smtp processes. we now keep the mbox and message descriptors in the session, saving space in struct message which is now as small as we can make it. While at it, plugged a memory leak and did some cosmethic changes This was the last planned change to our struct message which means that later changes will no longer require a queue flush before rebuild.
Diffstat (limited to 'usr.sbin/smtpd/mda.c')
-rw-r--r--usr.sbin/smtpd/mda.c74
1 files changed, 54 insertions, 20 deletions
diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c
index 7efb37da1b9..a4a5c5d7dbe 100644
--- a/usr.sbin/smtpd/mda.c
+++ b/usr.sbin/smtpd/mda.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mda.c,v 1.10 2009/03/10 22:33:26 jacekm Exp $ */
+/* $OpenBSD: mda.c,v 1.11 2009/03/15 19:15:25 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -28,6 +28,7 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include "smtpd.h"
@@ -92,6 +93,7 @@ mda_dispatch_parent(int sig, short event, void *p)
switch (imsg.hdr.type) {
case IMSG_MDA_MAILBOX_FILE: {
+ struct session *s;
struct batch *batchp;
struct message *messagep;
enum message_status status;
@@ -103,14 +105,15 @@ mda_dispatch_parent(int sig, short event, void *p)
batchp = batch_by_id(env, batchp->id);
if (batchp == NULL)
fatalx("mda_dispatch_parent: internal inconsistency.");
+ s = batchp->sessionp;
messagep = message_by_id(env, batchp, messagep->id);
if (messagep == NULL)
fatalx("mda_dispatch_parent: internal inconsistency.");
messagep->status = status;
- messagep->mboxfd = imsg_get_fd(ibuf, &imsg);
- if (messagep->mboxfd == -1) {
+ s->mboxfd = imsg_get_fd(ibuf, &imsg);
+ if (s->mboxfd == -1) {
mda_remove_message(env, batchp, messagep);
break;
}
@@ -123,6 +126,7 @@ mda_dispatch_parent(int sig, short event, void *p)
}
case IMSG_MDA_MESSAGE_FILE: {
+ struct session *s;
struct batch *batchp;
struct message *messagep;
enum message_status status;
@@ -135,16 +139,17 @@ mda_dispatch_parent(int sig, short event, void *p)
batchp = batch_by_id(env, batchp->id);
if (batchp == NULL)
fatalx("mda_dispatch_parent: internal inconsistency.");
+ s = batchp->sessionp;
messagep = message_by_id(env, batchp, messagep->id);
if (messagep == NULL)
fatalx("mda_dispatch_parent: internal inconsistency.");
messagep->status = status;
- messagep->messagefd = imsg_get_fd(ibuf, &imsg);
- if (messagep->messagefd == -1) {
- if (messagep->mboxfd != -1)
- close(messagep->mboxfd);
+ s->messagefd = imsg_get_fd(ibuf, &imsg);
+ if (s->messagefd == -1) {
+ if (s->mboxfd != -1)
+ close(s->mboxfd);
mda_remove_message(env, batchp, messagep);
break;
}
@@ -161,10 +166,10 @@ mda_dispatch_parent(int sig, short event, void *p)
sizeof(struct batch));
}
else
- if (messagep->mboxfd != -1)
- close(messagep->mboxfd);
- if (messagep->messagefd != -1)
- close(messagep->messagefd);
+ if (s->mboxfd != -1)
+ close(s->mboxfd);
+ if (s->messagefd != -1)
+ close(s->messagefd);
mda_remove_message(env, batchp, messagep);
break;
@@ -262,14 +267,29 @@ mda_dispatch_runner(int sig, short event, void *p)
switch (imsg.hdr.type) {
case IMSG_BATCH_CREATE: {
- struct batch *batchp;
-
+ struct session *s;
+ struct batch *batchp;
+
+ /* create a client session */
+ if ((s = calloc(1, sizeof(*s))) == NULL)
+ fatal(NULL);
+ s->s_state = S_INIT;
+ s->s_env = env;
+ s->s_id = queue_generate_id();
+ SPLAY_INSERT(sessiontree, &s->s_env->sc_sessions, s);
+
+ /* create the batch for this session */
batchp = calloc(1, sizeof (struct batch));
if (batchp == NULL)
- fatal("calloc");
+ fatal("mda_dispatch_runner: calloc");
+
*batchp = *(struct batch *)imsg.data;
+ batchp->session_id = s->s_id;
batchp->env = env;
batchp->flags = 0;
+ batchp->sessionp = s;
+
+ s->batch = batchp;
TAILQ_INIT(&batchp->messages);
SPLAY_INSERT(batchtree, &env->batch_queue, batchp);
@@ -282,27 +302,39 @@ mda_dispatch_runner(int sig, short event, void *p)
messagep = calloc(1, sizeof (struct message));
if (messagep == NULL)
- fatal("calloc");
+ fatal("mda_dispatch_runner: calloc");
*messagep = *(struct message *)imsg.data;
+
batchp = batch_by_id(env, messagep->batch_id);
if (batchp == NULL)
fatalx("mda_dispatch_runner: internal inconsistency.");
- TAILQ_INSERT_TAIL(&batchp->messages, messagep, entry);
+ batchp->session_ss = messagep->session_ss;
+ strlcpy(batchp->session_hostname,
+ messagep->session_hostname,
+ sizeof(batchp->session_hostname));
+ strlcpy(batchp->session_helo, messagep->session_helo,
+ sizeof(batchp->session_helo));
+
+ TAILQ_INSERT_TAIL(&batchp->messages, messagep, entry);
break;
}
case IMSG_BATCH_CLOSE: {
+ struct batch *batchp;
+ struct session *s;
struct batch lookup;
- struct batch *batchp;
struct message *messagep;
- lookup = *(struct batch *)imsg.data;
- batchp = batch_by_id(env, lookup.id);
+ batchp = (struct batch *)imsg.data;
+ batchp = batch_by_id(env, batchp->id);
if (batchp == NULL)
fatalx("mda_dispatch_runner: internal inconsistency.");
+ batchp->flags |= F_BATCH_COMPLETE;
+ s = batchp->sessionp;
+
lookup = *batchp;
TAILQ_FOREACH(messagep, &batchp->messages, entry) {
lookup.message = *messagep;
@@ -310,7 +342,6 @@ mda_dispatch_runner(int sig, short event, void *p)
IMSG_PARENT_MAILBOX_OPEN, 0, 0, -1, &lookup,
sizeof(struct batch));
}
-
break;
}
default:
@@ -442,5 +473,8 @@ mda_remove_message(struct smtpd *env, struct batch *batchp, struct message *mess
time(NULL) - messagep->creation);
}
+ SPLAY_REMOVE(sessiontree, &env->sc_sessions, batchp->sessionp);
+ free(batchp->sessionp);
+
queue_remove_batch_message(env, batchp, messagep);
}