From da226b3cfa80d97fbaf8d8a8c7dc5286b6779baf Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Fri, 20 Aug 2021 15:19:08 +0200 Subject: [PATCH] Server /etc parameters embryon, clean shutdown (&signals), model storage dir --- Makefile | 12 ++++++++++-- debian/Manifest | 10 ---------- include/base.h | 11 +++++++++++ include/model.h | 2 +- src/cmds.c | 6 +++--- src/localworker.c | 1 + src/main.c | 47 +++++++++++++++++++++++++++++++++++++--------- src/model.c | 5 +++-- src/tests/xml | Bin 17080 -> 17128 bytes src/tests/xml.c | 6 +++--- 10 files changed, 70 insertions(+), 30 deletions(-) delete mode 100644 debian/Manifest diff --git a/Makefile b/Makefile index b0f0f92..6d48a60 100644 --- a/Makefile +++ b/Makefile @@ -87,11 +87,19 @@ all: dependencies $(BINDIR)/gem-graph-server $(BINDIR)/gem-graph-ctl tests: $(TESTS) # ---- Build debian package -------------------------------------------------- # -$(BINDIR)/gem-graph-server.deb: all +$(BINDIR)/gem-graph-server.deb: all $(DEBDIR)/control \ + $(DEBDIR)/conffiles \ + $(DEBDIR)/etc/server.conf \ + $(DEBDIR)/copyright mkdir -p gem-graph-server/usr/bin + mkdir -p gem-graph-server/var/lib/gem-graph-server/models + mkdir -p gem-graph-server/var/lib/gem-graph-server/users + mkdir -p gem-graph-server/etc/gem-graph-server mkdir -p gem-graph-server/usr/share/doc/gem-graph-server mkdir -p gem-graph-server/DEBIAN - cp $(DEBDIR)/Manifest gem-graph-server/DEBIAN/control + cp $(DEBDIR)/control gem-graph-server/DEBIAN/control + cp $(DEBDIR)/conffiles gem-graph-server/DEBIAN/conffiles + cp $(DEBDIR)/etc/* gem-graph-server/etc/gem-graph-server cp $(BINDIR)/gem-graph-server gem-graph-server/usr/bin cp $(BINDIR)/gem-graph-ctl gem-graph-server/usr/bin cp $(DEBDIR)/copyright \ diff --git a/debian/Manifest b/debian/Manifest deleted file mode 100644 index d7fcae4..0000000 --- a/debian/Manifest +++ /dev/null @@ -1,10 +0,0 @@ -Package: gem-graph-server -Version: 0.0.1 -Section: custom -Priority: optional -Depends: libxml2 -Architecture: amd64 -Essential: no -Installed-Size: 1049 -Maintainer: The Gem-graph Project -Description: The gem-graph computation server diff --git a/include/base.h b/include/base.h index 97ea250..417687f 100644 --- a/include/base.h +++ b/include/base.h @@ -168,3 +168,14 @@ struct { Scheduler_t *scheduler; Supervisor_t *supervisor; } typedef Model_t; + +/* -------------------------------------------------------------------------- */ + +// +// Parameters +// +struct { + char *configDir; + char *modelDir; + char *userDir; +} typedef Parameters_t; diff --git a/include/model.h b/include/model.h index 49a3c02..a42fd6f 100644 --- a/include/model.h +++ b/include/model.h @@ -23,7 +23,7 @@ #include "../include/base.h" #endif -void ModelSystemInit(void); +void ModelSystemInit(Parameters_t *parameters); void ModelSystemDestroy(void); diff --git a/src/cmds.c b/src/cmds.c index b2d82cd..bb76061 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -179,12 +179,12 @@ CmdModelEnd: char *CmdShutdown(char *buf, char **argv, Server_t *args) { - ModelShutdown(); - strcat(buf, "All model shutted down\n"); - args->pleaseStop = true; strcat(buf, "Server stopping\n"); + ModelShutdown(); + strcat(buf, "All model shutted down\n"); + return buf; } diff --git a/src/localworker.c b/src/localworker.c index 1931a2d..958bba6 100644 --- a/src/localworker.c +++ b/src/localworker.c @@ -48,6 +48,7 @@ static void *workerMain(void *worker) printLog("Worker #%lu online\n", args->id); int size = args->globalDrawingSpace->size; + /* In each cell: the West (left) site is 0, the East (right) site is 1 */ for (int orig=0; orig < size; orig++){ int nxt1 = (orig + 1) % size, diff --git a/src/main.c b/src/main.c index 3762f50..e1972a2 100644 --- a/src/main.c +++ b/src/main.c @@ -23,37 +23,66 @@ #include "../include/server.h" #include "../include/model.h" +static Server_t *server; +void SigIntTermHandler(int signum) +{ + server->pleaseStop = true; + printLog("Server stopping\n"); + + ModelShutdown(); + printLog("All model shutted down\n"); +} + + +// TODO parse args to discover : +// - config files directory +// - models & users directories int main(int argc, char **argv) { time_t t; - Server_t *server0; int returnValue = 0; + // Get parameters TODO from args + Parameters_t *parameters = (Parameters_t*) calloc(sizeof(Parameters_t), 1); + + parameters->configDir = (char*) malloc(strlen("../debian/etc")); + strcpy(parameters->configDir, "../debian/etc"); + + parameters->modelDir = (char*) malloc(strlen("../debian/var/models")); + strcpy(parameters->modelDir, "../debian/etc"); + + parameters->userDir = (char*) malloc(strlen("../debian/var/users")); + strcpy(parameters->userDir, "../debian/etc"); + // Go! printLog("Starting gem-graph-server...\n"); + // Register new interrupt handler + signal(SIGINT, SigIntTermHandler); + signal(SIGTERM, SigIntTermHandler); + // Initializing random generator t = time(&t); srand((unsigned) t); - server0 = (Server_t*) calloc(1, sizeof(Server_t)); + server = (Server_t*) calloc(1, sizeof(Server_t)); // Initializing model system - ModelSystemInit(); + ModelSystemInit(parameters); // Launching server - ServerInit(server0); + ServerInit(server); // Waiting for termination - ServerWait(server0); + ServerWait(server); // Exiting - returnValue |= server0->returnValue; - ServerDestroy(server0); + returnValue |= server->returnValue; + ServerDestroy(server); ModelSystemDestroy(); - free(server0); - server0 = NULL; + free(server); + server = NULL; return returnValue; } diff --git a/src/model.c b/src/model.c index 2685dc5..8f093d5 100644 --- a/src/model.c +++ b/src/model.c @@ -182,15 +182,16 @@ void ModelShutdown(void) } } -void ModelSystemInit(void) +void ModelSystemInit(Parameters_t *parameters) { loadedModel = (Model_t**) calloc(1, sizeof(Model_t*)); - // XXX read known models from files knownModel = (Model_t**) calloc(1, sizeof(Model_t*)); knownModelSize = 0; loadedModelSize = 0; + + printLog("Model system initiated with folder : %s\n", parameters->modelDir); } void ModelSystemDestroy(void) diff --git a/src/tests/xml b/src/tests/xml index 04cd32f658a22bee170d4b3b5382a48e984f900b..b0826726346e8356badc37d0491a90faf21a9e8a 100755 GIT binary patch delta 2161 zcmZ8ieQZ-z6u-A!w?6mPw{E;WS!gRIII(?e$5w}QZ3lC2VVW&C96_WrvQ+Vd$r?0h z*uthRbD`rXjD!$inFgZ7*?$%=GGii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?Gup=s zrgjC;b`>r+O0*UV={aDY4N7SpVVVl&VUsi+L=qIMXL281HF7NHQ0%wHGd+8hC) zd5<-t`Qt+gHcK$sED8tt86Jc}a|Dhy+rb(O2u_}b6B4l`-hymQ7N)$q?-Ueb5uwbb za-PPMY~`thEEt>I1_OzRU{wB2C?sO+AX{R>a6k`Igj5SM*qy+37P2i7+{i-9s{a5J CarT@5 diff --git a/src/tests/xml.c b/src/tests/xml.c index bcba914..6c5eb80 100644 --- a/src/tests/xml.c +++ b/src/tests/xml.c @@ -8,8 +8,8 @@ void parseStory (xmlDocPtr doc, xmlNodePtr cur) { cur = cur->xmlChildrenNode; while (cur != NULL) { - if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyword"))) { - printf("keyword: %s\n", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); + if ((!xmlStrcmp(cur->name, (const xmlChar *)"authors"))) { + printf("%s\n", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); } cur = cur->next; } @@ -41,7 +41,7 @@ static void parseDoc(char *docname) cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *)"storyinfo"))){ - parseStory (doc, cur); + parseStory(doc, cur); } cur = cur->next; }