From 2e5ef8890115350ec6ffaeaba3b3622e42f86c63 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Wed, 26 Mar 2025 10:59:00 -0400 Subject: [PATCH] Foreground working and no apprent memory leak --- Makefile | 28 ++++++++++++++++++---------- lib/devsoc.c | 36 ++++++++++++++++++++++++++++++++++-- lib/gestcp.c | 3 +++ lib/lvleml.c | 5 ++++- lib/modrec.c | 10 ++++++---- lib/subrou.c | 2 +- lib/unisig.c | 2 ++ 7 files changed, 68 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index c4174df..72959d1 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,13 @@ FEEDPAR = \ $(TESTPORT) \ $(TESTDIR)/$(DATATST)/feed*.tst \ +onefeed : debug + @ bin/feeder \ + -d 3 \ + $(TESTIP) \ + $(TESTPORT) \ + $(TESTDIR)/$(DATATST)/feed00.tst + #direct test tstfeed : debug @ bin/feeder $(FEEDPAR) @@ -56,15 +63,16 @@ EMLPAR = \ -d 8 \ :$(TESTIP):$(TESTPORT) \ -emlrcvr : debug newtest +emlrcvr : clean debug newtest #starting email receiver @ echo @ echo "--------------" @ echo "starting $@" @ $(TESTDIR)/$(SBINDIR)/$@ \ + -f \ $(EMLPAR) @ echo "--------------" -valrcvr : clean debug newtest #valgrin dest +valrcvr : clean debug newtest #valgring of emlrcvr @ echo "emlrec valgrind test" @ valgrind \ --leak-check=full \ @@ -77,7 +85,7 @@ valrcvr : clean debug newtest #valgrin dest # --track-origins=yes \ # --trace-children=no \ -dbgrcvr : clean debug newtest #using gdb +dbgrcvr : clean debug newtest #debugging emlrcvr @ gdb --args \ $(TESTDIR)/$(SBINDIR)/emlrcvr \ -f \ @@ -105,11 +113,11 @@ newtest : deltest @ mkdir -p $(TESTDIR)/var/run @ mkdir -p $(TESTDIR)/var/spool/clement/{in,out}-logs @ mkdir -p $(TESTDIR)/$(SBINDIR) - @ cp -a \ - bin/{chkspf,emlrcvr} \ + @ cp -a \ + bin/{chkspf,emlrcvr} \ $(TESTDIR)/$(SBINDIR) - @ cp -a \ - $(DATATST) \ + @ cp -a \ + $(DATATST) \ $(TESTDIR) deltest : @@ -122,9 +130,9 @@ install : @ echo $@ need to implemented #-------------------------------------------------------------------- -SUBDIR = \ - lib \ - app \ +SUBDIR = \ + lib \ + app \ #-------------------------------------------------------------------- #definitions globale diff --git a/lib/devsoc.c b/lib/devsoc.c index a99ac98..5e5650e 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -739,6 +739,7 @@ if (seteuid(getuid())<0) phase=0; proceed=true; while (proceed==true) { + (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); switch (phase) { case 0 : //sanity check if (soc==(SOCTYP *)0) { @@ -747,8 +748,9 @@ while (proceed==true) { } break; case 1 : //check if time to retry binding - if ((soc->lasttry+5)>time((time_t)0)) + if ((soc->lasttry+5)>time((time_t)0)) { phase=999; //no need to go further + } break; case 2 : //to have the right address infp int status; @@ -832,6 +834,7 @@ while (proceed==true) { soc->handle=-1; break; default : //SAFE Guard + soc->lasttry=(time_t)0; proceed=false; break; } @@ -851,6 +854,7 @@ while (proceed==true) { PUBLIC int soc_waitforchar(SOCPTR *socptr,TIMESPEC *attend) { +#define OPEP "devsoc.c:soc_waitforchar" register int status; SOCTYP *soc; @@ -859,7 +863,7 @@ soc=(SOCTYP *)socptr; if (soc!=(SOCTYP *)0) { struct pollfd polling[1]; - polling[0].events=POLLIN|POLLPRI; + polling[0].events=POLLIN|POLLPRI|POLLERR|POLLHUP; polling[0].revents=(short)0; switch (soc->modtls) { case true : @@ -870,8 +874,29 @@ if (soc!=(SOCTYP *)0) { break; } status=ppoll(polling,1,attend,(sigset_t *)0); + switch (status) { + case -1 : + (void) rou_alert(0,"%s Polling error (error=<%s>)",OPEP,strerror(errno)); + break; + case 0 : + (void) rou_alert(0,"%s Polling timeout",OPEP); + break; + case 1 : + if ((polling[0].revents&POLLHUP)==POLLHUP) { + (void) close(soc->handle); + soc->handle=-1; + status=0; + } + if ((polling[0].revents&POLLERR)==POLLERR) { + (void) rou_alert(0,"%s Polling POLLERR detection",OPEP); + } + break; + default : + break; + } } return status; +#undef OPEP } /* ^L @@ -953,6 +978,8 @@ return got; PUBLIC int soc_writebuffer(SOCPTR *socptr,char *buffer,int tosend) { +#define OPEP "devsoc.c:soc_writebuffer" + int sent; SOCTYP *soc; @@ -967,8 +994,13 @@ if (soc!=(SOCTYP *)0) { sent=send(soc->handle,buffer,tosend,0); break; } + if (sent<0) { + (void) rou_alert(0,"%s Unable to send data, error=%d <%s> (Bug)", + OPEP,errno,strerror(errno)); + } } return sent; +#undef OPEP } /* ^L diff --git a/lib/gestcp.c b/lib/gestcp.c index 2c34b41..dbf30cb 100644 --- a/lib/gestcp.c +++ b/lib/gestcp.c @@ -42,6 +42,7 @@ got=0; phase=0; proceed=true; while (proceed==true) { + (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); switch (phase) { case 0 : if (socptr==(SOCPTR *)0) { @@ -52,9 +53,11 @@ while (proceed==true) { case 1 : //get nextline if ((got=soc_getnextline(socptr,lineptr))>0) phase=999; //we got a line. + (void) rou_alert(0,"JMPDBG %s phase='%d' got='%d'",OPEP,phase,got); break; case 2 : //waiting for new character presence got=soc_waitforchar(socptr,attend); + (void) rou_alert(0,"JMPDBG %s phase='%d' got='%d'",OPEP,phase,got); switch (got) { case -1 : //trouble? signal? if ((hangup==true)||(reload==true)) diff --git a/lib/lvleml.c b/lib/lvleml.c index 3cb2640..352ccaf 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -318,8 +318,11 @@ while (proceed==true) { attend.tv_sec=60; attend.tv_nsec=0; status=tcp_getline(contact->socptr,&attend,&line); - if (status<=0) //timeout or trouble? + (void) rou_alert(0,"%s, JMPDBG tcp_getline status='%d'",OPEP,status); + if (status<=0) { //timeout or trouble? + (void) rou_alert(0,"%s, lost contact",OPEP); break; //no need to go further + } (void) log_fprintlog(contact->logptr,false,"%s",line); switch (eml_getcode(line)) { case c_helo : //HELO SMTP protocol diff --git a/lib/modrec.c b/lib/modrec.c index db5d904..4d87ede 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -44,7 +44,7 @@ static int prepbinding(SOCPTR ***bindings,int argc,char *argv[]) { -#define OPEP "moderec.c:prepbinding" +#define OPEP "modrec.c:prepbinding" *bindings=(SOCPTR **)0; for (int i=0;i closed by timeout", contact->peerip); break; default : //exit under quit + (void) rou_alert(0,"JMPDBG exit under quit"); break; } break; @@ -248,7 +249,7 @@ while (proceed==true) { static void startwaiter(SOCPTR *socptr) { -#define OPEP "moderec.c:startwaiter" +#define OPEP "modrec.c:startwaiter" int phase; _Bool proceed; @@ -372,5 +373,6 @@ while (proceed==true) { } phase++; } +(void) rou_alert(0,"JMPDBG %s exiting",OPEP); #undef OPEP } diff --git a/lib/subrou.c b/lib/subrou.c index f484efc..7cedae9 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -21,7 +21,7 @@ //version definition #define VERSION "0.6" -#define RELEASE "14" +#define RELEASE "15" //Public variables PUBLIC int debug=0; //debug level diff --git a/lib/unisig.c b/lib/unisig.c index 1be9871..18eec15 100644 --- a/lib/unisig.c +++ b/lib/unisig.c @@ -174,11 +174,13 @@ if (onoff==true) { (void) sigaction(SIGQUIT,newsa,olds[4]); (void) sigaction(SIGHUP,newsa,olds[5]); (void) sigaction(SIGALRM,newsa,olds[6]); + (void) sigaction(SIGPIPE,newsa,olds[6]); (void) free(newsa); } else { int i; + (void) sigaction(SIGPIPE,olds[6],(struct sigaction *)0); (void) sigaction(SIGALRM,olds[6],(struct sigaction *)0); (void) sigaction(SIGHUP,olds[5],(struct sigaction *)0); (void) sigaction(SIGQUIT,olds[4],(struct sigaction *)0); -- 2.47.3