summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2012-07-02 17:00:06 +0000
committerEric Faurot <eric@cvs.openbsd.org>2012-07-02 17:00:06 +0000
commit8d2124f0c3865afc766782f0262d603bd9fdd549 (patch)
treed90eb4664412823443c3c08a31cf1a10c66f70b8 /usr.sbin
parent63459499c001e32644c0a796515e67c91964a158 (diff)
Lookup queue and scheduler backends by name, rather than enum.
Add a command-line option to specify the backend to use at runtime. ok gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/queue_backend.c12
-rw-r--r--usr.sbin/smtpd/runner.c8
-rw-r--r--usr.sbin/smtpd/scheduler.c10
-rw-r--r--usr.sbin/smtpd/smtpctl.c4
-rw-r--r--usr.sbin/smtpd/smtpd.c22
-rw-r--r--usr.sbin/smtpd/smtpd.h18
6 files changed, 35 insertions, 39 deletions
diff --git a/usr.sbin/smtpd/queue_backend.c b/usr.sbin/smtpd/queue_backend.c
index f539eb0d2b8..50625760ac5 100644
--- a/usr.sbin/smtpd/queue_backend.c
+++ b/usr.sbin/smtpd/queue_backend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_backend.c,v 1.24 2012/06/20 20:45:23 eric Exp $ */
+/* $OpenBSD: queue_backend.c,v 1.25 2012/07/02 17:00:05 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -40,21 +40,15 @@
static const char* envelope_validate(struct envelope *, uint64_t);
-/* fsqueue backend */
extern struct queue_backend queue_backend_fs;
struct queue_backend *
-queue_backend_lookup(enum queue_type type)
+queue_backend_lookup(const char *name)
{
- switch (type) {
- case QT_FS:
+ if (!strcmp(name, "fs"))
return &queue_backend_fs;
- default:
- fatalx("invalid queue type");
- }
-
return (NULL);
}
diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c
index 4c3ac999d68..68e518ccb6a 100644
--- a/usr.sbin/smtpd/runner.c
+++ b/usr.sbin/smtpd/runner.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: runner.c,v 1.141 2012/06/20 20:45:23 eric Exp $ */
+/* $OpenBSD: runner.c,v 1.142 2012/07/02 17:00:05 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -60,6 +60,8 @@ static int runner_message_to_scheduler(u_int32_t);
static struct scheduler_backend *scheduler = NULL;
+extern const char *backend_scheduler;
+
void
runner_imsg(struct imsgev *iev, struct imsg *imsg)
{
@@ -264,7 +266,9 @@ runner(void)
if ((env->sc_maxconn = availdesc() / 4) < 1)
fatalx("runner: fd starvation");
- env->sc_scheduler = scheduler_backend_lookup(SCHED_RAMQUEUE);
+ env->sc_scheduler = scheduler_backend_lookup(backend_scheduler);
+ if (env->sc_scheduler == NULL)
+ errx(1, "cannot find scheduler backend \"%s\"", backend_scheduler);
scheduler = env->sc_scheduler;
scheduler->init();
diff --git a/usr.sbin/smtpd/scheduler.c b/usr.sbin/smtpd/scheduler.c
index a81769d1f70..3c835db6927 100644
--- a/usr.sbin/smtpd/scheduler.c
+++ b/usr.sbin/smtpd/scheduler.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scheduler.c,v 1.2 2012/06/17 15:17:08 gilles Exp $ */
+/* $OpenBSD: scheduler.c,v 1.3 2012/07/02 17:00:05 eric Exp $ */
/*
* Copyright (c) 2012 Gilles Chehade <gilles@openbsd.org>
@@ -37,14 +37,10 @@
extern struct scheduler_backend scheduler_backend_ramqueue;
struct scheduler_backend *
-scheduler_backend_lookup(enum scheduler_type type)
+scheduler_backend_lookup(const char *name)
{
- switch (type) {
- case SCHED_RAMQUEUE:
+ if (!strcmp(name, "ramqueue"))
return &scheduler_backend_ramqueue;
- default:
- fatal("unsupported scheduler_backend type");
- }
return NULL;
}
diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
index 0926c5f7143..cd06a80bf0f 100644
--- a/usr.sbin/smtpd/smtpctl.c
+++ b/usr.sbin/smtpd/smtpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpctl.c,v 1.81 2012/06/20 20:45:23 eric Exp $ */
+/* $OpenBSD: smtpctl.c,v 1.82 2012/07/02 17:00:05 eric Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -80,7 +80,7 @@ setup_env(struct smtpd *smtpd)
if ((env->sc_pw = getpwnam(SMTPD_USER)) == NULL)
errx(1, "unknown user %s", SMTPD_USER);
- env->sc_queue = queue_backend_lookup(QT_FS);
+ env->sc_queue = queue_backend_lookup("fs");
if (env->sc_queue == NULL)
errx(1, "could not find queue backend");
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index 9cfda52a2d3..0f3a0e76f2d 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.151 2012/06/01 14:55:09 eric Exp $ */
+/* $OpenBSD: smtpd.c,v 1.152 2012/07/02 17:00:05 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -91,6 +91,9 @@ void (*imsg_callback)(struct imsgev *, struct imsg *);
struct smtpd *env = NULL;
+const char *backend_queue = "fs";
+const char *backend_scheduler = "ramqueue";
+
static void
parent_imsg(struct imsgev *iev, struct imsg *imsg)
{
@@ -444,8 +447,16 @@ main(int argc, char *argv[])
TAILQ_INIT(&offline_q);
- while ((c = getopt(argc, argv, "dD:nP:f:T:v")) != -1) {
+ while ((c = getopt(argc, argv, "B:dD:nP:f:T:v")) != -1) {
switch (c) {
+ case 'B':
+ if (strstr(optarg, "queue=") == optarg)
+ backend_queue = strchr(optarg, '=') + 1;
+ else if (strstr(optarg, "scheduler=") == optarg)
+ backend_scheduler = strchr(optarg, '=') + 1;
+ else
+ log_warnx("invalid backend specifier %s", optarg);
+ break;
case 'd':
debug = 2;
verbose |= TRACE_VERBOSE;
@@ -528,9 +539,12 @@ main(int argc, char *argv[])
if (ckdir(PATH_SPOOL PATH_PURGE, 0700, env->sc_pw->pw_uid, 0, 1) == 0)
errx(1, "error in purge directory setup");
- env->sc_queue = queue_backend_lookup(QT_FS);
+ log_debug("using \"%s\" queue backend", backend_queue);
+ log_debug("using \"%s\" scheduler backend", backend_scheduler);
+
+ env->sc_queue = queue_backend_lookup(backend_queue);
if (env->sc_queue == NULL)
- errx(1, "could not find queue backend");
+ errx(1, "could not find queue backend \"%s\"", backend_queue);
if (!env->sc_queue->init(1))
errx(1, "could not initialize queue backend");
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 57bb6422181..f3df0852c1a 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.301 2012/06/20 20:45:23 eric Exp $ */
+/* $OpenBSD: smtpd.h,v 1.302 2012/07/02 17:00:05 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -886,12 +886,6 @@ struct map_netaddr {
struct netaddr netaddr;
};
-/* queue structures */
-enum queue_type {
- QT_INVALID=0,
- QT_FS
-};
-
enum queue_op {
QOP_INVALID=0,
QOP_CREATE,
@@ -951,12 +945,6 @@ struct delivery_backend {
void (*open)(struct deliver *);
};
-
-/* scheduler_backend */
-enum scheduler_type {
- SCHED_RAMQUEUE,
-};
-
struct scheduler_info {
u_int64_t evpid;
char destination[MAXHOSTNAMELEN];
@@ -1121,7 +1109,7 @@ void queue_commit_envelopes(struct envelope *);
/* queue_backend.c */
u_int32_t queue_generate_msgid(void);
u_int64_t queue_generate_evpid(u_int32_t msgid);
-struct queue_backend *queue_backend_lookup(enum queue_type);
+struct queue_backend *queue_backend_lookup(const char *);
int queue_message_create(u_int32_t *);
int queue_message_delete(u_int32_t);
int queue_message_commit(u_int32_t);
@@ -1143,7 +1131,7 @@ void message_reset_flags(struct envelope *);
/* scheduler.c */
-struct scheduler_backend *scheduler_backend_lookup(enum scheduler_type);
+struct scheduler_backend *scheduler_backend_lookup(const char *);
void scheduler_info(struct scheduler_info *, struct envelope *);