]> Nishi Git Mirror - mandshurica.git/commitdiff
use pid_t
authornishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 13 Apr 2024 07:17:23 +0000 (07:17 +0000)
committernishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 13 Apr 2024 07:17:23 +0000 (07:17 +0000)
git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@16 f982e544-4a7d-3444-ad1a-fde59a2a69f1

DevForge/config.c
DevForge/df_config.h
DevForge/log.c
DevForge/main.c

index bfd3827f696af18cfd7e4a7ce03fd39c592b8240..5db210c7948c000324e8b018b4fa77217fb29b7c 100644 (file)
@@ -43,7 +43,7 @@
 #include <string.h>
 
 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);
 }
index c48ef9f1b22c2d0062b27c3d7c33eacbb31c31aa..43b22635fa7991f309f107579b68a061481d8ad0 100644 (file)
 #define __DEVFORGE_DF_CONFIG_H__
 
 #include <stddef.h>
+#include <sys/types.h>
 
 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
index 62a739ee218019ca6afd975d4f610466317f08d3..e62b1204e7219efc09e6b9102281ec4fc1612480 100644 (file)
@@ -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);
index c4cb6f564d22efdae18284369e2e7957154773b3..34b9852437e3c52c3c11737babf8ef95af3ab61d 100644 (file)
@@ -36,6 +36,7 @@
 #include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
+#include <dlfcn.h>
 
 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!");
 }