diff options
Diffstat (limited to 'main/dns_core.c')
-rw-r--r-- | main/dns_core.c | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/main/dns_core.c b/main/dns_core.c index 3e270aff7..6f37a5d46 100644 --- a/main/dns_core.c +++ b/main/dns_core.c @@ -29,6 +29,7 @@ #include "asterisk.h" +#include "asterisk/_private.h" #include "asterisk/linkedlists.h" #include "asterisk/astobj2.h" #include "asterisk/strings.h" @@ -537,6 +538,22 @@ static void dns_shutdown(void) } } +int dns_core_init(void) +{ + sched = ast_sched_context_create(); + if (!sched) { + return -1; + } + + if (ast_sched_start_thread(sched)) { + return -1; + } + + ast_register_cleanup(dns_shutdown); + + return 0; +} + int ast_dns_resolver_register(struct ast_dns_resolver *resolver) { struct ast_dns_resolver *iter; @@ -559,27 +576,6 @@ int ast_dns_resolver_register(struct ast_dns_resolver *resolver) AST_RWLIST_WRLOCK(&resolvers); - /* On the first registration of a resolver start a scheduler for recurring queries */ - if (AST_LIST_EMPTY(&resolvers) && !sched) { - sched = ast_sched_context_create(); - if (!sched) { - ast_log(LOG_ERROR, "DNS resolver '%s' could not be registered: Failed to create scheduler for recurring DNS queries\n", - resolver->name); - AST_RWLIST_UNLOCK(&resolvers); - return -1; - } - - if (ast_sched_start_thread(sched)) { - ast_log(LOG_ERROR, "DNS resolver '%s' could not be registered: Failed to start thread for recurring DNS queries\n", - resolver->name); - dns_shutdown(); - AST_RWLIST_UNLOCK(&resolvers); - return -1; - } - - ast_register_cleanup(dns_shutdown); - } - AST_LIST_TRAVERSE(&resolvers, iter, next) { if (!strcmp(iter->name, resolver->name)) { ast_log(LOG_ERROR, "A DNS resolver with the name '%s' is already registered\n", resolver->name); |