From 4ad8861572e1764fa79b2cd39aa9d693de52dffa Mon Sep 17 00:00:00 2001 From: Kasper Sauramo Date: Fri, 9 May 2025 23:39:00 +0300 Subject: [PATCH] be slightly stricter on when to load a module --- CMakeLists.txt | 12 ++++++++++++ src/hiload.c | 15 +++++++++------ src/moduler.c | 3 +-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a75ff55..df223a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,9 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED) +set(BUILD_AUDITOR OFF) +set(BUILD_TESTS OFF) + # Conditionally define _GNU_SOURCE for Linux systems if(UNIX AND NOT APPLE) # This checks for Linux (UNIX but not macOS) @@ -71,12 +74,15 @@ install(EXPORT hiloadTargets export(TARGETS hiload FILE hiloadConfig.cmake) + +if (BUILD_AUDITOR) # Auditor libraries # ############### # TODO: Move auditor to its own project, possibly even out of this repo. # It has only been a side product + add_library(auditor-x86_64 SHARED solib-auditors/auditor-x86_64.c ) @@ -95,7 +101,13 @@ install(TARGETS auditor-x86_64 RUNTIME DESTINATION bin ) +endif() + # tests and test projects # ####################### +if (BUILD_TESTS) + add_subdirectory(test) + +endif() diff --git a/src/hiload.c b/src/hiload.c index 752bb2e..4d4af12 100644 --- a/src/hiload.c +++ b/src/hiload.c @@ -1,6 +1,7 @@ #include "hiload.h" #include "common.h" +#include "filewatcher/filewatch_type.h" #include "filewatcher/filewatcher.h" #include "histring.h" #include "logger.h" @@ -178,11 +179,13 @@ static void handle_file_events(FileWatcher *fw, VectorModuleData *modules) { log_debug("Event pop: %s – %s\n", event.pathname, filewatch_type_to_str(event.type)); - ModuleData *module = module_get(event.pathname, modules); - if (!module) { - log_warn("Watched module: %s not found.\n", event.pathname); - } else { - module->info = modinfo_add(module->info, HI_MODULE_STATE_DIRTY); + if (event.type == HI_FILE_CHANGE || event.type == HI_FILE_CREATE) { + ModuleData *module = module_get(event.pathname, modules); + if (!module) { + log_warn("Watched module: %s not found.\n", event.pathname); + } else { + module->info = modinfo_add(module->info, HI_MODULE_STATE_DIRTY); + } } event = filewatcher_event_pop(context.filewatcher); } @@ -215,7 +218,7 @@ int hi_init(size_t n, const char **enabled_modules) { fprintf(stderr, "Failed to init logger.\n"); return 1; } - log_set_level("WARNING"); + log_set_level("DEBUG"); log_set_thread_name("Hiload"); // Start the filewatcher diff --git a/src/moduler.c b/src/moduler.c index 3275973..5a956b9 100644 --- a/src/moduler.c +++ b/src/moduler.c @@ -338,8 +338,7 @@ HiResult moduler_reload(VectorModuleData *modules, size_t modindx) { log_debug("Opening patch: %s\n", patch.filename); void *new_handle = dlopen(patch.filename, RTLD_LAZY); if (!new_handle) { - log_error("Couldn't load: %s\n", dlerror()); - module->info = modinfo_clear(module->info, HI_MODULE_STATE_DIRTY); + log_errorv("Couldn't load: %s\n", dlerror()); return HI_FAIL; } patch.dlhandle = new_handle;