diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2012-07-10 11:13:41 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2012-07-10 11:13:41 +0000 |
commit | 5683a9f2a556eddccba1ea28dd9d78ca61fe0d91 (patch) | |
tree | 37ae91f3a472c4a912d023a76b9109ad5351b4db /usr.sbin/smtpd | |
parent | 75db6922a00509f20b0e1e7dd8ae17f18492f733 (diff) |
- simplify the scheduler loop logic further, it is ridiculously simple now
and I don't think we can do much better (at that level) :-p
- always break out of the handler after processing an envelope, this will
avoid a busy scheduler from not getting a chance to handle SIGTERM/SIGINT
YES we can now ctrl-c a maaaaad scheduler !
ok eric@, ok chl@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/scheduler.c | 50 | ||||
-rw-r--r-- | usr.sbin/smtpd/scheduler_ramqueue.c | 27 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 4 |
3 files changed, 32 insertions, 49 deletions
diff --git a/usr.sbin/smtpd/scheduler.c b/usr.sbin/smtpd/scheduler.c index 92cb85ec348..a139f02bd48 100644 --- a/usr.sbin/smtpd/scheduler.c +++ b/usr.sbin/smtpd/scheduler.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scheduler.c,v 1.5 2012/07/09 17:57:54 gilles Exp $ */ +/* $OpenBSD: scheduler.c,v 1.6 2012/07/10 11:13:40 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -317,49 +317,39 @@ scheduler_timeout(int fd, short event, void *p) { time_t nsched; time_t curtm; - int schedulable; u_int64_t evpid; static int setup = 0; + int delay = 0; struct timeval tv; log_trace(TRACE_SCHEDULER, "scheduler: entering scheduler_timeout"); -again: - log_trace(TRACE_SCHEDULER, "scheduler: entering scheduler_timeout loop"); - - /* do we have something to schedule at some point in the future ? */ - schedulable = 0; - if (backend->next(NULL, &nsched)) - schedulable = 1; /* if we're not done setting up the scheduler, do it some more */ - curtm = time(NULL); if (! setup) - setup = backend->setup(curtm, nsched); + setup = backend->setup(); - /* we have nothing to schedule and we're done setting up the scheduler */ - if (! schedulable && setup) + /* we don't have a schedulable envelope ... sleep */ + if (! backend->next(&evpid, &nsched)) goto scheduler_sleep; - /* we have something to schedule, just not now, pause a little */ - if (nsched > curtm) - goto scheduler_pause; - - /* pop envelopes as long as they are schedulable */ - while (backend->next(&evpid, &nsched)) { - if (nsched > curtm) - goto scheduler_pause; - + /* is the envelope schedulable right away ? */ + curtm = time(NULL); + if (nsched <= curtm) { + /* yup */ scheduler_process_envelope(evpid); } + else { + /* nope, so we can either keep the timeout delay to 0 if we + * are not done setting up the scheduler, or sleep until it + * is time to schedule that envelope otherwise. + */ + if (setup) + delay = nsched - curtm; + } - /* nothing left to schedule, but we're not done setting scheduler */ - if (! setup) - goto again; - -scheduler_pause: - log_info("scheduler: pausing for %lld seconds", - (long long int)nsched - curtm); - tv.tv_sec = nsched - curtm; + if (delay) + log_info("scheduler: pausing for %d seconds", delay); + tv.tv_sec = delay; tv.tv_usec = 0; evtimer_add(&env->sc_ev, &tv); return; diff --git a/usr.sbin/smtpd/scheduler_ramqueue.c b/usr.sbin/smtpd/scheduler_ramqueue.c index baa675d532e..a2ab2f1254d 100644 --- a/usr.sbin/smtpd/scheduler_ramqueue.c +++ b/usr.sbin/smtpd/scheduler_ramqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scheduler_ramqueue.c,v 1.10 2012/06/20 20:45:23 eric Exp $ */ +/* $OpenBSD: scheduler_ramqueue.c,v 1.11 2012/07/10 11:13:40 gilles Exp $ */ /* * Copyright (c) 2012 Gilles Chehade <gilles@openbsd.org> @@ -116,11 +116,11 @@ static struct ramqueue_envelope *ramqueue_lookup_offload(u_int64_t); /*NEEDSFIX*/ -static int ramqueue_expire(struct envelope *, time_t); +static int ramqueue_expire(struct envelope *); static time_t ramqueue_next_schedule(struct scheduler_info *, time_t); static void scheduler_ramqueue_init(void); -static int scheduler_ramqueue_setup(time_t, time_t); +static int scheduler_ramqueue_setup(void); static int scheduler_ramqueue_next(u_int64_t *, time_t *); static void scheduler_ramqueue_insert(struct scheduler_info *); static void scheduler_ramqueue_schedule(u_int64_t); @@ -236,12 +236,11 @@ scheduler_ramqueue_init(void) } static int -scheduler_ramqueue_setup(time_t curtm, time_t nsched) +scheduler_ramqueue_setup(void) { struct envelope envelope; static struct qwalk *q = NULL; u_int64_t evpid; - time_t sched; struct scheduler_info si; log_debug("scheduler_ramqueue: load"); @@ -261,22 +260,14 @@ scheduler_ramqueue_setup(time_t curtm, time_t nsched) queue_message_corrupt(evpid_to_msgid(evpid)); continue; } - if (ramqueue_expire(&envelope, curtm)) + if (ramqueue_expire(&envelope)) continue; scheduler_info(&si, &envelope); scheduler_ramqueue_insert(&si); - - if (! scheduler_ramqueue_next(&evpid, &sched)) - continue; - if (sched <= nsched) - nsched = sched; - - if (nsched <= curtm) { - log_debug("ramqueue: loading interrupted"); - return (0); - } + log_debug("ramqueue: loading interrupted"); + return (0); } qwalk_close(q); q = NULL; @@ -669,11 +660,13 @@ ramqueue_lookup_batch(struct ramqueue_host *rq_host, u_int32_t msgid) } static int -ramqueue_expire(struct envelope *envelope, time_t curtm) +ramqueue_expire(struct envelope *envelope) { struct envelope bounce; struct scheduler_info si; + time_t curtm; + curtm = time(NULL); if (curtm - envelope->creation >= envelope->expire) { envelope_set_errormsg(envelope, "message expired after sitting in queue for %d days", diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index a38f9618e24..55aec5b3bd6 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.306 2012/07/09 17:57:54 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.307 2012/07/10 11:13:40 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -960,7 +960,7 @@ struct scheduler_info { struct scheduler_backend { void (*init)(void); - int (*setup)(time_t, time_t); + int (*setup)(void); int (*next)(u_int64_t *, time_t *); |