From: Jean-Marc Pigeon (Delson) Date: Wed, 10 Jul 2024 05:04:42 +0000 (-0400) Subject: Adding module moderec, testing receiveing email sub process X-Git-Tag: tag-0.2~3 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=aa7eab56e970e0c2680a0b815efb39cc863215c5;p=jmp%2Fmailleur Adding module moderec, testing receiveing email sub process --- diff --git a/app/Makefile b/app/Makefile index 6d7ee49..4311de5 100644 --- a/app/Makefile +++ b/app/Makefile @@ -42,6 +42,8 @@ maild : toremake maild.o maild.o : maild.c \ + ../lib/modrec.h \ + ../lib/uniprc.h \ ../lib/unipar.h \ ../lib/subrou.h \ diff --git a/app/maild.c b/app/maild.c index bea11be..6067d1a 100644 --- a/app/maild.c +++ b/app/maild.c @@ -4,6 +4,7 @@ /* Main SMTP Daemon */ /* */ /********************************************************/ +#include #include #include #include @@ -11,7 +12,10 @@ #include "subrou.h" #include "unipar.h" #include "uniprc.h" +#include "modrec.h" +//port listening format is "IP:PORT NUMBER:num iteration" +#define PORTREC "192.168.0.1:25:2" /* */ @@ -20,13 +24,69 @@ /* Program main task */ /* */ /********************************************************/ -static void task() +static void task(u_int iteration) { -(void) rou_alert(0,"JMPDBG starting task"); -(void) prc_settitle("JMPDBG bingo!"); -(void) sleep(10); -(void) rou_alert(0,"JMPDBG task completed"); +pid_t *pidlst; +int phase; +_Bool proceed; + +pidlst=(pid_t *)calloc(iteration,sizeof(pid_t)); +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //looping forever email receiving processes + for (int i=0;i0) { + (void) sleep(2); + phase--; //let send signal again + } + } + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +(void) free(pidlst); } /* @@ -68,12 +128,14 @@ while (proceed==true) { (void) rou_modesubrou(true); (void) par_modeunipar(true); (void) prc_modeuniprc(true); + (void) rec_modemodrec(true); break; case 3 : //doing main tash - (void) task(); + (void) task(5); break; case 4 : //doing main tash (void) prc_cleantitle(); + (void) rec_modemodrec(false); (void) prc_modeuniprc(false); (void) par_modeunipar(false); (void) rou_modesubrou(false); diff --git a/lib/Makefile b/lib/Makefile index d0a2cec..b31bbf9 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -16,6 +16,7 @@ clean : #Equivalences #-------------------------------------------------------------------- OBJS= \ + modrec.o \ unipar.o uniprc.o \ subrou.o @@ -24,6 +25,9 @@ objs : $(OBJS) #-------------------------------------------------------------------- #Dependances +modrec.o: \ + subrou.h \ + modrec.h modrec.c uniprc.o: \ subrou.h \ diff --git a/lib/modrec.c b/lib/modrec.c new file mode 100644 index 0000000..bd06d68 --- /dev/null +++ b/lib/modrec.c @@ -0,0 +1,76 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/********************************************************/ +/* */ +/* Module to handle all email incoming */ +/* */ +/********************************************************/ +#include +#include +#include + +#include "subrou.h" +#include "uniprc.h" +#include "modrec.h" + +static _Bool modopen; //boolean module open/close + +/* + +*/ +/********************************************************/ +/* */ +/* */ +/********************************************************/ +//procedure to receive email form outside +void rec_getemail() + +{ +int attend; + +attend=(random()%7)+2; +(void) rou_alert(0,"JMPDBG getemail with pid='%06d' (wait for '%0d')", + getpid(),attend); +(void) prc_settitle("JMPDBG getemail with pid='%06d' (wait for '%0d')", + getpid(),attend); +(void) sleep(attend); +(void) rou_alert(0,"JMPDBG exiting from pid='%06d'",getpid()); +} +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to "open/close" module and do */ +/* homework purpose */ +/* return zero if everything right */ +/* */ +/********************************************************/ +int rec_modemodrec(_Bool mode) + +{ +#define OPEP "mode.c:rec_modemoderec" + +int status; + +status=0; +if (mode!=modopen) { + switch ((int)mode) { + case true : + (void) rou_modesubrou(mode); + (void) prc_modeuniprc(mode); + break; + case false : + (void) prc_modeuniprc(mode); + (void) rou_modesubrou(mode); + break; + default : + (void) fprintf(stderr,"Calling %s with wrong mode='%d' (Bug?!):", + OPEP,(int)mode); + status=-1; + break; + } + modopen=mode; + } +return status; +#undef OPEP +} diff --git a/lib/modrec.h b/lib/modrec.h new file mode 100644 index 0000000..f806343 --- /dev/null +++ b/lib/modrec.h @@ -0,0 +1,18 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/************************************************/ +/* */ +/* Module to handle all incoming email */ +/* */ +/************************************************/ +#ifndef MODREC +#define MODREC + +#include + +//procedure to receive email form outside +extern void rec_getemail(); + +//homework to be done before starting/stoping module. +extern int rec_modemodrec(_Bool mode); + +#endif diff --git a/lib/subrou.c b/lib/subrou.c index ae0ddd9..c47a0ef 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -4,6 +4,7 @@ /* Module for low level subroutine */ /* */ /********************************************************/ +#include #include #include #include @@ -14,7 +15,7 @@ //version definition #define VERSION "0.1" -#define RELEASE "10" +#define RELEASE "11" //Public variables PUBLIC int debug=0; //debug level @@ -181,6 +182,7 @@ if (mode!=modopen) { debug=0; off64_time=(time_t)0; off_date=(time_t)0; + (void) srand((int)(M_PI*100000000)); if (appname!=(char *)0) (void) free(appname); appname=strdup(APPNAME); diff --git a/lib/uniprc.c b/lib/uniprc.c index 4ff3b29..d56d47b 100644 --- a/lib/uniprc.c +++ b/lib/uniprc.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +70,21 @@ if (setrlimit(RLIMIT_CORE,&limites)<0) { */ /********************************************************/ /* */ +/* */ +/* Procedure to allow exited child process */ +/* to leave the zombie stat. */ +/* */ +/********************************************************/ +void prc_nozombie() + +{ +while (waitpid(-1,(int *)0,WNOHANG)>0); +} +/* +^L +*/ +/********************************************************/ +/* */ /* procedure to check if a process is */ /* still up and running. */ /* */ diff --git a/lib/uniprc.h b/lib/uniprc.h index d188ae2..e197a60 100644 --- a/lib/uniprc.h +++ b/lib/uniprc.h @@ -35,6 +35,10 @@ extern void prc_allow_core_dump(); //with an explication message extern void prc_core_dump(const char *fmt,...); +//routine to make sure all child process are out of +//zombie state +extern void prc_nozombie(); + //routine to check if a proces is still up and running extern _Bool prc_checkprocess(pid_t pidnumber);