From 13cc094cba39d40d82573f0f16a8cc8719ddabc6 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Tue, 21 May 2019 09:27:17 -0500 Subject: [PATCH] Flesh out hexagram_module more --- include/hexagram/module.h | 6 +++++- src/module.c | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/include/hexagram/module.h b/include/hexagram/module.h index a1bcd0f..0985e87 100644 --- a/include/hexagram/module.h +++ b/include/hexagram/module.h @@ -1,6 +1,9 @@ #ifndef _HEXAGRAM_MODULE_H #define _HEXAGRAM_MODULE_H +#include + +#include #include typedef struct _hexagram_module hexagram_module; @@ -11,7 +14,8 @@ int hexagram_module_close(hexagram_module *module); const char *hexagram_module_name(hexagram_module *module); -int hexagram_module_run(hexagram_module *module, hexagram_can_if *can_if); +int hexagram_module_run(hexagram_module *module, + hexagram_dict *buses); int hexagram_module_stop(hexagram_module *module); diff --git a/src/module.c b/src/module.c index 0489b45..439a10c 100644 --- a/src/module.c +++ b/src/module.c @@ -1,8 +1,8 @@ #include #include -#include +#include #include -#include +#include #include #include @@ -11,8 +11,8 @@ struct _hexagram_module { const char *soname; void *handle; char *(*name)(); - int (*run)(hexagram_can_if *can_if); - int pid; + int (*run)(hexagram_dict *buses); + pid_t pid; }; hexagram_module *hexagram_module_open(const char *soname) { @@ -50,10 +50,19 @@ error_malloc: } const char *hexagram_module_name(hexagram_module *module) { + if (module->name == NULL) { + return NULL; + } + return module->name(); } -int hexagram_module_run(hexagram_module *module, hexagram_can_if *can_if) { +int hexagram_module_run(hexagram_module *module, + hexagram_dict *buses) { + if (module->run == NULL) { + return -1; + } + /* * Module already stopped */ @@ -61,7 +70,18 @@ int hexagram_module_run(hexagram_module *module, hexagram_can_if *can_if) { return -1; } - return module->run(can_if); + if ((module->pid = fork()) < 0) { + goto error_fork; + } + + if (module->pid == 0) { + exit(module->run(buses)); + } + + return 0; + +error_fork: + return -1; } int hexagram_module_stop(hexagram_module *module) { @@ -102,11 +122,15 @@ int hexagram_module_close(hexagram_module *module) { memset(module, '\0', sizeof(*module)); + free(module); + return 0; error_dlclose: memset(module, '\0', sizeof(*module)); + free(module); + error_stop_module: return -1; }