summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/util.c
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2012-08-08 08:50:43 +0000
committerEric Faurot <eric@cvs.openbsd.org>2012-08-08 08:50:43 +0000
commit4fb538ff7fe692fc3494a906f82178b14bf48bf1 (patch)
tree74c2a8e0bb894841c747e6bee85be58c05869135 /usr.sbin/smtpd/util.c
parente653821d1952b330839a2b474720109458d1d375 (diff)
Improve the scheduler backend API.
New envelopes are pushed into the scheduler through the insert() commit() rollback() transactional interface functions. Worklists are pulled from the scheduler through a single batch() interface function, which returns a list of envelope ids and the type of processing. Envelopes returned in this batch are said to be "in-flight", as opposed to "pending". They are supposed to be processed in some way, and either updated() or deleted() at some point. The schedule()/remove() functions are used to alter the internal state of "pending" envelopes to make them schedulable. The enve- lopes will be part of a worklist on the next call to batch(). Rewrite the scheduler_ramqueue backend. The initial queue loading in now done by the queue. ok gilles@
Diffstat (limited to 'usr.sbin/smtpd/util.c')
-rw-r--r--usr.sbin/smtpd/util.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index 7000a366c1d..8fa0beff0c4 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.68 2012/08/07 21:47:58 eric Exp $ */
+/* $OpenBSD: util.c,v 1.69 2012/08/08 08:50:42 eric Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -538,6 +538,51 @@ time_to_text(time_t when)
return buf;
}
+char *
+duration_to_text(time_t t)
+{
+ static char dst[64];
+ char buf[64];
+ int d, h, m, s;
+
+ if (t == 0) {
+ strlcpy(dst, "0s", sizeof dst);
+ return (dst);
+ }
+
+ dst[0] = '\0';
+ if (t < 0) {
+ strlcpy(dst, "-", sizeof dst);
+ t = -t;
+ }
+
+ s = t % 60;
+ t /= 60;
+ m = t % 60;
+ t /= 60;
+ h = t % 24;
+ d = t / 24;
+
+ if (d) {
+ snprintf(buf, sizeof buf, "%id", d);
+ strlcat(dst, buf, sizeof dst);
+ }
+ if (h) {
+ snprintf(buf, sizeof buf, "%ih", h);
+ strlcat(dst, buf, sizeof dst);
+ }
+ if (m) {
+ snprintf(buf, sizeof buf, "%im", m);
+ strlcat(dst, buf, sizeof dst);
+ }
+ if (s) {
+ snprintf(buf, sizeof buf, "%is", s);
+ strlcat(dst, buf, sizeof dst);
+ }
+
+ return (dst);
+}
+
int
text_to_netaddr(struct netaddr *netaddr, char *s)
{