From: Jean-Marc Pigeon (Delson) Date: Fri, 9 May 2025 14:33:35 +0000 (-0400) Subject: Working about SIGCHILD received (lot of trace) X-Git-Tag: tag-0.8~117 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=6550c0a65320448a2c69fcf7b6c6f0f2f7c0f083;p=jmp%2Fmailleur Working about SIGCHILD received (lot of trace) --- diff --git a/Makefile b/Makefile index 6f1607e..303d8db 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ TESTPORT= 1025 #TESTPROT= smtps EXTIP = safemail3.safe.ca EXTPORT = 25 -TESTITER= 3 +TESTITER= 4 #-------------------------------------------------------------------- #testing feed FEEDPAR = \ @@ -182,6 +182,7 @@ eml465 : prepare -r $(TESTDIR) \ smtps:$(TESTIP):1065:1 +#VALKIND= "definite,possible,indirect,reachable" VALKIND = "definite,possible,indirect" valrcvr : prepare #valgring of emlrcvr @ echo "emlrec valgrind test" @@ -190,6 +191,7 @@ valrcvr : prepare #valgring of emlrcvr --show-leak-kinds=$(VALKIND) \ $(TESTDIR)/$(SBINDIR)/emlrcvr \ -f \ + -d 3 \ $(EMLPAR) # --track-fds=yes \ diff --git a/Notes b/Notes index f74bac5..76e9953 100644 --- a/Notes +++ b/Notes @@ -3,3 +3,11 @@ Versions: #----------------------------------------------------------- MA-0.6-dvl, certificat exchange is working properly #----------------------------------------------------------- +#Format for trans file +status date delta session from rcpt +Char long int char * char * char * +status can be: + D delayed + R Ready + S Sent +#----------------------------------------------------------- diff --git a/data-feed/xxfeed.tst b/data-feed/xxfeed.tst index 08515d2..0494b0a 100644 --- a/data-feed/xxfeed.tst +++ b/data-feed/xxfeed.tst @@ -4,13 +4,17 @@ T:Very Simple email sending R:220 mailleur.example.com ESMTP (cleartext) emlrcvr... C:ORGN 127.127.0.2 R:220 mailleur.example.com ESMTP (cleartext) emlrcvr... +C:WAIT 100 #==================================================== S:HELO example.com -R:250-mailleur.example.com, link (cleartext) ready, your IP/FQDN=[127.127.0.2/feed2.example.com] +#R:250-mailleur.example.com, link (cleartext) ready, your IP/FQDN=[127.127.0.2/feed2.example.com] +R:250-mailleur.example.com, link (cleartext) ready,... S:MAIL FROM: R:250 2.1.3 postmaster@example.com.. sender ok S:RCPT TO: R:250 2.6.2 Address accepted +S:RCPT TO: +R:250 2.6.2 Address accepted #------------------------------------------------------------------------- #-sending data C:DATA diff --git a/lib/devlog.c b/lib/devlog.c index cb1c64f..7fc569a 100644 --- a/lib/devlog.c +++ b/lib/devlog.c @@ -80,7 +80,7 @@ event=(char *)0; phase=0; proceed=true; while (proceed==true) { - //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); + (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); switch (phase) { case 0 : //do we have a log name? if (logname==(char *)0) { @@ -237,7 +237,7 @@ log=(LOGTYP *)logptr; phase=0; proceed=true; while (proceed==true) { - //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); + (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); switch (phase) { case 0 : //do we have a log reference? if (log==(LOGTYP *)0) diff --git a/lib/devsoc.c b/lib/devsoc.c index fe5b112..b69555f 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -291,7 +291,7 @@ _Bool proceed; phase=0; proceed=true; while (proceed==true) { - //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); + (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); switch (phase) { case 0 : //is the connect still active if (soc->connected==false) //no!, no need to shutdown @@ -317,6 +317,9 @@ while (proceed==true) { "(errno=<%s>)", OPEP,soc->ip,soc->port,strerror(errno)); } + (void) rou_alert(0,"JMPDBG %s sleep in",OPEP,phase); + (void) sleep(1); //JMPDBG + (void) rou_alert(0,"JMPDBG %s sleep out",OPEP,phase); break; default : //SAFE Guard proceed=false; @@ -889,8 +892,8 @@ while (proceed==true) { (void) freeaddrinfo(tobind); break; case 4 : //listening on socket - (void) prc_settitle("monitoring %02d contacts on %s:%s", - soc->iteration,soc->ip,soc->port); + (void) prc_settitle("%s, monitoring %02d contacts on %s:%s", + appname,soc->iteration,soc->ip,soc->port); if (listen(soc->handle,soc->iteration+4)<0) { (void) rou_alert(0,"%s, Unable to listen at address " "IP:port '%s:%s' (error='%s')", @@ -1250,7 +1253,7 @@ while (proceed==true) { } break; case 1 : //display ready on process status; - (void) prc_settitle("%s waiting on [%s:%s] (%02d/%02d)", + (void) prc_settitle("%s, waiting on [%s:%s] (%02d/%02d)", appname,soc->ip,soc->port,pos,soc->iteration); break; case 2 : //waiting for new connection diff --git a/lib/gestcp.c b/lib/gestcp.c index 6aa72f3..ab7d2b9 100644 --- a/lib/gestcp.c +++ b/lib/gestcp.c @@ -47,7 +47,7 @@ got=0; phase=0; proceed=true; while (proceed==true) { - //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); + (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); switch (phase) { case 0 : //link still open? if (soc_receive(socptr)<0) { @@ -63,6 +63,7 @@ while (proceed==true) { got=soc_waitforchar(socptr,secwait*1000); switch (got) { case -2 : //remote is disconnectd + (void) rou_alert(0,"%s remote is disconnected",OPEP); break; case -1 : //trouble? signal? if ((hangup==true)||(reload==true)) diff --git a/lib/lvleml.c b/lib/lvleml.c index becf33e..6bd69d2 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -8,11 +8,13 @@ #include #include +#include #include #include #include #include #include +#include #include #include "subrou.h" @@ -36,6 +38,9 @@ static CONTYP *freecontact(CONTYP *contact) if (contact!=(CONTYP *)0) { contact->sqlptr=sql_closesql(contact->sqlptr); contact->logptr=log_closelog(contact->logptr); + contact->rcptto=(char **)rou_freelist((void **)contact->rcptto, + (freehandler_t)rou_freestr); + contact->mailfrom=rou_freestr(contact->mailfrom); contact->cursesid=rou_freestr(contact->cursesid); contact->mainsesid=rou_freestr(contact->mainsesid); contact->fqdn=rou_freestr(contact->fqdn); @@ -194,6 +199,10 @@ while (proceed==true) { phase=999; //trouble trouble break; case 1 : //write data to trans file; + if (eml_mktransfile(contact,trans)==false) { + (void) eml_closeqfile(trans); + phase=999; //Trouble trouble + } break; case 2 : //closing transfile if (eml_closeqfile(trans)<0) @@ -474,7 +483,11 @@ while (proceed==true) { rcptto[strlen(rcptto)-1]='\000'; (void) memmove(rcptto,rcptto+1,strlen(rcptto)); break; - case 2 : //everything ok + case 2 : //Storing rcpt to + contact->rcptto=(char **)rou_addlist((void **)contact->rcptto, + (void *)strdup(rcptto)); + break; + case 3 : //everything ok (void) transmit(contact,"%d 2.6.2 Address accepted",CMDOK); break; default : //SAFE guard @@ -720,7 +733,7 @@ return contact; /********************************************************/ /* */ /* Procedure to wait for a remote client. */ -/* return all reference to contact. */ +/* return the frreed memory contact (NULL pointer) */ /* */ /********************************************************/ PUBLIC CONTYP *eml_dropcontact(CONTYP *contact) @@ -734,6 +747,7 @@ _Bool proceed; phase=0; proceed=true; while (proceed==true) { + (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); switch (phase){ case 0 : //check for binding if (contact==(CONTYP *)0) { @@ -745,6 +759,8 @@ while (proceed==true) { (void) rou_alert(0,"Contact from peer <%s> to port <%s> terminated", contact->peerip,contact->locserv); contact->socptr=soc_release(contact->socptr); + //(void) kill(getppid(),SIGCHLD); + //(void) rou_alert(0,"%s JMPDBG signal SIGCHLD sent to='%d'",OPEP,getppid()); break; case 2 : //freeing contact memory contact=freecontact(contact); @@ -758,3 +774,40 @@ while (proceed==true) { return contact; #undef OPEP } +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to generate transfile contents */ +/* return all reference to contact. */ +/* */ +/********************************************************/ +PUBLIC _Bool eml_mktransfile(CONTYP *contact,FILE *qfile) + +{ +#define OPEP "lvleml.c:eml_mktrans" + +_Bool status; + +if ((contact!=(CONTYP *)0)&&(contact->rcptto!=(char **)0)) { + char **ptr; + + ptr=contact->rcptto; + while (*ptr!=(char *)0) { + time_t isnow; + + status=true; + isnow=time((time_t *)0); + if (fprintf(qfile,"%c %ld %d %s %s %s\n", + 'R',isnow,0,contact->cursesid,contact->mailfrom,*ptr)<0) { + (void) rou_alert(0,"%s Unable to write transfile (error=<%s>)", + OPEP,strerror(errno)); + status=false; + } + ptr++; + } + } +return status; +#undef OPEP +} diff --git a/lib/lvleml.h b/lib/lvleml.h index 3c354a0..f1954db 100644 --- a/lib/lvleml.h +++ b/lib/lvleml.h @@ -8,6 +8,8 @@ #ifndef LVLEML #define LVLEML +#include + #include "devsoc.h" #include "devsql.h" #include "gestcp.h" @@ -24,6 +26,7 @@ typedef struct { char *mainsesid;//session main ID char *cursesid; //current session ID char *mailfrom; //current mail from originator + char **rcptto; //List of mail recipient LOGPTR *logptr; //reference to session log }CONTYP; @@ -36,4 +39,7 @@ extern CONTYP *eml_getcontact(SOCPTR *socptr,int pos); //drop contact established by remote extern CONTYP *eml_dropcontact(CONTYP *contact); + +//generate trans file contents +extern _Bool eml_mktransfile(CONTYP *contact,FILE *qfile); #endif diff --git a/lib/modrec.c b/lib/modrec.c index 93602fb..b52ee54 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -121,7 +121,7 @@ intstat=0; phase=0; proceed=true; while (proceed==true) { - //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); + (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); switch (phase) { case 0 : //waiting contact (void) rou_checkleak(true); @@ -129,13 +129,13 @@ while (proceed==true) { phase=999; //No contact! break; case 1 : //within forked process - (void) prc_settitle("Processing incoming contact from [%s] on [%s:%s]", - contact->peerip,contact->locname,contact->locserv); + (void) prc_settitle("%s, incoming contact from [%s] on [%s:%s]", + appname,contact->peerip,contact->locname,contact->locserv); break; case 2 : //do contact intstat=eml_docontact(contact); switch (intstat) { - case 1 : //quit done + case 1 : //command 'quit' receoved break; case 0 : //exit under timeout (void) rou_alert(0,"Contact timeout with peer <%s>",contact->peerip); @@ -154,6 +154,7 @@ while (proceed==true) { case 3 : //connection terminated contact=eml_dropcontact(contact); (void) rou_checkleak(false); + (void) rou_alert(0,"%s JMPBG apres checleak",OPEP); break; default : //SAFE guard proceed=false; @@ -218,20 +219,28 @@ while (proceed==true) { (void) docontact(socptr,i+1); (void) exit(0); break; - default : //Main process + default : //Main process relax (void) usleep(10000); break; } } - if ((hangup==true)||(reload==true)) - phase=999; break; case 3 : //Relax time - if ((hangup==false)&&(reload==false)) - phase=0; //lets continue to check childs if (foreground==true) phase=999; //foreground ->one shot deal break; + case 4 : //Relax time + phase=0; //lets continue to check childs + (void) rou_alert(0,"%s, start sleep",OPEP); + (void) sleep(10); //signal received to exit fast. + if (childout==true) { + (void) rou_alert(0,"%s, Got child out",OPEP); + childout=false; + } + (void) rou_alert(0,"%s, Exit from sleep",OPEP); + if ((hangup==true)||(reload==true)) + phase=999; //exiting under signal + break; default : //SAFE Guard (void) prc_killchilds(childs,iterations,maxretry); (void) free(childs); diff --git a/lib/unisig.c b/lib/unisig.c index 69960c1..2cb0513 100644 --- a/lib/unisig.c +++ b/lib/unisig.c @@ -4,7 +4,9 @@ /* Module for signal handling level */ /* */ /********************************************************/ +#include #include +#include #include #include #include @@ -14,8 +16,10 @@ PUBLIC _Bool hangup; //Hangup signal received PUBLIC _Bool reload; //reload configuration signal received PUBLIC _Bool wakeup; //application wakeup under an alarm +PUBLIC _Bool childout; //application child signal static _Bool modopen; //boolean module open/close +static int sfd; //Signal detail information /* */ @@ -85,11 +89,21 @@ PUBLIC void sig_alrm(int sig) { #define OPEP "unisig.c:sig_alrm" -(void) rou_alert(10,"%s, signal <%s> received",OPEP,strsignal(sig)); +(void) rou_alert(0,"%s, signal <%s> received",OPEP,strsignal(sig)); switch (sig) { - case SIGCHLD : + case SIGCHLD : { +/* + struct signalfd_siginfo sfd_si; + + if (read(sfd,&sfd_si,sizeof(sfd_si))<0) { + (void) rou_alert(0,"%s, Unable to get siginfo (error=<%s>)", + OPEP,strerror(errno)); + } + */ + childout=true; while (waitpid(-1,(int *)0,WNOHANG)>0); + } break; case SIGQUIT : case SIGTERM : @@ -125,6 +139,7 @@ switch (sig) } //able to receive next signal (void) signal(sig,sig_alrm); +(void) rou_alert(0,"%s, signal <%s> exited",OPEP,strsignal(sig)); #undef OPEP } /* @@ -139,8 +154,8 @@ switch (sig) PUBLIC void sig_trapsignal(_Bool onoff,sighandler_t trap) { -#define OPEP "modbck.c:settrap" -#define NUMINTR 7 +#define OPEP "unisig.c:settrap" +#define NUMINTR 9 static struct sigaction *olds[NUMINTR]; static _Bool alldone=false; @@ -159,9 +174,12 @@ if (onoff==alldone) { } } if (onoff==true) { + sigset_t mask; struct sigaction *newsa; int i; + (void) sigemptyset(&mask); + (void) sigaddset(&mask,SIGCHLD); newsa=(struct sigaction *)calloc(1,sizeof(struct sigaction)); newsa->sa_flags=0; newsa->sa_handler=trap; @@ -176,13 +194,19 @@ 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) sigaction(SIGPIPE,newsa,olds[7]); + (void) sigaction(SIGCHLD,newsa,olds[8]); (void) free(newsa); + if ((sfd=signalfd(-1, &mask, 0))<0) { + (void) rou_alert(0,"%s Unable to set signalfd (error=<%s>)", + OPEP,strerror(errno)); + } } else { int i; - (void) sigaction(SIGPIPE,olds[6],(struct sigaction *)0); + (void) sigaction(SIGCHLD,olds[8],(struct sigaction *)0); + (void) sigaction(SIGPIPE,olds[7],(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); diff --git a/lib/unisig.h b/lib/unisig.h index 61336d4..9c50ea9 100644 --- a/lib/unisig.h +++ b/lib/unisig.h @@ -19,6 +19,7 @@ typedef void (*sighandler_t)(int); extern _Bool hangup; //Hangup signal received extern _Bool reload; //reload configuration signal received extern _Bool wakeup; //just got a signal +extern _Bool childout; //A child process just vanished //"standard" signal trap extern void sig_alrm(int sig);