simplify handling of environment variables for disabling backends;

make event_get_supported_methods obey environment variables; this
fixes make verify; problem reported by Scott Lamb.


svn:r838
This commit is contained in:
Niels Provos 2008-05-29 01:39:43 +00:00
parent 8b66f1bd4d
commit 2deb3ce061
9 changed files with 43 additions and 44 deletions

View File

@ -102,7 +102,8 @@ Changes in current version:
o Fix connection keep-alive behavior for HTTP/1.0
o Fix use of freed memory in event_reinit; pointed out by Peter Postma
o constify struct timeval * where possible
o make event_get_supported_methods obey environment variables
Changes in 1.4.0:
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
o demote most http warnings to debug messages

View File

@ -131,10 +131,6 @@ devpoll_init(struct event_base *base)
struct rlimit rl;
struct devpollop *devpollop;
/* Disable devpoll when this environment variable is set */
if (getenv("EVENT_NODEVPOLL"))
return (NULL);
if (!(devpollop = mm_calloc(1, sizeof(struct devpollop))))
return (NULL);

View File

@ -112,10 +112,6 @@ epoll_init(struct event_base *base)
struct rlimit rl;
struct epollop *epollop;
/* Disable epollueue when this environment variable is set */
if (getenv("EVENT_NOEPOLL"))
return (NULL);
if (getrlimit(RLIMIT_NOFILE, &rl) == 0 &&
rl.rlim_cur != RLIM_INFINITY) {
/*

39
event.c
View File

@ -51,6 +51,7 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
@ -208,6 +209,19 @@ event_config_is_avoided_method(struct event_config *cfg, const char *method)
return (0);
}
static int
event_is_method_disabled(const char *name)
{
char environment[64];
int i;
evutil_snprintf(environment, sizeof(environment), "EVENT_NO%s", name);
for (i = 8; environment[i] != '\0'; ++i)
environment[i] = toupper(environment[i]);
return (getenv(environment) != NULL);
}
struct event_base *
event_base_new_with_config(struct event_config *cfg)
{
@ -238,6 +252,10 @@ event_base_new_with_config(struct event_config *cfg)
continue;
}
/* also obey the environment variables */
if (event_is_method_disabled(eventops[i]->name))
continue;
base->evsel = eventops[i];
base->evbase = base->evsel->init(base);
@ -247,8 +265,7 @@ event_base_new_with_config(struct event_config *cfg)
event_errx(1, "%s: no event mechanism available", __func__);
if (getenv("EVENT_SHOW_METHOD"))
event_msgx("libevent using: %s\n",
base->evsel->name);
event_msgx("libevent using: %s", base->evsel->name);
/* allocate a single active event queue */
event_base_priority_init(base, 1);
@ -356,12 +373,12 @@ event_get_supported_methods(void)
const char **tmp;
int i = 0, k;
if (methods != NULL)
return (methods);
/* count all methods */
for (method = &eventops[0]; *method != NULL; ++method)
for (method = &eventops[0]; *method != NULL; ++method) {
if (event_is_method_disabled((*method)->name))
continue;
++i;
}
/* allocate one more than we need for the NULL pointer */
tmp = mm_malloc((i + 1) * sizeof(char *));
@ -369,10 +386,16 @@ event_get_supported_methods(void)
return (NULL);
/* populate the array with the supported methods */
for (k = 0; k < i; ++k)
tmp[k] = eventops[k]->name;
for (k = 0, i = 0; eventops[k] != NULL; ++k) {
if (event_is_method_disabled(eventops[k]->name))
continue;
tmp[i++] = eventops[k]->name;
}
tmp[i] = NULL;
if (methods != NULL)
mm_free(methods);
methods = tmp;
return (methods);

View File

@ -141,11 +141,6 @@ evport_init(struct event_base *base)
{
struct evport_data *evpd;
int i;
/*
* Disable event ports when this environment variable is set
*/
if (getenv("EVENT_NOEVPORT"))
return (NULL);
if (!(evpd = mm_calloc(1, sizeof(struct evport_data))))
return (NULL);

View File

@ -99,10 +99,6 @@ kq_init(struct event_base *base)
int kq;
struct kqop *kqueueop;
/* Disable kqueue when this environment variable is set */
if (getenv("EVENT_NOKQUEUE"))
return (NULL);
if (!(kqueueop = mm_calloc(1, sizeof(struct kqop))))
return (NULL);

4
poll.c
View File

@ -87,10 +87,6 @@ poll_init(struct event_base *base)
{
struct pollop *pollop;
/* Disable poll when this environment variable is set */
if (getenv("EVENT_NOPOLL"))
return (NULL);
if (!(pollop = mm_calloc(1, sizeof(struct pollop))))
return (NULL);

View File

@ -94,10 +94,6 @@ select_init(struct event_base *base)
{
struct selectop *sop;
/* Disable select when this environment variable is set */
if (getenv("EVENT_NOSELECT"))
return (NULL);
if (!(sop = mm_calloc(1, sizeof(struct selectop))))
return (NULL);

View File

@ -495,7 +495,7 @@ test_fork(void)
if ((pid = fork()) == 0) {
/* in the child */
if (event_reinit(current_base) == -1) {
fprintf(stderr, "FAILED (reinit)\n");
fprintf(stdout, "FAILED (reinit)\n");
exit(1);
}
@ -515,12 +515,12 @@ test_fork(void)
write(pair[0], TEST1, strlen(TEST1)+1);
if (waitpid(pid, &status, 0) == -1) {
fprintf(stderr, "FAILED (fork)\n");
fprintf(stdout, "FAILED (fork)\n");
exit(1);
}
if (WEXITSTATUS(status) != 76) {
fprintf(stderr, "FAILED (exit): %d\n", WEXITSTATUS(status));
fprintf(stdout, "FAILED (exit): %d\n", WEXITSTATUS(status));
exit(1);
}
@ -1971,7 +1971,7 @@ rpc_test(void)
gettimeofday(&tv_end, NULL);
evutil_timersub(&tv_end, &tv_start, &tv_end);
fprintf(stderr, "(%.1f us/add) ",
fprintf(stdout, "(%.1f us/add) ",
(float)tv_end.tv_sec/(float)i * 1000000.0 +
tv_end.tv_usec / (float)i);
@ -2109,16 +2109,16 @@ test_methods(void)
const char *backend;
int n_methods = 0;
fprintf(stderr, "Testing supported methods: ");
fprintf(stdout, "Testing supported methods: ");
if (methods == NULL) {
fprintf(stderr, "FAILED\n");
fprintf(stdout, "FAILED\n");
exit(1);
}
backend = methods[0];
while (*methods != NULL) {
fprintf(stderr, "%s ", *methods);
fprintf(stdout, "%s ", *methods);
++methods;
++n_methods;
}
@ -2135,19 +2135,19 @@ test_methods(void)
base = event_base_new_with_config(cfg);
if (base == NULL) {
fprintf(stderr, "FAILED\n");
fprintf(stdout, "FAILED\n");
exit(1);
}
if (strcmp(backend, event_base_get_method(base)) == 0) {
fprintf(stderr, "FAILED\n");
fprintf(stdout, "FAILED\n");
exit(1);
}
event_base_free(base);
event_config_free(cfg);
done:
fprintf(stderr, "OK\n");
fprintf(stdout, "OK\n");
}