From: Jean-Marc Pigeon (Delson) Date: Fri, 6 Jun 2025 11:53:07 +0000 (-0400) Subject: Improving hanlde smto loop X-Git-Tag: tag-0.8~65 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=18682b83b406200407031bf717d8cb07e7d56c57;p=jmp%2Fmailleur Improving hanlde smto loop --- diff --git a/Makefile b/Makefile index 00bfc4c..741e6f2 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ TESTPORT= 1025 #TESTPROT= smtps EXTIP = safemail3.safe.ca EXTPORT = 25 -TESTITER= 4 +TESTITER= 1 #-------------------------------------------------------------------- #To test sorter dosorter: debug @@ -248,7 +248,7 @@ tlsref: EMLPAR = \ -r $(TESTDIR) \ -c ./conf/$(APPNAME).conf.dvl \ - -d 3 \ + -d 2 \ $(TESTPROT):$(TESTIP):$(TESTPORT): dorcvr : debug @@ -306,7 +306,7 @@ prepare : debug newtest #to kill all remaining emlrcvr process killall : - @ - kill -9 emlrcvr + @ - kill -HUP emlrcvr @ - kill -9 sorter #-------------------------------------------------------------------- diff --git a/app/sorter.c b/app/sorter.c index d403926..f513bde 100644 --- a/app/sorter.c +++ b/app/sorter.c @@ -122,11 +122,16 @@ while (proceed==true) { (void) rou_setappname(SORTER); (void) rou_loadconfig(config,true); (void) openlog(appname,LOG_NDELAY|LOG_PID,LOG_DAEMON); - (void) closelog(); break; - case 2 : //check about signal - if ((hangup==true)||(reload==true)) - phase=999; //Process + case 2 : //check about signal process + if (hangup==true) { + (void) rou_alert(0,"%s got hangup signal",OPEP); + phase=999; //exiting loop + } + if (reload==true) { + (void) rou_alert(0,"%s got reload signal",OPEP); + phase=999; //exiting loop + } break; case 3 : //Scanning all ".trans" file (void) scantrans(EXTRANS,true); @@ -145,6 +150,7 @@ while (proceed==true) { (void) rou_loadconfig(config,false); (void) sig_modeunisig(false); (void) rou_modesubrou(false); + (void) closelog(); proceed=false; break; } diff --git a/lib/devsoc.c b/lib/devsoc.c index 6757dd3..c78fd08 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -180,7 +180,7 @@ if ((newhandle=accept(soc->handle,(SOCKADDR *)0,(socklen_t *)0))<0) { OPEP,soc->ip,soc->port,strerror(errno)); break; case EINTR : - (void) rou_alert(3,"%s Socket on IP/PORT <%s/%s> got a signal " + (void) rou_alert(5,"%s Socket on IP/PORT <%s/%s> got a signal " "(errno=<%s>)", OPEP,soc->ip,soc->port,strerror(errno)); break; @@ -1257,7 +1257,7 @@ while (proceed==true) { break; case 2 : //waiting for new connection if ((newsoc=waitincoming(soc))==(SOCPTR *)0) { - (void) rou_alert(0,"%s, Contact from Remote not successful",OPEP); + (void) rou_alert(4,"%s, Contact from Remote not successful",OPEP); phase=999; //no need to go further } break; diff --git a/lib/devsql.c b/lib/devsql.c index 6a9c002..e3b0d46 100644 --- a/lib/devsql.c +++ b/lib/devsql.c @@ -79,6 +79,7 @@ sql=(SQLTYP *)0; phase=0; proceed=true; while (proceed==true) { + //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); switch (phase) { case 0 : //get database parameters for (int i=0;i<(sizeof(dbenv)/sizeof(char *));i++) { @@ -109,6 +110,7 @@ while (proceed==true) { break; case 3 : //checking if the database is properly open if (sql->db.psql==(POSPTR *)0) { + (void) rou_alert(0,"%s data-base not properly connected (config?)",OPEP); (void) free(sql); sql=(SQLTYP *)0; phase=999; //Trouble trouble @@ -148,7 +150,7 @@ while (proceed==true) { switch (phase) { case 0 : //check if database available if (sql==(SQLTYP *)0) { - (void) rou_alert(0,"%s %s Datbase pointer null (bug?)",OPEP); + (void) rou_alert(0,"%s %s Database pointer is NULL (bug?)",OPEP); phase=999; } break; diff --git a/lib/lvleml.c b/lib/lvleml.c index aaf55b7..a7ce213 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -35,7 +35,7 @@ static CONTYP *freecontact(CONTYP *contact) { -#define OPEP "gestcp.c:freecontact" +#define OPEP "lvleml.c:freecontact" if (contact!=(CONTYP *)0) { contact->sqlptr=sql_closesql(contact->sqlptr); @@ -849,8 +849,7 @@ while (proceed==true) { break; case 2 : //waiting from contact if ((contact->socptr=soc_accept(socptr,pos))==(SOCPTR *)0) { - (void) rou_alert(0,"%s Unable to open contact",OPEP); - contact->sqlptr=sql_closesql(contact->sqlptr); + (void) rou_alert(3,"%s Unable to open contact",OPEP); contact=freecontact(contact); phase=999; //no contact } diff --git a/lib/modrec.c b/lib/modrec.c index 41b7df4..d0236f7 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -310,6 +310,7 @@ PUBLIC void rec_handlesmtp(int argc,char *argv[]) { #define OPEP "modrec.c:rec_handlesmtp" +#define RELAX 5 //Relax time between process checking pid_t *childs; int nbrbind; @@ -334,7 +335,13 @@ while (proceed==true) { } childs=(pid_t *)calloc(nbrbind,sizeof(pid_t)); break; - case 1 : //Opening ALL channels + case 1 : //Detecting signal + if ((hangup==true)||(reload==true)) { + (void) prc_killchilds(childs,nbrbind,10); + phase=999; //No need to have sub process; + } + break; + case 2 : //Opening ALL channels allbusy=true; for (int i=0;i)", OPEP,strerror(errno)); childs[i]=(pid_t)0; - (void) sleep(1); //Weathering the storm + (void) sleep(2); //Weathering the storm break; case 0 : //Child process itself (void) startwaiter(bindings[i]); + (void) exit(0); break; default : //Main process (void) usleep(10000); @@ -379,14 +387,9 @@ while (proceed==true) { } } break; - case 4 : //relax time - if ((hangup==false)&&(reload==false)&&(foreground==false)) - phase=0; //Normal process, lets restart - else - (void) usleep(10000); - break; - case 5 : //we got a signal, kill all childs - (void) prc_killchilds(childs,nbrbind,10); + case 5 : //lets continue within process loop + if (foreground==false) + phase=0; break; default : //SAFE Guard if (childs!=(pid_t *)0) @@ -397,5 +400,7 @@ while (proceed==true) { } phase++; } + +#undef RELAX #undef OPEP } diff --git a/lib/subrou.c b/lib/subrou.c index d97d181..67ace47 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -438,25 +438,29 @@ PUBLIC void rou_valert(const int dlevel,const char *fmt,va_list ap) { if (debug>=dlevel) { - char *ptr; char strloc[10000]; (void) memset(strloc,'\000',sizeof(strloc)); (void) vsnprintf(strloc,sizeof(strloc)-1,fmt,ap); - ptr=strloc; if (foreground==true) (void) fprintf(stderr,"%s\n",strloc); else { + char *ptr; + char lvl[10]; + + ptr=strloc; + (void) snprintf(lvl,sizeof(lvl),":%02d: ",dlevel); while (strlen(ptr)>DEBMAX) { char locline[DEBMAX+10]; (void) strncpy(locline,ptr,DEBMAX); locline[DEBMAX]='\000'; - (void) syslog(LOG_INFO,"%s",locline); + (void) syslog(LOG_INFO,"%s%s",lvl,locline); ptr +=DEBMAX; + (void) strcpy(lvl,""); } if (strlen(ptr)>0) - (void) syslog(LOG_INFO,"%s",ptr); + (void) syslog(LOG_INFO,"%s%s",lvl,ptr); } } }