From ebcfc1f4b3bbf898a4d0043573dec81d9c52d46d Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Sat, 13 Jul 2024 03:15:08 -0400 Subject: [PATCH] able to start process on the ip:port binding --- lib/modrec.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++- lib/unisoc.c | 2 + lib/unisoc.h | 3 +- 3 files changed, 128 insertions(+), 3 deletions(-) diff --git a/lib/modrec.c b/lib/modrec.c index e0bd281..1a3b3ad 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -6,6 +6,7 @@ /********************************************************/ #include #include +#include #include #include @@ -21,6 +22,126 @@ static _Bool modopen; //boolean module open/close */ /********************************************************/ /* */ +/* kleenex procedure */ +/* */ +/********************************************************/ +static void kludge(SOCTYP *binding,int attend) + +{ +for (int i=0;i", + attend-i,binding->ip,binding->port); + (void) sleep(1); + } +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to dispatch sub process */ +/* */ +/********************************************************/ +static void dispatching(SOCTYP *binding) + +{ +#define OPEP "modrec.c:dispatching" + +int phase; +_Bool proceed; + +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //dispatched process still alive + (void) prc_nozombie(); + for (int i=0;iiteration;i++) { + if (binding->childs[i]==(pid_t)0) + continue; + if (prc_checkprocess(binding->childs[i])==false) { + (void) rou_alert(3,"%s, Process '%05d' exited",OPEP,binding->childs[i]); + binding->childs[i]=(pid_t)0; + } + } + break; + case 1 : //dispating need process + for (int i=0;iiteration;i++) { + int attend; + + attend=(random()%60)+10; + if (binding->childs[i]!=(pid_t)0) + continue; + switch(binding->childs[i]=fork()) { + case -1 : + (void) rou_alert(0,"%s, Unable to start process to " + "handle <%s:%s> socket (config?)", + OPEP,binding->ip,binding->port); + break; + case 0 : //the dispatched process + (void) kludge(binding,attend); + (void) sleep(1); //avoiding avalanche + (void) exit(0); + break; + default : + (void) usleep(10000); //wait for next fork + break; + } + } + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +#undef OPEP +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to active child process if necessary */ +/* */ +/********************************************************/ +static void activate(SOCTYP **bindings) + +{ +#define OPEP "modrec.c:activate" + +int phase; +_Bool proceed; + +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //making sur the list is defined + if (bindings==(SOCTYP **)0) { + (void) rou_alert(0,"%s bindings list pointer is NULL (Bug!?)",OPEP); + phase=999; //not going further + } + break; + case 1 : //check need to dispatch a process + while (*bindings!=(SOCTYP *)0) { + (void) dispatching(*bindings); + bindings++; + } + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +#undef OPEP +} +/* + +*/ +/********************************************************/ +/* */ /* Waiting and handling smtp request */ /* */ /********************************************************/ @@ -48,9 +169,10 @@ while (proceed==true) { (void) rou_alert(0,"%s, Unable to open ALL socket (config?)",OPEP); break; case 2 : //Terminating all remaining process - (void) fprintf(stderr,"JMPDBG wait 5 sec\n"); + (void) activate(bindings); (void) sleep(5); - (void) fprintf(stderr,"JMPDBG wleep completed\n"); + if ((hangup==false)&&(reload==false)) + phase--; //normal cycle, lets proceed to actvate again break; case 3 : //closing all socket openend (void) soc_mulclose(bindings); diff --git a/lib/unisoc.c b/lib/unisoc.c index f9c5efb..c9affa2 100644 --- a/lib/unisoc.c +++ b/lib/unisoc.c @@ -44,6 +44,7 @@ static SOCTYP *freebinding(SOCTYP *binding) if (binding!=(SOCTYP *)0) { binding->port=rou_freestr(binding->port); binding->ip=rou_freestr(binding->ip); + (void) free(binding->childs); (void) free(binding); binding=(SOCTYP *)0; } @@ -200,6 +201,7 @@ bininf->proto=proto; bininf->ip=strdup(ip); bininf->port=strdup(port); bininf->iteration=iteration; +bininf->childs=(pid_t *)calloc(iteration,sizeof(pid_t)); bindings=(SOCTYP **)rou_addlist((void **)bindings,(void *)bininf); return bindings; } diff --git a/lib/unisoc.h b/lib/unisoc.h index 975948b..bb42135 100644 --- a/lib/unisoc.h +++ b/lib/unisoc.h @@ -24,8 +24,9 @@ typedef struct { char *ip; //Binding IP //IPV4 or IPV6 char *port; //Binding Port time_t lasttry; //successful binding last time - int iteration; //number of handle ready on the soc + int iteration; //number of soc slot used on the IP int handle; //connexion handle + pid_t *childs; //all process connected to this handle }SOCTYP; //procedure to free all memory used by a TCP socket -- 2.47.3