void topo_close(topo_hdl_t *thp) { ttree_t *tp; topo_hdl_lock(thp); if (thp->th_platform != NULL) topo_hdl_strfree(thp, thp->th_platform); if (thp->th_isa != NULL) topo_hdl_strfree(thp, thp->th_isa); if (thp->th_machine != NULL) topo_hdl_strfree(thp, thp->th_machine); if (thp->th_product != NULL) topo_hdl_strfree(thp, thp->th_product); if (thp->th_rootdir != NULL) topo_hdl_strfree(thp, thp->th_rootdir); if (thp->th_ipmi != NULL) ipmi_close(thp->th_ipmi); if (thp->th_smbios != NULL) smbios_close(thp->th_smbios); if (thp->th_pcidb != NULL) pcidb_close(thp->th_pcidb); /* * Clean-up snapshot */ topo_snap_destroy(thp); /* * Clean-up trees */ while ((tp = topo_list_next(&thp->th_trees)) != NULL) { topo_list_delete(&thp->th_trees, tp); topo_tree_destroy(tp); } /* * Unload all plugins */ topo_modhash_unload_all(thp); if (thp->th_modhash != NULL) topo_modhash_destroy(thp); if (thp->th_alloc != NULL) topo_free(thp->th_alloc, sizeof (topo_alloc_t)); topo_hdl_unlock(thp); topo_free(thp, sizeof (topo_hdl_t)); }
/*----------------------------------------------------------------------------*/ static local_store_topo *topo_alloc (ghmm_dmodel * mo, int len) { #define CUR_PROC "sdtopo_alloc" local_store_topo *v = NULL; ARRAY_CALLOC (v, 1); ARRAY_CALLOC (v->queue, mo->N); v->topo_order_length = 0; v->head = 0; /* initialize static queue (array implementation) */ v->tail = 0; ARRAY_CALLOC (v->topo_order, mo->N); return (v); STOP: /* Label STOP from ARRAY_[CM]ALLOC */ topo_free (&v, mo->N, len); return (NULL); #undef CUR_PROC }
static int rtld_init(topo_mod_t *mod, topo_version_t version) { int err; topo_rtld_t *rp; void *dlp; if ((dlp = dlopen(mod->tm_path, RTLD_LOCAL | RTLD_NOW)) == NULL) { topo_dprintf(mod->tm_hdl, TOPO_DBG_ERR, "dlopen() failed: %s\n", dlerror()); return (topo_mod_seterrno(mod, ETOPO_RTLD_OPEN)); } if ((rp = mod->tm_data = topo_mod_alloc(mod, sizeof (topo_rtld_t))) == NULL) return (topo_mod_seterrno(mod, ETOPO_RTLD_OPEN)); rp->rtld_dlp = dlp; rp->rtld_init = (int (*)())dlsym(dlp, "_topo_init"); rp->rtld_fini = (void (*)())dlsym(dlp, "_topo_fini"); if (rp->rtld_init == NULL) { (void) dlclose(dlp); topo_free(rp, sizeof (topo_rtld_t)); return (topo_mod_seterrno(mod, ETOPO_RTLD_INIT)); } /* * Call _topo_init() in the module. */ err = rp->rtld_init(mod, version); if (err < 0 || !(mod->tm_flags & TOPO_MOD_REG)) { (void) rtld_fini(mod); return (topo_mod_seterrno(mod, ETOPO_MOD_NOREG)); } return (0); }