-/* $OpenBSD: mta.c,v 1.227 2018/12/23 16:37:53 eric Exp $ */
+/* $OpenBSD: mta.c,v 1.228 2019/06/14 19:55:25 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
if (route->flags & ROUTE_DISABLED) {
log_info("smtp-out: Enabling route %s per admin request",
mta_route_to_text(route));
- if (!runq_cancel(runq_route, NULL, route)) {
+ if (!runq_cancel(runq_route, route)) {
log_warnx("warn: route not on runq");
fatalx("exiting");
}
case IMSG_CTL_MTA_SHOW_ROUTES:
SPLAY_FOREACH(route, mta_route_tree, &routes) {
- v = runq_pending(runq_route, NULL, route, &t);
+ v = runq_pending(runq_route, route, &t);
(void)snprintf(buf, sizeof(buf),
"%llu. %s %c%c%c%c nconn=%zu nerror=%d penalty=%d timeout=%s",
(unsigned long long)route->id,
if (c->flags & CONNECTOR_WAIT) {
log_debug("debug: mta: cancelling connector timeout");
- runq_cancel(runq_connector, NULL, c);
+ runq_cancel(runq_connector, c);
c->flags &= ~CONNECTOR_WAIT;
}
mta_connector_to_text(c),
(unsigned long long) nextconn - time(NULL));
c->flags |= CONNECTOR_WAIT;
- runq_schedule(runq_connector, nextconn, NULL, c);
+ runq_schedule_at(runq_connector, nextconn, c);
return;
}
mta_route_to_text(route), delay);
if (route->flags & ROUTE_DISABLED)
- runq_cancel(runq_route, NULL, route);
+ runq_cancel(runq_route, route);
else
mta_route_ref(route);
route->flags |= reason & ROUTE_DISABLED;
- runq_schedule(runq_route, time(NULL) + delay, NULL, route);
+ runq_schedule(runq_route, delay, route);
}
static void
log_debug("debug: mta: scheduling relay %s in %llus...",
mta_relay_to_text(r),
(unsigned long long) r->nextsource - time(NULL));
- runq_schedule(runq_relay, r->nextsource, NULL, r);
+ runq_schedule_at(runq_relay, r->nextsource, r);
r->status |= RELAY_WAIT_CONNECTOR;
mta_relay_ref(r);
}
SHOWSTATUS(RELAY_WAIT_CONNECTOR, "connector");
#undef SHOWSTATUS
- if (runq_pending(runq_relay, NULL, r, &to))
+ if (runq_pending(runq_relay, r, &to))
(void)snprintf(dur, sizeof(dur), "%s", duration_to_text(to - t));
else
(void)strlcpy(dur, "-", sizeof(dur));
iter = NULL;
while (tree_iter(&r->connectors, &iter, NULL, (void **)&c)) {
- if (runq_pending(runq_connector, NULL, c, &to))
+ if (runq_pending(runq_connector, c, &to))
(void)snprintf(dur, sizeof(dur), "%s", duration_to_text(to - t));
else
(void)strlcpy(dur, "-", sizeof(dur));
if (c->flags & CONNECTOR_WAIT) {
log_debug("debug: mta: cancelling timeout for %s",
mta_connector_to_text(c));
- runq_cancel(runq_connector, NULL, c);
+ runq_cancel(runq_connector, c);
}
mta_source_unref(c->source); /* from constructor */
free(c);
log_debug("debug: mta: mta_route_ref(): cancelling runq for route %s",
mta_route_to_text(r));
r->flags &= ~(ROUTE_RUNQ | ROUTE_KEEPALIVE);
- runq_cancel(runq_route, NULL, r);
+ runq_cancel(runq_route, r);
r->refcount--; /* from mta_route_unref() */
}
if (sched > now) {
r->flags |= ROUTE_RUNQ;
- runq_schedule(runq_route, sched, NULL, r);
+ runq_schedule_at(runq_route, sched, r);
r->refcount++;
return;
}
{
struct hoststat *hs = NULL;
char buf[HOST_NAME_MAX+1];
- time_t tm;
if (!lowercase(buf, host, sizeof buf))
return;
- tm = time(NULL);
hs = dict_get(&hoststat, buf);
if (hs == NULL) {
if ((hs = calloc(1, sizeof *hs)) == NULL)
return;
tree_init(&hs->deferred);
- runq_schedule(runq_hoststat, tm+HOSTSTAT_EXPIRE_DELAY, NULL, hs);
+ runq_schedule(runq_hoststat, HOSTSTAT_EXPIRE_DELAY, hs);
}
(void)strlcpy(hs->name, buf, sizeof hs->name);
(void)strlcpy(hs->error, error, sizeof hs->error);
hs->tm = time(NULL);
dict_set(&hoststat, buf, hs);
- runq_cancel(runq_hoststat, NULL, hs);
- runq_schedule(runq_hoststat, tm+HOSTSTAT_EXPIRE_DELAY, NULL, hs);
+ runq_cancel(runq_hoststat, hs);
+ runq_schedule(runq_hoststat, HOSTSTAT_EXPIRE_DELAY, hs);
}
void
while (tree_poproot(&hs->deferred, NULL, NULL))
;
dict_pop(&hoststat, hs->name);
- runq_cancel(runq_hoststat, NULL, hs);
+ runq_cancel(runq_hoststat, hs);
}
-/* $OpenBSD: mta_session.c,v 1.116 2019/06/12 17:42:53 eric Exp $ */
+/* $OpenBSD: mta_session.c,v 1.117 2019/06/14 19:55:25 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
if (s->flags & MTA_HANGON) {
log_debug("debug: mta: %p: cancelling hangon timer", s);
- runq_cancel(hangon, NULL, s);
+ runq_cancel(hangon, s);
}
if (s->io)
(long long)(s->relay->limits->sessdelay_keepalive -
s->hangon));
s->flags |= MTA_HANGON;
- runq_schedule(hangon, time(NULL) + 1, NULL, s);
+ runq_schedule(hangon, 1, s);
break;
}
(long long int)s->relay->limits->sessdelay_transaction);
s->hangon = s->relay->limits->sessdelay_transaction -1;
s->flags |= MTA_HANGON;
- runq_schedule(hangon, time(NULL)
- + s->relay->limits->sessdelay_transaction,
- NULL, s);
+ runq_schedule(hangon,
+ s->relay->limits->sessdelay_transaction, s);
}
else
mta_enter_state(s, MTA_READY);
(long long int)s->relay->limits->sessdelay_transaction);
s->hangon = s->relay->limits->sessdelay_transaction -1;
s->flags |= MTA_HANGON;
- runq_schedule(hangon, time(NULL)
- + s->relay->limits->sessdelay_transaction,
- NULL, s);
+ runq_schedule(hangon,
+ s->relay->limits->sessdelay_transaction, s);
}
else
mta_enter_state(s, MTA_READY);
-/* $OpenBSD: runq.c,v 1.2 2015/01/20 17:37:54 deraadt Exp $ */
+/* $OpenBSD: runq.c,v 1.3 2019/06/14 19:55:25 eric Exp $ */
/*
- * Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
+ * Copyright (c) 2013,2019 Eric Faurot <eric@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
struct job {
TAILQ_ENTRY(job) entry;
time_t when;
- void (*cb)(struct runq *, void *);
void *arg;
};
if (job->when > now)
break;
TAILQ_REMOVE(&runq->jobs, job, entry);
- if (job->cb)
- job->cb(runq, job->arg);
- else
- runq->cb(runq, job->arg);
+ runq->cb(runq, job->arg);
free(job);
}
}
int
-runq_schedule(struct runq *runq, time_t when, void (*cb)(struct runq *, void *),
- void *arg)
+runq_schedule(struct runq *runq, time_t delay, void *arg)
+{
+ time_t t;
+
+ time(&t);
+ return runq_schedule_at(runq, t + delay, arg);
+}
+
+int
+runq_schedule_at(struct runq *runq, time_t when, void *arg)
{
struct job *job, *tmpjob;
return (0);
job->arg = arg;
- job->cb = cb;
job->when = when;
TAILQ_FOREACH(tmpjob, &runq->jobs, entry) {
}
int
-runq_delay(struct runq *runq, unsigned int delay,
- void (*cb)(struct runq *, void *), void *arg)
-{
- return runq_schedule(runq, time(NULL) + delay, cb, arg);
-}
-
-int
-runq_cancel(struct runq *runq, void (*cb)(struct runq *, void *), void *arg)
+runq_cancel(struct runq *runq, void *arg)
{
struct job *job, *first;
first = TAILQ_FIRST(&runq->jobs);
TAILQ_FOREACH(job, &runq->jobs, entry) {
- if (job->cb == cb && job->arg == arg) {
+ if (job->arg == arg) {
TAILQ_REMOVE(&runq->jobs, job, entry);
free(job);
if (runq != active && job == first) {
}
int
-runq_pending(struct runq *runq, void (*cb)(struct runq *, void *), void *arg,
- time_t *when)
+runq_pending(struct runq *runq, void *arg, time_t *when)
{
struct job *job;
TAILQ_FOREACH(job, &runq->jobs, entry) {
- if (job->cb == cb && job->arg == arg) {
+ if (job->arg == arg) {
if (when)
*when = job->when;
return (1);
return (0);
}
-
-int
-runq_next(struct runq *runq, void (**cb)(struct runq *, void *), void **arg,
- time_t *when)
-{
- struct job *job;
-
- job = TAILQ_FIRST(&runq->jobs);
- if (job == NULL)
- return (0);
- if (cb)
- *cb = job->cb;
- if (arg)
- *arg = job->arg;
- if (when)
- *when = job->when;
-
- return (1);
-}
-/* $OpenBSD: smtpd.h,v 1.623 2019/06/13 11:45:35 eric Exp $ */
+/* $OpenBSD: smtpd.h,v 1.624 2019/06/14 19:55:25 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
struct runq;
int runq_init(struct runq **, void (*)(struct runq *, void *));
-int runq_schedule(struct runq *, time_t, void (*)(struct runq *, void *), void *);
-int runq_delay(struct runq *, unsigned int, void (*)(struct runq *, void *), void *);
-int runq_cancel(struct runq *, void (*)(struct runq *, void *), void *);
-int runq_pending(struct runq *, void (*)(struct runq *, void *), void *, time_t *);
-int runq_next(struct runq *, void (**)(struct runq *, void *), void **, time_t *);
+int runq_schedule(struct runq *, time_t, void *);
+int runq_schedule_at(struct runq *, time_t, void *);
+int runq_cancel(struct runq *, void *);
+int runq_pending(struct runq *, void *, time_t *);