summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-12-14 16:44:15 +0000
committerJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-12-14 16:44:15 +0000
commit034a0252a19eeacb9c170b4e9e717523762a88ed (patch)
tree6946497f3035e5820fcaf2bcf9d23cc4b63b108d /usr.sbin
parent08715c4cca55339b6172439518c6befab992639b (diff)
Impose sessions limit on the delivery sessions (mta and mda).
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/mda.c5
-rw-r--r--usr.sbin/smtpd/mta.c9
-rw-r--r--usr.sbin/smtpd/queue.c4
-rw-r--r--usr.sbin/smtpd/runner.c31
-rw-r--r--usr.sbin/smtpd/smtpctl.c6
-rw-r--r--usr.sbin/smtpd/smtpd.h6
6 files changed, 47 insertions, 14 deletions
diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c
index 4886f8931bd..6f5c8e43e95 100644
--- a/usr.sbin/smtpd/mda.c
+++ b/usr.sbin/smtpd/mda.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mda.c,v 1.33 2009/12/14 13:17:51 jacekm Exp $ */
+/* $OpenBSD: mda.c,v 1.34 2009/12/14 16:44:14 jacekm Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -535,6 +535,9 @@ mda_done(struct smtpd *env, struct batch *b)
IMSG_QUEUE_MESSAGE_UPDATE, 0, 0, -1,
&b->message, sizeof(b->message));
+ imsg_compose_event(env->sc_ievs[PROC_RUNNER],
+ IMSG_BATCH_DONE, 0, 0, -1, NULL, 0);
+
/* log status */
log_info("%s: to=<%s@%s>, delay=%d, stat=%s",
b->message.message_id,
diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c
index 660fd113afd..7f014b64e82 100644
--- a/usr.sbin/smtpd/mta.c
+++ b/usr.sbin/smtpd/mta.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mta.c,v 1.81 2009/12/12 14:03:59 jacekm Exp $ */
+/* $OpenBSD: mta.c,v 1.82 2009/12/14 16:44:14 jacekm Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -249,9 +249,6 @@ mta_dispatch_runner(int sig, short event, void *p)
TAILQ_INIT(&s->recipients);
TAILQ_INIT(&s->relays);
SPLAY_INSERT(mtatree, &env->mta_sessions, s);
-
- env->stats->mta.sessions++;
- env->stats->mta.sessions_active++;
break;
}
@@ -693,9 +690,11 @@ mta_enter_state(struct mta_session *s, int newstate, void *p)
while ((m = TAILQ_FIRST(&s->recipients)))
mta_message_done(s, m);
+ imsg_compose_event(s->env->sc_ievs[PROC_RUNNER],
+ IMSG_BATCH_DONE, 0, 0, -1, NULL, 0);
+
/* deallocate resources */
SPLAY_REMOVE(mtatree, &s->env->mta_sessions, s);
- s->env->stats->mta.sessions_active--;
while ((relay = TAILQ_FIRST(&s->relays))) {
TAILQ_REMOVE(&s->relays, relay, entry);
free(relay);
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c
index d43164ac4c4..8d6a505efdf 100644
--- a/usr.sbin/smtpd/queue.c
+++ b/usr.sbin/smtpd/queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue.c,v 1.74 2009/12/13 22:02:55 jacekm Exp $ */
+/* $OpenBSD: queue.c,v 1.75 2009/12/14 16:44:14 jacekm Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -585,6 +585,8 @@ queue(struct smtpd *env)
* increase relative to default.
*/
fdlimit(getdtablesize() * 2);
+ if ((env->sc_maxconn = availdesc() / 4) < 1)
+ fatalx("runner: fd starvation");
config_pipes(env, peers, nitems(peers));
config_peers(env, peers, nitems(peers));
diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c
index e68cd5d9176..1592cbe19d1 100644
--- a/usr.sbin/smtpd/runner.c
+++ b/usr.sbin/smtpd/runner.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: runner.c,v 1.73 2009/12/13 22:02:55 jacekm Exp $ */
+/* $OpenBSD: runner.c,v 1.74 2009/12/14 16:44:14 jacekm Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -304,6 +304,10 @@ runner_dispatch_mda(int sig, short event, void *p)
break;
switch (imsg.hdr.type) {
+ case IMSG_BATCH_DONE:
+ env->stats->mda.sessions_active--;
+ break;
+
default:
log_warnx("runner_dispatch_mda: got imsg %d",
imsg.hdr.type);
@@ -349,6 +353,9 @@ runner_dispatch_mta(int sig, short event, void *p)
break;
switch (imsg.hdr.type) {
+ case IMSG_BATCH_DONE:
+ env->stats->mta.sessions_active--;
+ break;
default:
log_warnx("runner_dispatch_mta: got imsg %d",
@@ -550,6 +557,8 @@ runner(struct smtpd *env)
/* see fdlimit()-related comment in queue.c */
fdlimit(getdtablesize() * 2);
+ if ((env->sc_maxconn = availdesc() / 4) < 1)
+ fatalx("runner: fd starvation");
config_pipes(env, peers, nitems(peers));
config_peers(env, peers, nitems(peers));
@@ -632,13 +641,19 @@ runner_process_queue(struct smtpd *env)
if (! queue_load_envelope(&message, basename(path)))
continue;
- if (message.type & T_MDA_MESSAGE)
+ if (message.type & T_MDA_MESSAGE) {
if (env->sc_opts & SMTPD_MDA_PAUSED)
continue;
+ if (env->stats->mda.sessions_active >= env->sc_maxconn)
+ continue;
+ }
- if (message.type & T_MTA_MESSAGE)
+ if (message.type & T_MTA_MESSAGE) {
if (env->sc_opts & SMTPD_MTA_PAUSED)
continue;
+ if (env->stats->mta.sessions_active >= env->sc_maxconn)
+ continue;
+ }
if (! runner_message_schedule(&message, now))
continue;
@@ -665,6 +680,16 @@ runner_process_queue(struct smtpd *env)
break;
fatal("runner_process_queue: symlink");
}
+
+ if (message.type & T_MDA_MESSAGE) {
+ env->stats->mda.sessions_active++;
+ env->stats->mda.sessions++;
+ }
+
+ if (message.type & T_MTA_MESSAGE) {
+ env->stats->mta.sessions_active++;
+ env->stats->mta.sessions++;
+ }
}
qwalk_close(q);
diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
index 89446dba2e1..6316de3e4b2 100644
--- a/usr.sbin/smtpd/smtpctl.c
+++ b/usr.sbin/smtpd/smtpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpctl.c,v 1.42 2009/12/13 22:02:55 jacekm Exp $ */
+/* $OpenBSD: smtpctl.c,v 1.43 2009/12/14 16:44:14 jacekm Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -276,7 +276,9 @@ show_stats_output(struct imsg *imsg)
printf("control.sessions=%zd\n", stats->control.sessions);
printf("control.sessions_active=%zd\n", stats->control.sessions_active);
- printf("mda.errors.write_system=%zd\n", stats->mda.write_error);
+ printf("mda.sessions=%zd\n", stats->mda.sessions);
+ printf("mda.sessions.active=%zd\n", stats->mda.sessions_active);
+
printf("mta.sessions=%zd\n", stats->mta.sessions);
printf("mta.sessions.active=%zd\n", stats->mta.sessions_active);
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 38a591e81a1..54b1719f99c 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.162 2009/12/14 13:17:51 jacekm Exp $ */
+/* $OpenBSD: smtpd.h,v 1.163 2009/12/14 16:44:14 jacekm Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -162,6 +162,7 @@ enum imsg_type {
IMSG_BATCH_CREATE,
IMSG_BATCH_APPEND,
IMSG_BATCH_CLOSE,
+ IMSG_BATCH_DONE,
IMSG_PARENT_ENQUEUE_OFFLINE,
IMSG_PARENT_FORWARD_OPEN,
@@ -673,7 +674,8 @@ struct s_session {
};
struct s_mda {
- size_t write_error;
+ size_t sessions;
+ size_t sessions_active;
};
struct s_control {