start of new reload setup

This commit is contained in:
2025-03-24 00:32:11 +02:00
parent 317e1acd07
commit fe095913f1
3 changed files with 10 additions and 5 deletions

View File

@@ -25,8 +25,8 @@ void hi_deinit();
/* Print a random assortment of information from current state */ /* Print a random assortment of information from current state */
void hi_print_module_infos(); void hi_print_module_infos();
/* Reload module identified by the name */ /* Reload shared library if it has changed since last reload or init was called */
ReloadResult hi_reload_module(const char *module_name); ReloadResult hi_reload_solib(const char *module_name);
#pragma GCC visibility pop #pragma GCC visibility pop

View File

@@ -7,6 +7,7 @@
#include <assert.h> #include <assert.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <libelf.h>
#include <link.h> #include <link.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -114,7 +115,7 @@ ModuleInfos *gather_module_infos(void) {
} }
static static
ReloadResult reload_module(ModuleInfos *modules, const char *filename, ReloadResult reload_solib(ModuleInfos *modules, const char *filename,
void **updated_handle) { void **updated_handle) {
if (!modules || !filename) { if (!modules || !filename) {
return HI_RELOAD_NOT_FOUND; return HI_RELOAD_NOT_FOUND;
@@ -181,11 +182,11 @@ ReloadResult reload_module(ModuleInfos *modules, const char *filename,
return HI_RELOAD_SUCCESS; return HI_RELOAD_SUCCESS;
} }
ReloadResult hi_reload_module(const char *module_name) { ReloadResult hi_reload_solib(const char *module_name) {
assert(module_infos); assert(module_infos);
void *new_handle = NULL; void *new_handle = NULL;
ReloadResult result = reload_module(module_infos, module_name, &new_handle); ReloadResult result = reload_solib(module_infos, module_name, &new_handle);
return result; return result;
} }

View File

@@ -27,6 +27,10 @@ int main(int argc, char *argv[]) {
printf("otherValue: %d\n", minimal_lib::otherValue++); printf("otherValue: %d\n", minimal_lib::otherValue++);
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(1));
printf("\n"); printf("\n");
if (hi_reload_solib("libmini.so") != HI_RELOAD_SUCCESS) {
fprintf(stderr, "Failed to load solib\n");
}
} }
hi_deinit(); hi_deinit();