summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgilles <gilles@openbsd.org>2012-01-12 22:40:16 +0000
committergilles <gilles@openbsd.org>2012-01-12 22:40:16 +0000
commitee2a58c0e3dd45d581dbfab0de9331fba03c6f65 (patch)
tree58bb5987afe9fc0ef7e79a50b47f2e85c6ca7a3c
parentnow that we no longer do a stateful iteration on schedule queue, we need (diff)
downloadwireguard-openbsd-ee2a58c0e3dd45d581dbfab0de9331fba03c6f65.tar.xz
wireguard-openbsd-ee2a58c0e3dd45d581dbfab0de9331fba03c6f65.zip
the ramqueue filling at startup was busted, it would load envelopes one by
one instead of doing it efficiently. fix runner_timeout() and ramqueue_load() so that at startup smtpd fills the ramqueue as long as there's no schedulable envelope in it, interrupts filling if there is and resume once it's scheduled. bug spotted by Nathanael Rensel, bug fix by me w/ help from eric@ tested by eric@ and I
-rw-r--r--usr.sbin/smtpd/ramqueue.c14
-rw-r--r--usr.sbin/smtpd/runner.c11
2 files changed, 16 insertions, 9 deletions
diff --git a/usr.sbin/smtpd/ramqueue.c b/usr.sbin/smtpd/ramqueue.c
index 8d21afb75f3..929c9cd6ab6 100644
--- a/usr.sbin/smtpd/ramqueue.c
+++ b/usr.sbin/smtpd/ramqueue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ramqueue.c,v 1.29 2012/01/12 22:00:21 gilles Exp $ */
+/* $OpenBSD: ramqueue.c,v 1.30 2012/01/12 22:40:16 gilles Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -133,7 +133,7 @@ ramqueue_load(struct ramqueue *rqueue, time_t *nsched)
while (qwalk(q, &evpid)) {
curtm = time(NULL);
if (! queue_envelope_load(Q_QUEUE, evpid, &envelope)) {
- log_debug("failed to load envelope");
+ log_debug("ramqueue: moved envelope to /corrupt");
queue_message_corrupt(Q_QUEUE, evpid_to_msgid(evpid));
continue;
}
@@ -141,10 +141,14 @@ ramqueue_load(struct ramqueue *rqueue, time_t *nsched)
continue;
ramqueue_insert(rqueue, &envelope, curtm);
- rq_evp = TAILQ_FIRST(&rqueue->queue);
- *nsched = rq_evp->sched;
+ rq_evp = ramqueue_next_envelope(rqueue);
+ if (rq_evp == NULL)
+ continue;
+
+ if (rq_evp->sched <= *nsched)
+ *nsched = rq_evp->sched;
- if (rq_evp->sched <= *nsched) {
+ if (*nsched <= curtm) {
log_debug("ramqueue: loading interrupted");
return (0);
}
diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c
index 7c41816d17e..f551856a8f3 100644
--- a/usr.sbin/smtpd/runner.c
+++ b/usr.sbin/smtpd/runner.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: runner.c,v 1.128 2012/01/12 22:00:21 gilles Exp $ */
+/* $OpenBSD: runner.c,v 1.129 2012/01/12 22:40:16 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -297,6 +297,8 @@ runner_timeout(int fd, short event, void *p)
time_t curtm;
nsched = 0;
+
+again:
rq_evp = ramqueue_first_envelope(rqueue);
if (rq_evp)
nsched = rq_evp->sched;
@@ -307,7 +309,6 @@ runner_timeout(int fd, short event, void *p)
if (! rq_done)
rq_done = ramqueue_load(rqueue, &nsched);
-
/* let's do the schedule dance baby ! */
curtm = time(NULL);
rq_evp = ramqueue_next_envelope(rqueue);
@@ -320,8 +321,7 @@ runner_timeout(int fd, short event, void *p)
rq_evp = ramqueue_next_envelope(rqueue);
}
- if (rq_evp == NULL ||
- (rq_done && ramqueue_is_empty(rqueue))) {
+ if (rq_evp == NULL && rq_done) {
log_debug("runner: nothing to schedule, wake me up. zZzZzZ");
return;
}
@@ -335,6 +335,9 @@ runner_timeout(int fd, short event, void *p)
nsched = 0;
}
+ if (nsched == 0)
+ goto again;
+
log_debug("runner: nothing to do for the next %lld seconds, zZzZzZ",
(long long int) nsched);