diff --git a/ChangeLog b/ChangeLog index cef1fda7..9f2922a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -35,6 +35,7 @@ Changes in 2.0.3-alpha: o Add an API to replace all fatal calls to exit() with a user-provided panic function. o Replace all assert() calls with a variant that is aware of the user-provided logging and panic functions. o Add a return value to event_assign so that it can fail rather than asserting when the user gives it bad input. event_set still dies on bad input. + o The event_base_new() and event_base_new_with_config() functions now never call exit() on failure. For backward "compatibility", event_init() still does, but more consistently. Changes in 2.0.2-alpha: diff --git a/event.c b/event.c index f0bed0c7..af202a63 100644 --- a/event.c +++ b/event.c @@ -189,10 +189,12 @@ gettime(struct event_base *base, struct timeval *tp) struct event_base * event_init(void) { - struct event_base *base = event_base_new(); + struct event_base *base = event_base_new_with_config(NULL); - if (base != NULL) - current_base = base; + if (base == NULL) + event_errx(1, "%s: Unable to construct event_base", __func__); + + current_base = base; return (base); } @@ -200,7 +202,13 @@ event_init(void) struct event_base * event_base_new(void) { - return (event_base_new_with_config(NULL)); + struct event_base *base = NULL; + struct event_config *cfg = event_config_new(); + if (cfg) { + base = event_base_new_with_config(cfg); + event_config_free(cfg); + } + return base; } static int @@ -263,8 +271,10 @@ event_base_new_with_config(struct event_config *cfg) struct event_base *base; int should_check_environment; - if ((base = mm_calloc(1, sizeof(struct event_base))) == NULL) - event_err(1, "%s: calloc", __func__); + if ((base = mm_calloc(1, sizeof(struct event_base))) == NULL) { + event_warn("%s: calloc", __func__); + return NULL; + } detect_monotonic(); gettime(base, &base->event_tv); @@ -308,13 +318,10 @@ event_base_new_with_config(struct event_config *cfg) } if (base->evbase == NULL) { - if (cfg == NULL) - event_errx(1, "%s: no event mechanism available", - __func__); - else { - event_base_free(base); - return NULL; - } + event_warnx("%s: no event mechanism available", + __func__); + event_base_free(base); + return NULL; } if (getenv("EVENT_SHOW_METHOD")) diff --git a/test/regress.c b/test/regress.c index eef9859b..e1929580 100644 --- a/test/regress.c +++ b/test/regress.c @@ -1789,7 +1789,7 @@ struct testcase_t main_testcases[] = { /* Some converted-over tests */ { "methods", test_methods, TT_FORK, NULL, NULL }, { "version", test_version, 0, NULL, NULL }, - { "base_features", test_base_features, TT_FORK, NULL, NULL }, + BASIC(base_features, TT_FORK|TT_NO_LOGS), { "base_environ", test_base_environ, TT_FORK, NULL, NULL }, BASIC(event_base_new, TT_FORK|TT_NEED_SOCKETPAIR),