]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Working about SIGCHILD received (lot of trace)
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 9 May 2025 14:33:35 +0000 (10:33 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 9 May 2025 14:33:35 +0000 (10:33 -0400)
Makefile
Notes
data-feed/xxfeed.tst
lib/devlog.c
lib/devsoc.c
lib/gestcp.c
lib/lvleml.c
lib/lvleml.h
lib/modrec.c
lib/unisig.c
lib/unisig.h

index 6f1607e444f8ee20d0e2d68bbbee18bcda56ea3e..303d8db45d8b8f849275e8efb4ce54d8fbb3e826 100644 (file)
--- 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 f74bac514fd843b4db42562818c3cfb80dd0d2f9..76e99535a1042119f9e7ca2c8beb06b5a5cb365c 100644 (file)
--- 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
+#-----------------------------------------------------------
index 08515d2d0004d659ae713e49275a8f87d5f1e1fd..0494b0aeffcbe48620d50551a9f0e8f134d4fd26 100644 (file)
@@ -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: <postmaster@example.com>
 R:250 2.1.3 postmaster@example.com.. sender ok
 S:RCPT TO: <postmaster@example.com>
 R:250 2.6.2 Address accepted
+S:RCPT TO: <webmaster@example.com>
+R:250 2.6.2 Address accepted
 #-------------------------------------------------------------------------
 #-sending data
 C:DATA
index cb1c64f86fb81666954dacff19c86fa037b88e41..7fc569afba4a4579ee24c1679a8833ce86a1c7d2 100644 (file)
@@ -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) 
index fe5b1128fef8172f5555cb0fcbb278bd74124039..b69555fa4c8b2f8a7aa9441038ddd1c3ad14b01f 100644 (file)
@@ -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
index 6aa72f3dc6ca0b4fe6499055505c1ba776dbf275..ab7d2b92d4676ce08d8e0a787b99aae0454e76d9 100644 (file)
@@ -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))
index becf33ef4032e7e79998a14e167bab2c9c830cb3..6bd69d254e8258171d0e745c6ef4c522bf8a03ce 100644 (file)
@@ -8,11 +8,13 @@
 #include        <arpa/inet.h>
 #include        <sys/types.h>
 
+#include        <errno.h>
 #include        <netdb.h>
 #include        <stdbool.h>
 #include        <stdlib.h>
 #include        <stdio.h>
 #include        <string.h>
+#include        <signal.h>
 #include        <unistd.h>
 
 #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
+}
index 3c354a0781f8f5a458f100794a02e76c3f4ab8dd..f1954db71e9363fc04f8598adf6fd304a672706c 100644 (file)
@@ -8,6 +8,8 @@
 #ifndef        LVLEML
 #define LVLEML
 
+#include        <stdio.h>
+
 #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
index 93602fb58a836ce4b95686632b2ddcb5e0ff387c..b52ee54ece28f618c0744e5a39852d23367b41d2 100644 (file)
@@ -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);
index 69960c11295b36a9ba96360ae1562507928c273d..2cb0513db9e89c6121fe1644b25cd29e6326a5a0 100644 (file)
@@ -4,7 +4,9 @@
 /*     Module for signal handling level                */
 /*                                                     */
 /********************************************************/
+#include        <errno.h>
 #include        <sys/wait.h>
+#include        <sys/signalfd.h>
 #include        <stdlib.h>
 #include        <stdio.h>
 #include        <string.h>
 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
 /*
 \f
 */
@@ -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);
index 61336d467d157dbee2a79b26aafe8e38dafdf3f1..9c50ea9a913ac2a9df193935cb085ec9270c18c3 100644 (file)
@@ -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);