From 124d1180bdc50dbb7f1e2ca46e2325641240d430 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Fri, 9 Apr 2021 01:50:55 +0000 Subject: [PATCH] chore: Cleanup dl error handling --- runtime/src/main.c | 2 +- runtime/src/module.c | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/runtime/src/main.c b/runtime/src/main.c index 34d9500..7411dd6 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -363,7 +363,7 @@ main(int argc, char **argv) #ifdef LOG_MODULE_LOADING debuglog("Parsing modules file [%s]\n", argv[1]); #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(); listener_thread_initialize(); diff --git a/runtime/src/module.c b/runtime/src/module.c index 9a9a49d..8f0a5ea 100644 --- a/runtime/src/module.c +++ b/runtime/src/module.c @@ -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 */ module->dynamic_library_handle = dlopen(path, RTLD_LAZY | RTLD_DEEPBIND); 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; }; /* Resolve the symbols in the dynamic library *.so file */ module->main = (mod_main_fn_t)dlsym(module->dynamic_library_handle, MODULE_MAIN); 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; } module->initialize_globals = (mod_glb_fn_t)dlsym(module->dynamic_library_handle, MODULE_INITIALIZE_GLOBALS); 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; } module->initialize_memory = (mod_mem_fn_t)dlsym(module->dynamic_library_handle, MODULE_INITIALIZE_MEMORY); 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; }; module->initialize_tables = (mod_tbl_fn_t)dlsym(module->dynamic_library_handle, MODULE_INITIALIZE_TABLE); 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; }; module->initialize_libc = (mod_libc_fn_t)dlsym(module->dynamic_library_handle, MODULE_INITIALIZE_LIBC); 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; }