mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Avoid calling exit() during event_base_new*()
Previously, each of the three make-an-event-base functions would exit under different, weird circumstances, but return NULL on others. - All three would exit on OOM sometimes. - event_base_new() and event_init() would die if all backends were disabled. - None of them would die if the socketpair() call failed. Now, only event_init() exits on failure, and it exits on every kind of failure. event_base_new() and event_base_new_with_config() never do. svn:r1472
This commit is contained in:
parent
a2a7d1d123
commit
904b5721cb
@ -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:
|
||||
|
33
event.c
33
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"))
|
||||
|
@ -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),
|
||||
|
Loading…
x
Reference in New Issue
Block a user