]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Improving hanlde smto loop
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 6 Jun 2025 11:53:07 +0000 (07:53 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 6 Jun 2025 11:53:07 +0000 (07:53 -0400)
Makefile
app/sorter.c
lib/devsoc.c
lib/devsql.c
lib/lvleml.c
lib/modrec.c
lib/subrou.c

index 00bfc4cdd99d77fee89919f1dc200cd516d8a964..741e6f23904f94741817a352ebdcb75d1a729848 100644 (file)
--- 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
 
 #--------------------------------------------------------------------
index d4039260a469f21204cdf5f4a4a7f874d05e9690..f513bdea4f2fe93ae61dce894b89e160eb20172e 100644 (file)
@@ -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;
     }
index 6757dd34fec6a3a62f9f2df924a17a1a1b92be38..c78fd08c1ddf0d1e09cb1ad92475d1ac722ae692 100644 (file)
@@ -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;
index 6a9c0025fb8724dcf246e6c3726f3028909ad10e..e3b0d46856b78289a269fb4c4c05cb161510d639 100644 (file)
@@ -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;
index aaf55b7fa1c0cce8d7b3d29bc4786feae6ebd4ec..a7ce213251c9823ec45cc0b43edfa003b02f939a 100644 (file)
@@ -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 
         }
index 41b7df42bb5fc2be750f36ddae42ef7879b1f5a8..d0236f701373ea31970a43272f9cb581228c70ec 100644 (file)
@@ -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<nbrbind;i++) {
         (void) prc_nozombie();
@@ -348,17 +355,17 @@ while (proceed==true) {
           }
         }
       if (allbusy==true) {      //all serveur up and running?
-        (void) sleep(1);        //yes then relax
+        (void) sleep(RELAX);    //yes! then relax 
         phase=0;                //Lets check again
         }
       break;
-    case 2      :       //starting one process only
+    case 3      :       //starting one process only
       if (foreground==true) {
         (void) startwaiter(bindings[0]);
         phase++;        //no multiple fork
         }
       break;
-    case 3      :       //starting/restarting all waiting process
+    case 4      :       //starting/restarting all waiting process
       for (int i=0;i<nbrbind;i++) {
         if (childs[i]!=(pid_t)0)
           continue;
@@ -368,10 +375,11 @@ while (proceed==true) {
             (void) rou_alert(0,"%s Unable to fork smtp handler (error=<%s>)",
                                 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
 }
index d97d181f23f1f0c1b11b9d82fea4034d9e236b27..67ace4712548948a1687eb0ad95cecbe987720ce 100644 (file)
@@ -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);
     }
   }
 }