/* **************************************************************** * Imprime uma tabela sobre a biblioteca * **************************************************************** */ int do_table (const char *argv[]) { const MOD *mp; const char *mod_nm; /* * Lê o arquivo de sinopse */ read_sinop_file (0); /* * Verifica se foram dados nomes de módulos */ if (*argv == NOSTR) { for (mp = mod_first; mp != NOMOD; mp = mp->m_next) list_mod (mp); } else /* Lista apenas os modulos dados */ { while ((mod_nm = *argv++) != NOSTR) { if ((mp = mod_search (mod_nm)) == NOMOD) error ("Não encontrei o módulo \"%s\"", mod_nm); else list_mod (mp); } } vflag = 0; /* Não escreve a mensagem sobre a sinopse */ return (0); /* Não escreve a sinopse */ } /* end do_table */
/* **************************************************************** * Cria o arquivo de sinopse * **************************************************************** */ int do_replace (const char *argv[]) { MOD *mp, *lp, *ap; const char *mod_nm, **cpp; char *mod_path, *nm_point; int len, max_len, r, modif = 0, sort = 0; STAT s; HEADER h; /* * Pequena consistência */ if (argv[0] == NOSTR) error ("$A substituição deve ter nomes de <módulo>s"); /* * Lê a sinopse e insere todos os símbolos na tabela HASH */ read_sinop_file (1); if ((hash_tb = calloc (HASHSZ, sizeof (SYMTB *))) == NULL) error (NOSTR); hash_all_sym (); /* * Prepara o prefixo dos nomes dos módulos */ for (cpp = argv, max_len = 0; *cpp != NOSTR; cpp++) { if (max_len < (len = strlen (*cpp))) max_len = len; } mod_path = alloca (lib_dir_nm_len + 1 + max_len); strcpy (mod_path, lib_dir_nm); strcat (mod_path, "/"); nm_point = strend (mod_path); /* * Processa cada um dos argumentos (módulos) */ while ((mod_nm = *argv++) != NOSTR) { strcpy (nm_point, mod_nm); if (mod_copy (last_nm (mod_nm), /* => */ mod_path, &s, &h) < 0) continue; /* * Verifica se o módulo já está na biblioteca */ if ((mp = mod_search (mod_nm)) == NOMOD) { /* O módulo ainda NÃO pertence à biblioteca */ if ((mp = malloc (sizeof (MOD))) == NOMOD) error (NOSTR); mp->m_mod_nm = mod_nm; mp->m_ino = s.st_ino; /*** mp->m_sym = ...; ***/ /*** mp->m_n_sym = ...; ***/ /*** mp->m_next = ...; ***/ /* Insere já no local correto da lista */ for (ap = NOMOD, lp = mod_first; lp != NOMOD; ap = lp, lp = lp->m_next) { if (strcmp (lp->m_mod_nm, mp->m_mod_nm) > 0) break; } if (ap == NOMOD) mod_first = mp; else ap->m_next = mp; mp->m_next = lp; if (mod_insert (mod_nm, mp, &s, &h) < 0) continue; modif++; sort++; } else { /* O módulo já pertence à biblioteca */ if ((r = mod_replace (mp, &s, &h, 'r')) > 0) modif += r; } } /* end for (nomes de módulos) */ free (hash_tb); if (sort) return (-modif); /* < 0 => Ordena */ else return (modif); } /* end do_replace */
module_t* mod_load(const char* path_name) { module_t* mod = mod_create(); int* api_version; int* type; int err = 0; boolean_t flag = B_FALSE; assert(mod != NULL); logmsg(LOG_INFO, "Loading module %s ...", path_name); err = plat_mod_open(&mod->mod_library, path_name); if(err != 0) { logmsg(LOG_WARN, "Failed loading, platform-specific error code: %d", err); logerror(); goto fail; } strcpy(mod->mod_path, path_name); /*Load module api version and name*/ MOD_LOAD_SYMBOL(api_version, mod, "mod_api_version", flag); MOD_LOAD_SYMBOL(type, mod, "mod_type", flag); MOD_LOAD_SYMBOL(mod->mod_name, mod, "mod_name", flag); if(flag) goto fail; if(*type != mod_type) { logmsg(LOG_INFO, "Ignoring module - wrong type %d", *type); goto fail; } if(*api_version != MOD_API_VERSION) { logmsg(LOG_WARN, "Wrong api version %d", *api_version); goto fail; } if(mod_search(mod->mod_name) != NULL) { logmsg(LOG_WARN, "Module %s already exists", mod->mod_name); goto fail; } MOD_LOAD_SYMBOL(mod->mod_config, mod, "mod_config", flag); MOD_LOAD_SYMBOL(mod->mod_unconfig, mod, "mod_unconfig", flag); /*Call helper*/ mod->mod_status = MOD_UNCONFIGURED; if(mod->mod_config(mod) != MOD_OK) { logmsg(LOG_INFO, "Failed to configure module %s (path: %s)", mod->mod_name, path_name); goto fail; } logmsg(LOG_INFO, "Loaded module %s (path: %s)", mod->mod_name, path_name); mod->mod_status = MOD_READY; mod_add(mod); return mod; fail: if(err != 0) plat_mod_close(&mod->mod_library); logmsg(LOG_WARN, "Failed to load module %s!", path_name); mod_destroy(mod); return NULL; }