diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2009-03-15 19:15:26 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2009-03-15 19:15:26 +0000 |
commit | b6b944aa351d07fa3a8e68b0f477b46eac779338 (patch) | |
tree | 34a243a8e3390113c9066069feb80e340281153a | |
parent | cba696bab4080fdc038f23657d90ba4a1ddd1f37 (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.
-rw-r--r-- | usr.sbin/smtpd/mda.c | 74 | ||||
-rw-r--r-- | usr.sbin/smtpd/mta.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/runner.c | 8 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 7 | ||||
-rw-r--r-- | usr.sbin/smtpd/store.c | 14 |
5 files changed, 67 insertions, 40 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); } diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c index 54631222150..480e37dd2f7 100644 --- a/usr.sbin/smtpd/mta.c +++ b/usr.sbin/smtpd/mta.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta.c,v 1.34 2009/03/12 11:08:26 pea Exp $ */ +/* $OpenBSD: mta.c,v 1.35 2009/03/15 19:15:25 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -367,7 +367,6 @@ mta_dispatch_runner(int sig, short event, void *p) sizeof(batchp->session_helo)); TAILQ_INSERT_TAIL(&batchp->messages, messagep, entry); - break; } case IMSG_BATCH_CLOSE: { @@ -1081,4 +1080,5 @@ mta_batch_update_queue(struct batch *batchp) fclose(batchp->messagefp); free(batchp); + } diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c index 9d46ed1f579..5e0c7bca9f2 100644 --- a/usr.sbin/smtpd/runner.c +++ b/usr.sbin/smtpd/runner.c @@ -1,4 +1,4 @@ -/* $OpenBSD: runner.c,v 1.34 2009/03/09 01:43:19 gilles Exp $ */ +/* $OpenBSD: runner.c,v 1.35 2009/03/15 19:15:25 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -608,10 +608,6 @@ runner_process_batchqueue(struct smtpd *env) batchp != NULL; batchp = nxt) { nxt = SPLAY_NEXT(batchtree, &env->batch_queue, batchp); -// if ((batchp->type & T_MTA_BATCH) && -// (batchp->flags & F_BATCH_RESOLVED) == 0) { -// continue; -// } runner_batch_dispatch(env, batchp, curtime); @@ -857,8 +853,6 @@ batch_record(struct smtpd *env, struct message *messagep) } else { batchp->type |= T_MTA_BATCH; -// imsg_compose(env->sc_ibufs[PROC_LKA], IMSG_LKA_MX, -// 0, 0, -1, batchp, sizeof(struct batch)); } } diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 0bfcc2cd34a..9cd19ee4789 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.92 2009/03/15 18:12:15 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.93 2009/03/15 19:15:25 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -457,9 +457,6 @@ struct message { u_int8_t retry; enum message_flags flags; enum message_status status; - - int mboxfd; - int messagefd; }; enum batch_status { @@ -617,6 +614,8 @@ struct session { TAILQ_HEAD(mxhostlist, mxhost) mxhosts; FILE *datafp; + int mboxfd; + int messagefd; }; struct smtpd { diff --git a/usr.sbin/smtpd/store.c b/usr.sbin/smtpd/store.c index 512040ccaf8..437d1de8a4c 100644 --- a/usr.sbin/smtpd/store.c +++ b/usr.sbin/smtpd/store.c @@ -1,4 +1,4 @@ -/* $OpenBSD: store.c,v 1.16 2009/03/12 11:08:26 pea Exp $ */ +/* $OpenBSD: store.c,v 1.17 2009/03/15 19:15:25 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -141,11 +141,11 @@ store_write_daemon(struct batch *batchp, struct message *messagep) FILE *mboxfp; FILE *messagefp; - mboxfp = fdopen(messagep->mboxfd, "a"); + mboxfp = fdopen(batchp->sessionp->mboxfd, "a"); if (mboxfp == NULL) return 0; - messagefp = fdopen(messagep->messagefd, "r"); + messagefp = fdopen(batchp->sessionp->messagefd, "r"); if (messagefp == NULL) goto bad; @@ -237,11 +237,11 @@ store_write_message(struct batch *batchp, struct message *messagep) FILE *mboxfp; FILE *messagefp; - mboxfp = fdopen(messagep->mboxfd, "a"); + mboxfp = fdopen(batchp->sessionp->mboxfd, "a"); if (mboxfp == NULL) return 0; - messagefp = fdopen(messagep->messagefd, "r"); + messagefp = fdopen(batchp->sessionp->messagefd, "r"); if (messagefp == NULL) goto bad; @@ -273,12 +273,12 @@ store_message(struct batch *batchp, struct message *messagep, { struct stat sb; - if (fstat(messagep->mboxfd, &sb) == -1) + if (fstat(batchp->sessionp->mboxfd, &sb) == -1) return 0; if (! writer(batchp, messagep)) { if (S_ISREG(sb.st_mode)) { - ftruncate(messagep->mboxfd, sb.st_size); + ftruncate(batchp->sessionp->mboxfd, sb.st_size); return 0; } return 0; |