]> SAFE projects GIT repository - jmp/mailleur/commitdiff
missing emlrec detection contact subprocess working fine
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 15 Jul 2024 13:36:46 +0000 (09:36 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 15 Jul 2024 13:36:46 +0000 (09:36 -0400)
lib/gestcp.c
lib/modrec.c
lib/subrou.c
lib/unisoc.c

index 20cbe2e3959e78ac12732c1b2513d57e63a247d2..e0107fa6b4a49be657bbdb55709dd399b0e8d9cc 100644 (file)
@@ -36,15 +36,18 @@ int contact;
 socklen_t taille;
 struct sockaddr addr;
 
-contact=-1;
 taille=sizeof(addr);
-if ((contact=accept(binding->handle,&addr,&taille))<0) {
+contact=accept(binding->handle,&addr,&taille);
+(void) rou_alert(0,"JMPDBG, getcontact. acct status='%d' errno=<%s>",
+                    contact,strerror(errno));
+if (contact<0) {
   switch (errno)  {
     case EAGAIN         :
       /*well process not quick enough the handle was already    */
       /*accepted by another clement???.                         */
       break;
     case EINVAL         :       /*no socket avail anymore       */
+      contact--;                //There is NO main process anymore
       break;
     default             :
       (void) rou_alert(0,"%s Unexpected error on IP/PORT <%s/%s> errno=<%s>",
@@ -105,18 +108,23 @@ while (proceed==true) {
     case 2      :       //listening on the handle
       fd_set reading;
       struct timeval relax;
+      int status;
+
       FD_ZERO(&reading);
       FD_SET(binding->handle,&reading);
       relax.tv_sec=1;   //1 sec relax time
       relax.tv_usec=0;
-      switch (select(binding->handle+1,&reading,(fd_set *)0,(fd_set *)0,&relax)) {
+      status=select(binding->handle+1,&reading,(fd_set *)0,(fd_set *)0,&relax);
+      (void) rou_alert(0,"JMPDBG select status='%d' errno='%d'",status,errno);
+      switch (status) {
         case     -1     :     //got a wrong return
           switch (errno) {
             case EINTR  :       //Received a signal, get out! fast!
+              (void) rou_alert(0,"JMPDBG select received a signal!");
               phase=999;
               break;
             default     :       //Unexpected error?
-              (void) rou_core_dump("%, Unexpected select status (error=<%s>)",
+              (void) rou_core_dump("%s, Unexpected select status (error=<%s>)",
                                     OPEP,strerror(errno));
               break;            //never reached
             }
@@ -132,10 +140,21 @@ while (proceed==true) {
             phase=999;          //exiting
           break;
         default         :       //we got a contact
-          if ((contact=getcontact(binding))<0) 
-            phase--;            //not quick enough, lets continue to wait
+          contact=getcontact(binding);
+          switch (contact) {
+            case -2     :       //no handle anymore exiting
+              break;
+            case -1     :       //not quick enough
+              phase--;          //let continue to wait
+              (void) sleep(1);
+              break;
+            default     :       //we have a contact
+              break;
+            }
           break;
         }
+      (void) rou_alert(0,"JMPDBG exiting from select phase='%d' contact='%d'",
+                          phase,contact);
       break;
     default     :       //SAFE Guard
       proceed=false;
index cca60364a23d56a5c5e3c5ba8a7ca95ab0a707ab..625b7f94a31dd7fd5f578febc5524537484f46df 100644 (file)
@@ -8,6 +8,7 @@
 #include        <stdio.h>
 #include        <stdlib.h>
 #include        <string.h>
+#include        <syslog.h>
 #include        <unistd.h>
 
 #include        "subrou.h"
@@ -27,10 +28,11 @@ static  _Bool modopen;          //boolean module open/close
 /*      a remote TCP connection.                        */
 /*                                                     */
 /********************************************************/
-void contact(SOCTYP *binding) 
+void docontact(SOCTYP *binding) 
 
 {
 #define OPEP    "modrec.c:contact"
+#define TESTL   4
 
 CONTYP *contact;
 int phase;
@@ -41,22 +43,27 @@ phase=0;
 proceed=true;
 while (proceed==true) {
   switch (phase) {
-    case 0      :       //do we have a contact
+    case 0      :       //display waiting contact
+      (void) prc_settitle("Waiting contact on %s:%s",binding->ip,binding->port);
+      break;
+    case 1      :       //do we have a contact
       if ((contact=tcp_getcontact(binding))==(CONTYP *)0) {
         phase=999;      //no going further
         }
       break;
-    case 1      :       //do contact
-      for (int i=0;i<20;i++) {
-        (void) sleep(3);
+    case 2      :       //do contact
+      for (int i=0;i<TESTL;i++) {
+        (void) sleep(2);
         if ((reload==true)||(hangup==true))
           break;
+        if (prc_checkprocess(getppid())==false)
+          break;
         (void) dprintf(contact->channel,"JMPDBG pid=%d iteration=%d/%d\n",
-                                        getpid(),i,20);
+                                        getpid(),i,TESTL);
         
         }
       break;
-    case 2      :       //close contact
+    case 3      :       //close contact
       contact=tcp_dropcontact(contact);
       break;
     default     :       //SAFE guard
@@ -109,8 +116,12 @@ while (proceed==true) {
                                 OPEP,binding->ip,binding->port);
             break;
           case 0        :               //the dispatched process
-            (void) contact(binding);    //waiting, handling remote contact
+            (void) closelog();
+            (void) openlog("Contact",LOG_PID,LOG_DAEMON);
+            (void) docontact(binding);  //waiting, handling remote contact
+            (void) rou_alert(0,"Contact Exiting: %s-%s",appname,rou_getversion());
             (void) sleep(1);            //avoiding avalanche
+            (void) closelog();
             (void) exit(0);
             break;
           default       :
@@ -234,14 +245,14 @@ int phase;
 _Bool proceed;
 
 bindings=(SOCTYP **)0;
-bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.25","2525",2);
-bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",3);
+bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.25","2525",1);
+//bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",3);
 phase=0;
 proceed=true;
 while (proceed==true) {
   switch (phase) {
     case 0      :       //looping forever email receiving processes
-      (void) prc_settitle("emlrec with pid='%06d'",getpid());
+      (void) prc_settitle("Emlrec Daemon");
       break;
     case 1      :       //Opening ALL channels
       if (soc_mullisten(bindings)==false) 
index 7c4a87b610d84afc32c5e30c8c3a2ae795fa5858..6d3809c10139c7fe366096ea0d91d9adf0b66b3f 100644 (file)
@@ -5,6 +5,7 @@
 /*                                                     */
 /********************************************************/
 #include        <dirent.h>
+#include        <errno.h>
 #include        <math.h>
 #include        <signal.h>
 #include        <stdio.h>
@@ -45,13 +46,13 @@ static time_t off_date=(time_t)0;
 static char *get_dropzone()
 
 {
-const char *dropzone="/tmp/"APPNAME"-crash";
-
+char *dropzone;
 char command[100];
 
+dropzone=rou_apppath("/tmp/"APPNAME"-crash");
 (void) snprintf(command,sizeof(command)-2,"mkdir -p %s",dropzone);
 (void) system(command);
-return strdup(dropzone);
+return dropzone;
 }
 /*
 ^L
@@ -323,7 +324,7 @@ while (proceed==true) {
 
       (void) rou_alert(0,"Trying to store core-dump within directory <%s>",
                          crashdir);
-      if ((dirp=opendir(crashdir))!=(DIR *)0) {
+      if ((dirp=opendir("."))!=(DIR *)0) {
         int nument;
         struct dirent *entry;
 
@@ -340,6 +341,9 @@ while (proceed==true) {
           phase=999;          //No allowed to do abort
           }
         }
+      else
+        (void) rou_alert(0,"Unable to open crashdir <%s> PWD=%s (error=<%s>",
+                            crashdir,get_current_dir_name(),strerror(errno));
       (void) free(crashdir);
       break;
     case 3      :               //Ok we can call abort
index c9affa2cda48dae5da57d2682fe53b3d5134f331..867d0dd0589a0cf30ed635abbcf24499ec522732 100644 (file)
@@ -302,13 +302,13 @@ while (proceed==true) {
       break;
     case 2      :       //check if time to retry binding
       if (shutdown(binding->handle,SHUT_RDWR)<0) 
-        (void) rou_alert(0,"%s Unbale to shutdown socket (Bug!?, error=<%s>)",
+        (void) rou_alert(0,"%s Unable To shutdown socket (Bug!?, error=<%s>)",
                             OPEP,strerror(errno));
       
       break;
     case 3      :       //closing the the socket
       if (close(binding->handle)<0) 
-        (void) rou_alert(0,"%s Unbale to close socket (Bug!?, error=<%s>)",
+        (void) rou_alert(0,"%s Unable to close socket (Bug!?, error=<%s>)",
                             OPEP,strerror(errno));
       binding->handle=-1;
       break;