chore: Cleanup dl error handling

main
Sean McBride 4 years ago
parent da60ec8c8b
commit 124d1180bd

@ -363,7 +363,7 @@ main(int argc, char **argv)
#ifdef LOG_MODULE_LOADING #ifdef LOG_MODULE_LOADING
debuglog("Parsing modules file [%s]\n", argv[1]); debuglog("Parsing modules file [%s]\n", argv[1]);
#endif #endif
if (module_new_from_json(argv[1])) panic("failed to parse modules file[%s]\n", argv[1]); if (module_new_from_json(argv[1])) panic("failed to initialize module(s) defined in %s\n", argv[1]);
runtime_start_runtime_worker_threads(); runtime_start_runtime_worker_threads();
listener_thread_initialize(); listener_thread_initialize();

@ -150,38 +150,42 @@ module_new(char *name, char *path, int32_t argument_count, uint32_t stack_size,
/* Load the dynamic library *.so file with lazy function call binding and deep binding */ /* Load the dynamic library *.so file with lazy function call binding and deep binding */
module->dynamic_library_handle = dlopen(path, RTLD_LAZY | RTLD_DEEPBIND); module->dynamic_library_handle = dlopen(path, RTLD_LAZY | RTLD_DEEPBIND);
if (module->dynamic_library_handle == NULL) { if (module->dynamic_library_handle == NULL) {
fprintf(stderr, "Failed to open dynamic library at %s: %s\n", path, dlerror()); fprintf(stderr, "Failed to open %s with error: %s\n", path, dlerror());
goto dl_open_error; goto dl_open_error;
}; };
/* Resolve the symbols in the dynamic library *.so file */ /* Resolve the symbols in the dynamic library *.so file */
module->main = (mod_main_fn_t)dlsym(module->dynamic_library_handle, MODULE_MAIN); module->main = (mod_main_fn_t)dlsym(module->dynamic_library_handle, MODULE_MAIN);
if (module->main == NULL) { if (module->main == NULL) {
fprintf(stderr, "Failed to resolve symbol %s: %s\n", MODULE_MAIN, dlerror()); fprintf(stderr, "Failed to resolve symbol %s in %s with error: %s\n", MODULE_MAIN, path, dlerror());
goto dl_error; goto dl_error;
} }
module->initialize_globals = (mod_glb_fn_t)dlsym(module->dynamic_library_handle, MODULE_INITIALIZE_GLOBALS); module->initialize_globals = (mod_glb_fn_t)dlsym(module->dynamic_library_handle, MODULE_INITIALIZE_GLOBALS);
if (module->initialize_globals == NULL) { if (module->initialize_globals == NULL) {
fprintf(stderr, "Failed to resolve symbol %s: %s\n", MODULE_INITIALIZE_GLOBALS, dlerror()); fprintf(stderr, "Failed to resolve symbol %s in %s with error: %s\n", MODULE_INITIALIZE_GLOBALS, path,
dlerror());
goto dl_error; goto dl_error;
} }
module->initialize_memory = (mod_mem_fn_t)dlsym(module->dynamic_library_handle, MODULE_INITIALIZE_MEMORY); module->initialize_memory = (mod_mem_fn_t)dlsym(module->dynamic_library_handle, MODULE_INITIALIZE_MEMORY);
if (module->initialize_memory == NULL) { if (module->initialize_memory == NULL) {
fprintf(stderr, "Failed to resolve symbol %s: %s\n", MODULE_INITIALIZE_MEMORY, dlerror()); fprintf(stderr, "Failed to resolve symbol %s in %s with error: %s\n", MODULE_INITIALIZE_MEMORY, path,
dlerror());
goto dl_error; goto dl_error;
}; };
module->initialize_tables = (mod_tbl_fn_t)dlsym(module->dynamic_library_handle, MODULE_INITIALIZE_TABLE); module->initialize_tables = (mod_tbl_fn_t)dlsym(module->dynamic_library_handle, MODULE_INITIALIZE_TABLE);
if (module->initialize_tables == NULL) { if (module->initialize_tables == NULL) {
fprintf(stderr, "Failed to resolve symbol %s: %s\n", MODULE_INITIALIZE_TABLE, dlerror()); fprintf(stderr, "Failed to resolve symbol %s in %s with error: %s\n", MODULE_INITIALIZE_TABLE, path,
dlerror());
goto dl_error; goto dl_error;
}; };
module->initialize_libc = (mod_libc_fn_t)dlsym(module->dynamic_library_handle, MODULE_INITIALIZE_LIBC); module->initialize_libc = (mod_libc_fn_t)dlsym(module->dynamic_library_handle, MODULE_INITIALIZE_LIBC);
if (module->initialize_libc == NULL) { if (module->initialize_libc == NULL) {
fprintf(stderr, "Failed to resolve symbol %s: %s\n", MODULE_INITIALIZE_LIBC, dlerror()); fprintf(stderr, "Failed to resolve symbol %s in %s with error: %s\n", MODULE_INITIALIZE_LIBC, path,
dlerror());
goto dl_error; goto dl_error;
} }

Loading…
Cancel
Save