tzset();
#endif
daemon->need_to_exit = 0;
- memset(&daemon->mods, 0, sizeof(daemon->mods));
+ modstack_init(&daemon->mods);
if(!(daemon->env = (struct module_env*)calloc(1,
sizeof(*daemon->env)))) {
free(daemon);
daemon->env->alloc = &daemon->superalloc;
daemon->env->worker = NULL;
daemon->env->need_to_validate = 0; /* set by module init below */
- if(daemon->mods.num != 0)
- modstack_deinit(&daemon->mods, daemon->env);
- if(!modstack_call_init(&daemon->mods, daemon->cfg->module_conf,
+ if(!modstack_setup(&daemon->mods, daemon->cfg->module_conf,
daemon->env)) {
fatal_exit("failed to setup modules");
}
size_t i;
if(!daemon)
return;
- modstack_deinit(&daemon->mods, daemon->env);
+ modstack_desetup(&daemon->mods, daemon->env);
modstack_destartup(&daemon->mods, daemon->env);
daemon_remote_delete(daemon->rc);
for(i = 0; i < daemon->num_ports; i++)
#include "iterator/iter_fwd.h"
#include "iterator/iter_hints.h"
-/** If the modules have started, once. */
-int modstack_started = 0;
-
int
context_finalize(struct ub_ctx* ctx)
{
ctx->pipe_pid = getpid();
cfg_apply_local_port_policy(cfg, 65536);
config_apply(cfg);
- if(!modstack_started) {
- modstack_started = 1;
- if(!modstack_startup(&ctx->mods, cfg->module_conf, ctx->env))
- return UB_INITFAIL;
- }
- if(!modstack_call_init(&ctx->mods, cfg->module_conf, ctx->env))
+ if(!modstack_startup(&ctx->mods, cfg->module_conf, ctx->env))
+ return UB_INITFAIL;
+ if(!modstack_setup(&ctx->mods, cfg->module_conf, ctx->env))
return UB_INITFAIL;
listen_setup_locks();
log_edns_known_options(VERB_ALGO, ctx->env);
struct ctx_query* context_deserialize_cancel(struct ub_ctx* ctx,
uint8_t* p, uint32_t len);
-/** If the modules have started. */
-extern int modstack_started;
-
#endif /* LIBUNBOUND_CONTEXT_H */
ctx->env->alloc = &ctx->superalloc;
ctx->env->worker = NULL;
ctx->env->need_to_validate = 0;
- memset(&ctx->mods, 0, sizeof(ctx->mods));
+ modstack_init(&ctx->mods);
ctx->env->modstack = &ctx->mods;
rbtree_init(&ctx->queries, &context_query_cmp);
return ctx;
int e = errno;
ub_randfree(ctx->seed_rnd);
config_delete(ctx->env->cfg);
- modstack_deinit(&ctx->mods, ctx->env);
+ modstack_desetup(&ctx->mods, ctx->env);
modstack_destartup(&ctx->mods, ctx->env);
listen_desetup_locks();
edns_known_options_delete(ctx->env);
tube_delete(ctx->qq_pipe);
ub_randfree(ctx->seed_rnd);
config_delete(ctx->env->cfg);
- modstack_deinit(&ctx->mods, ctx->env);
+ modstack_desetup(&ctx->mods, ctx->env);
modstack_destartup(&ctx->mods, ctx->env);
listen_desetup_locks();
edns_known_options_delete(ctx->env);
}
libworker_delete_event(ctx->event_worker);
- modstack_deinit(&ctx->mods, ctx->env);
+ modstack_desetup(&ctx->mods, ctx->env);
modstack_destartup(&ctx->mods, ctx->env);
a = ctx->alloc_list;
while(a) {
return num;
}
+void
+modstack_init(struct module_stack* stack)
+{
+ stack->num = 0;
+ stack->mod = NULL;
+}
+
int
modstack_config(struct module_stack* stack, const char* module_conf)
{
modstack_startup(struct module_stack* stack, const char* module_conf,
struct module_env* env)
{
- int i;
- if (stack->num != 0)
+ int i;
+ if(stack->num != 0)
fatal_exit("unexpected already initialised modules");
/* fixed setup of the modules */
if(!modstack_config(stack, module_conf)) {
}
int
-modstack_call_init(struct module_stack* stack, const char* module_conf,
+modstack_setup(struct module_stack* stack, const char* module_conf,
struct module_env* env)
{
int i;
- env->need_to_validate = 0; /* set by module setup below */
+ if(stack->num != 0)
+ modstack_desetup(stack, env);
+ env->need_to_validate = 0; /* set by module init below */
for(i=0; i<stack->num; i++) {
while(*module_conf && isspace(*module_conf))
module_conf++;
}
void
-modstack_deinit(struct module_stack* stack, struct module_env* env)
+modstack_desetup(struct module_stack* stack, struct module_env* env)
{
int i;
for(i=0; i<stack->num; i++) {
struct module_func_block** mod;
};
+/**
+ * Init a stack of modules
+ * @param stack: initialised as empty.
+ */
+void modstack_init(struct module_stack* stack);
+
/**
* Initialises modules and assignes ids.
* @param stack: Expected empty, filled according to module_conf
* env.need_to_validate is set by the modules.
* @return on false a module init failed.
*/
-int modstack_call_init(struct module_stack* stack, const char* module_conf,
+int modstack_setup(struct module_stack* stack, const char* module_conf,
struct module_env* env);
/**
- * Deinint the modules
+ * Desetup the modules, deinit.
* @param stack: made empty.
* @param env: module env for module deinit() calls.
*/
-void modstack_deinit(struct module_stack* stack, struct module_env* env);
+void modstack_desetup(struct module_stack* stack, struct module_env* env);
/**
* Destartup the modules, close, delete.
memset(&mods, 0, sizeof(mods));
if(!modstack_startup(&mods, env.cfg->module_conf, &env))
fatal_exit("could not modstack_startup");
- if(!modstack_call_init(&mods, env.cfg->module_conf, &env))
+ if(!modstack_setup(&mods, env.cfg->module_conf, &env))
fatal_exit("could not modstack_call_init");
env.mesh = mesh_create(&mods, &env);
if(!env.mesh)
/* desetup test harness */
mesh_delete(env.mesh);
- modstack_deinit(&mods, &env);
+ modstack_desetup(&mods, &env);
modstack_destartup(&mods, &env);
auth_zones_delete(env.auth_zones);
anchors_delete(env.anchors);