static int dynmasq_init(void) { #if defined(PR_SHARED_MODULE) pr_event_register(&dynmasq_module, "core.module-unload", dynmasq_mod_unload_ev, NULL); #endif /* !PR_SHARED_MODULE */ pr_event_register(&dynmasq_module, "core.postparse", dynmasq_postparse_ev, NULL); pr_event_register(&dynmasq_module, "core.restart", dynmasq_restart_ev, NULL); #ifdef PR_USE_CTRLS if (pr_ctrls_register(&dynmasq_module, "dynmasq", "mod_dynmasq controls", dynmasq_handle_dynmasq) < 0) { pr_log_pri(PR_LOG_NOTICE, MOD_DYNMASQ_VERSION ": error registering 'dynmasq' control: %s", strerror(errno)); } else { register unsigned int i; dynmasq_act_pool = make_sub_pool(permanent_pool); pr_pool_tag(dynmasq_act_pool, "DynMasq Controls Pool"); for (i = 0; dynmasq_acttab[i].act_action; i++) { dynmasq_acttab[i].act_acl = palloc(dynmasq_act_pool, sizeof(ctrls_acl_t)); pr_ctrls_init_acl(dynmasq_acttab[i].act_acl); } } #endif /* PR_USE_CTRLS */ return 0; }
static void dynmasq_restart_ev(const void *event_data, void *user_data) { #ifdef PR_USE_CTRLS register unsigned int i; #endif /* PR_USE_CTRLS */ if (dynmasq_timer_id != -1) { pr_timer_remove(dynmasq_timer_id, &dynmasq_module); dynmasq_timer_id = -1; } #ifdef PR_USE_CTRLS if (dynmasq_act_pool) { destroy_pool(dynmasq_act_pool); dynmasq_act_pool = NULL; } dynmasq_act_pool = make_sub_pool(permanent_pool); pr_pool_tag(dynmasq_act_pool, "DynMasq Controls Pool"); /* Re-create the controls ACLs. */ for (i = 0; dynmasq_acttab[i].act_action; i++) { dynmasq_acttab[i].act_acl = palloc(dynmasq_act_pool, sizeof(ctrls_acl_t)); pr_ctrls_init_acl(dynmasq_acttab[i].act_acl); } #endif /* PR_USE_CTRLS */ }
static int dso_init(void) { #ifdef PR_USE_CTRLS register unsigned int i = 0; #endif /* PR_USE_CTRLS */ /* Allocate the pool for this module's use. */ dso_pool = make_sub_pool(permanent_pool); pr_pool_tag(dso_pool, MOD_DSO_VERSION); lt_dlpreload_default(lt_preloaded_symbols); /* Initialize libltdl. */ if (lt_dlinit() < 0) { pr_log_pri(PR_LOG_ERR, MOD_DSO_VERSION ": error initializing libltdl: %s", lt_dlerror()); return -1; } /* Explicitly set the search path used for opening modules. */ if (lt_dlsetsearchpath(dso_module_path) < 0) { pr_log_pri(PR_LOG_ERR, MOD_DSO_VERSION ": error setting module path: %s", lt_dlerror()); return -1; } #ifdef PR_USE_CTRLS /* Register ctrls handlers. */ for (i = 0; dso_acttab[i].act_action; i++) { pool *sub_pool = make_sub_pool(dso_pool); /* Allocate and initialize the ACL for this control. */ dso_acttab[i].act_acl = pcalloc(sub_pool, sizeof(ctrls_acl_t)); dso_acttab[i].act_acl->acl_pool = sub_pool; pr_ctrls_init_acl(dso_acttab[i].act_acl); if (pr_ctrls_register(&dso_module, dso_acttab[i].act_action, dso_acttab[i].act_desc, dso_acttab[i].act_cb) < 0) pr_log_pri(PR_LOG_INFO, MOD_DSO_VERSION ": error registering '%s' control: %s", dso_acttab[i].act_action, strerror(errno)); } #endif /* PR_USE_CTRLS */ /* Ideally, we'd call register a listener for the 'core.exit' event * and call lt_dlexit() there, politely freeing up any resources allocated * by the ltdl library. However, it's possible that other modules, later in * the dispatch cycles, may need to use pointers to memory in shared modules * that would become invalid by such finalization. So we skip it, for now. * * If there was a way to schedule this handler, to happen after all other * exit handlers, that'd be best. */ pr_event_register(&dso_module, "core.restart", dso_restart_ev, NULL); return 0; }
static void dso_restart_ev(const void *event_data, void *user_data) { module *m, *mi; #ifdef PR_USE_CTRLS register unsigned int i = 0; #endif /* PR_USE_CTRLS */ if (dso_pool) destroy_pool(dso_pool); dso_pool = make_sub_pool(permanent_pool); pr_pool_tag(dso_pool, MOD_DSO_VERSION); #ifdef PR_USE_CTRLS /* Re-register the control handlers */ for (i = 0; dso_acttab[i].act_action; i++) { pool *sub_pool = make_sub_pool(dso_pool); /* Allocate and initialize the ACL for this control. */ dso_acttab[i].act_acl = pcalloc(sub_pool, sizeof(ctrls_acl_t)); dso_acttab[i].act_acl->acl_pool = sub_pool; pr_ctrls_init_acl(dso_acttab[i].act_acl); } #endif /* PR_USE_CTRLS */ /* Unload all shared modules. */ for (mi = loaded_modules; mi; mi = m) { #ifndef PR_USE_CTRLS register unsigned int i; #endif /* PR_USE_CTRLS */ int is_static = FALSE; m = mi->next; for (i = 0; static_modules[i]; i++) { if (strcmp(mi->name, static_modules[i]->name) == 0) { is_static = TRUE; break; } } if (!is_static) { pr_log_debug(DEBUG7, "unloading 'mod_%s.c'", mi->name); if (dso_unload_module(mi) < 0) pr_log_pri(PR_LOG_INFO, "error unloading 'mod_%s.c': %s", mi->name, strerror(errno)); } } return; }