From e9580fb8d4f54d8eb584dd7228491a8738314391 Mon Sep 17 00:00:00 2001 From: nishi Date: Sat, 13 Apr 2024 07:17:23 +0000 Subject: [PATCH] use pid_t git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@16 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- DevForge/config.c | 5 +++-- DevForge/df_config.h | 8 +++++++- DevForge/log.c | 4 ++-- DevForge/main.c | 16 ++++++++++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/DevForge/config.c b/DevForge/config.c index bfd3827..5db210c 100644 --- a/DevForge/config.c +++ b/DevForge/config.c @@ -43,7 +43,7 @@ #include void devforge_add_mod(void* lib) { - void** old_mods = loaded_mods; + struct devforge_mod** old_mods = loaded_mods; int i; for(i = 0; old_mods[i] != NULL; i++) ; @@ -51,7 +51,8 @@ void devforge_add_mod(void* lib) { for(i = 0; old_mods[i] != NULL; i++) { loaded_mods[i] = old_mods[i]; } - loaded_mods[i] = lib; + loaded_mods[i] = malloc(sizeof(**loaded_mods)); + loaded_mods[i]->lib = lib; loaded_mods[i + 1] = NULL; free(old_mods); } diff --git a/DevForge/df_config.h b/DevForge/df_config.h index c48ef9f..43b2263 100644 --- a/DevForge/df_config.h +++ b/DevForge/df_config.h @@ -32,10 +32,16 @@ #define __DEVFORGE_DF_CONFIG_H__ #include +#include int devforge_load_config(const char* path); int devforge_create_config(const char* path); +struct devforge_mod { + void* lib; + pid_t pid; +}; + #ifdef DF_CONFIG_SRC #define DF_CONFIG_PREFIX #else @@ -48,7 +54,7 @@ DF_CONFIG_PREFIX char* server_root #endif ; -DF_CONFIG_PREFIX void** loaded_mods +DF_CONFIG_PREFIX struct devforge_mod** loaded_mods #ifdef DF_CONFIG_SRC = NULL #endif diff --git a/DevForge/log.c b/DevForge/log.c index 62a739e..e62b120 100644 --- a/DevForge/log.c +++ b/DevForge/log.c @@ -44,9 +44,9 @@ void devforge_log(const char* name, const char* log) { if(loaded_mods != NULL) { int i; for(i = 0; loaded_mods[i] != NULL; i++) { - const char* type = (const char*)dlsym(loaded_mods[i], "mod_type"); + const char* type = (const char*)dlsym(loaded_mods[i]->lib, "mod_type"); if(strcmp(type, DF_MOD_LOG) == 0) { - void (*mod_log)(const char*, const char*) = (void (*)(const char*, const char*))dlsym(loaded_mods[i], "mod_log"); + void (*mod_log)(const char*, const char*) = (void (*)(const char*, const char*))dlsym(loaded_mods[i]->lib, "mod_log"); if(mod_log != NULL) { fallback = false; mod_log(name, log); diff --git a/DevForge/main.c b/DevForge/main.c index c4cb6f5..34b9852 100644 --- a/DevForge/main.c +++ b/DevForge/main.c @@ -36,6 +36,7 @@ #include #include #include +#include int main(int argc, char** argv) { int i; @@ -72,4 +73,19 @@ int main(int argc, char** argv) { if(ret != 0) return ret; } devforge_log(DF_INFO, "Hello World, initialization done"); + if(loaded_mods != NULL){ + devforge_log(DF_INFO, "Starting server"); + int i; + bool loaded_srv = false; + for(i = 0; loaded_mods[i] != NULL; i++){ + const char* type = (const char*)dlsym(loaded_mods[i]->lib, "mod_type"); + if(type != NULL){ + if(strcmp(type, DF_MOD_SRV) == 0){ + loaded_srv = true; + } + } + } + if(loaded_srv) return 0; + } + devforge_log(DF_ERROR, "Server module was not loaded!"); } -- 2.43.0