]> SAFE projects GIT repository - jmp/mailleur/commitdiff
This phase is an echec some memory is over written tag-0.3
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 17 Jul 2024 07:43:18 +0000 (03:43 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 17 Jul 2024 07:43:18 +0000 (03:43 -0400)
lib/gestcp.c
lib/modrec.c
lib/subrou.c
lib/unisoc.c
lib/unisoc.h

index 6594a63e1c61a610d044099d9964bebfdd1d656f..2d44d279c91cbe4b069337b7e9ee47433be310c6 100644 (file)
@@ -56,6 +56,7 @@ if (contact<0) {
 else {
   int flags;
 
+  (void) rou_alert(0,"JMPDBG binding->handle '%d'",binding->handle);
   if ((flags=fcntl(contact,F_GETFL,0))<0)
     (void) rou_core_dump("%s Unable to get socket descripteur (error='%s')",
                           OPEP,strerror(errno));
@@ -105,6 +106,10 @@ while (proceed==true) {
         }
       break;
     case 2      :       //listening on the handle
+      (void) soc_setlinger(binding->handle);
+      (void) soc_getlinger(binding->handle,"waitlisten");
+      break;
+    case 3      :       //listening on the handle
       fd_set reading;
       struct timeval relax;
       int status;
@@ -118,7 +123,8 @@ while (proceed==true) {
         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!");
+              (void) fprintf(stderr,"JMPDBG pid='%05d select received a signal!\n",
+                                     getpid());
               phase=999;
               break;
             default     :       //Unexpected error?
@@ -157,7 +163,7 @@ while (proceed==true) {
       break;
     }
   phase++;
-  (void) rou_alert(0,"JMPDB waitlisten contat='%d' phase='%d'",contact,phase);
+  //(void) rou_alert(0,"JMPDB waitlisten contat='%d' phase='%d'",contact,phase);
   }
 return contact;
 #undef  OPEP
@@ -181,6 +187,7 @@ va_list args;
 sent=0;
 va_start(args,format);
 sent=vdprintf(contact->channel,format,args);
+//(void) fdatasync(contact->channel);
 va_end(args);
 return sent;
 }
@@ -229,7 +236,7 @@ while (proceed==true) {
       proceed=false;
       break;
     }
-  (void) rou_alert(0,"JMPDB tcp_getcontact contat='%p' phase='%d'",contact,phase);
+  //(void) rou_alert(0,"JMPDBG tcp_getcontact contat='%p' phase='%d'",contact,phase);
   phase++;
   }
 return contact;
index 4739ff13cf9d604e6da7920f4d83c4205258412a..7e0420ef11acca18cb471efcb44f16db84c781d3 100644 (file)
@@ -54,17 +54,19 @@ while (proceed==true) {
     case 2      :       //do contact
       for (int i=0;i<TESTL;i++) {
         int sent;
+        char tmpbuf[100];
 
-        (void) sleep(2);
         if ((reload==true)||(hangup==true))
           break;
         if (prc_checkprocess(getppid())==false)
           break;
-        sent=tcp_fprintf(contact,"JMPDBG pid=%d iter=%d/%d\n",getpid(),i,TESTL);
+        sent=tcp_fprintf(contact,"Remote pid=%d iter=%d/%d\n",getpid(),i,TESTL);
         if (sent<0) {
           (void) rou_alert(0,"JMPDBG tcp_fprintf error <%s>",strerror(errno));
           break;
           }
+        (void) read(contact->channel,tmpbuf,sizeof(tmpbuf));
+        (void) sleep(2);
         }
       break;
     case 3      :       //close contact
@@ -113,6 +115,7 @@ while (proceed==true) {
       for (int i=0;i<binding->iteration;i++) {
         if (binding->childs[i]!=(pid_t)0)
           continue;
+        (void) soc_getlinger(binding->handle,"before fork");
         switch(binding->childs[i]=fork()) {
           case -1       :
             (void) rou_alert(0,"%s, Unable to start process to "
@@ -121,10 +124,11 @@ while (proceed==true) {
             break;
           case 0        :               //the dispatched process
             (void) closelog();
-            (void) openlog("Contact",LOG_PID,LOG_DAEMON);
+            (void) openlog("Contact",LOG_NDELAY|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       :
@@ -169,6 +173,7 @@ while (proceed==true) {
       break;
     case 1      :       //check need to dispatch a process
       while (*bindings!=(SOCTYP *)0) {
+        (void) soc_getlinger((*bindings)->handle,"before displatching");
         (void) dispatching(*bindings);
         bindings++;
         }
@@ -268,8 +273,8 @@ int phase;
 _Bool proceed;
 
 bindings=(SOCTYP **)0;
-bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.25","2525",1);
-//bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",3);
+bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.25","2525",2);
+//bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",1);
 phase=0;
 proceed=true;
 while (proceed==true) {
index 6d3809c10139c7fe366096ea0d91d9adf0b66b3f..fb93f4aa6587a5fc8152ce2fc340e056a70bc144 100644 (file)
@@ -394,7 +394,7 @@ if (mode!=modopen) {
         (void) srand((int)(M_PI*100000000));
       if (appname==(char *)0)
         appname=strdup(APPNAME);
-      (void) openlog(appname,LOG_PID,LOG_DAEMON);
+      (void) openlog(appname,LOG_NDELAY|LOG_PID,LOG_DAEMON);
       (void) rou_alert(0,"Starting: %s-%s",appname,rou_getversion());
       break;
     case false    :
index 6070fc2c8964bb66c3674177d26d3c4cef631a46..0b4d032f152c77a0d725e63808455788df675bba 100644 (file)
@@ -80,6 +80,12 @@ flags=0;
 phase=0;
 proceed=true;
 while (proceed==true) {
+  if (handle>=0) {
+    char bigre[50];
+
+    (void) sprintf(bigre,"Phase='%02d'",phase);
+    (void) soc_getlinger(handle,bigre);
+    }
   switch (phase) {
     case 0     :       //lets get a socket
       if ((handle=socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol))<0) {
@@ -108,11 +114,12 @@ while (proceed==true) {
       if (setsockopt(handle,SOL_SOCKET,SO_LINGER,&slg,sizeof(slg))<0) {
         (void) rou_alert(0,"%s Unable to set socket option "
                            "SO_LINGER for <%s> (error='%s')",
-                         OPEP,ai->ai_canonname,strerror(errno));
+                         OPEP,strerror(errno));
         phase=999;     //trouble cleanup phase
        }
       break;
     case 4     :       /*getting socket option */
+      (void) soc_getlinger(handle,"binhandle");
       if ((flags=fcntl(handle,F_GETFL,0))<0) {
         (void) rou_alert(0,"%s Unable to set socket descriptor "
                            "for <%s> (error='%s')",
@@ -129,6 +136,7 @@ while (proceed==true) {
        }
       break;
     case 6     :       //getting socket option
+      (void) soc_getlinger(handle,"before bind");
       if (bind(handle,ai->ai_addr,ai->ai_addrlen)<0) {
        (void) rou_alert(0,"%s Unable to bind on IP/port <%s/%s> (error='%s')",
                           OPEP,ai->ai_canonname,binding->port,strerror(errno));
@@ -136,6 +144,7 @@ while (proceed==true) {
        }
       break;
     case 7     :       /*preparing listen      */
+      (void) soc_getlinger(handle,"after bind");
       if (listen(handle,5)<0) {
        (void) rou_alert(0,"%s Unable to listen on IP/port <%s/%s> (error='%s')",
                           OPEP,ai->ai_canonname,binding->port,strerror(errno));
@@ -143,6 +152,7 @@ while (proceed==true) {
        }
       break;
     case 8     :       /*reporting listen      */
+      (void) soc_getlinger(handle,"after listen");
       (void) rou_alert(1,"Now Listening on IP/PORT <%s/%s>",
                           ai->ai_canonname,binding->port);
       proceed=false;    //evrything fine no need to go further
@@ -157,6 +167,7 @@ while (proceed==true) {
   }
 (void) free(buf);
 (void) rou_alert(0,"JMPDBG got handle channel='%d'",handle);
+(void) soc_getlinger(handle,"exiting from bindhandle");
 return handle;
 #undef OPEP
 }
@@ -208,6 +219,44 @@ bindings=(SOCTYP **)rou_addlist((void **)bindings,(void *)bininf);
 return bindings;
 }
 /*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Procedure to set set the linger mode on the     */
+/*      socket device.                                  */
+/*      return -1 if trouble.                           */
+/*                                                     */
+/********************************************************/
+PUBLIC int soc_setlinger(int socket)
+
+{
+#define OPEP    "unisoc.c:soc_setlinger"
+#define BFSZ    30
+
+int status;
+int flags;
+char *buf;
+struct linger slg;
+
+status=-1;
+slg.l_onoff=true;
+slg.l_linger=0;
+buf=calloc(BFSZ,sizeof(char));
+flags=fcntl(socket,F_GETFL,0);
+(void) fcntl(socket,F_SETFL,flags|O_NONBLOCK|O_ASYNC);
+(void) setsockopt(socket,SOL_SOCKET,SO_REUSEADDR,buf,BFSZ*sizeof(char));
+(void) setsockopt(socket,SOL_SOCKET,SO_REUSEPORT,buf,BFSZ*sizeof(char));
+status=setsockopt(socket,SOL_SOCKET,SO_LINGER,&slg,sizeof(slg));
+if (status<0)
+  (void) rou_alert(0,"%s Unable to set socket option "
+                     "SO_LINGER for <%s> (error='%s' bug?)",
+                     OPEP,strerror(errno));
+(void) free(buf);
+return status;
+#undef  OPEP
+}
+/*
 ^L
 */
 /********************************************************/
@@ -260,7 +309,8 @@ while (proceed==true) {
       break;
     case 3      :       //binding socket
       soc=bindhandle(tobind,binding);
-      (void) freeaddrinfo(tobind);
+      (void) soc_getlinger(soc,"result from bindhandle");
+      //(void) freeaddrinfo(tobind); JMPDBG ALARM
       break;
     default     :       //SAFE Guard
       proceed=false;
@@ -268,6 +318,7 @@ while (proceed==true) {
     }
   phase++;
   }
+(void) soc_getlinger(soc,"exiting from soc_onelisten");
 return soc;
 #undef  OPEP
 }
@@ -366,9 +417,16 @@ while (proceed==true) {
     case 2      :       //binding on all interface
       ready=true;
       while (*bindings!=(SOCTYP *)0) {
-        (*bindings)->handle=soc_onelisten(*bindings);
+        int soc;
+
+        soc=soc_onelisten(*bindings);
+        (void) soc_getlinger(soc,"after onelisten");
+        (*bindings)->handle=soc;
+        (void) soc_getlinger((*bindings)->handle,"after binding onelisten");
         if ((*bindings)->handle<0)
           ready=false;  //Trouble?
+        else
+          (void) soc_getlinger((*bindings)->handle,"mullisten");
         bindings++;
         }
       break;
@@ -424,6 +482,19 @@ while (proceed==true) {
   }
 #undef  OPEP
 }
+//temporary JMPDBG
+void soc_getlinger(int socket,char *inf)
+
+{
+socklen_t len;
+struct linger slg;
+
+if (getsockopt(socket,SOL_SOCKET,SO_LINGER,&slg,&len)<0) 
+  (void) rou_alert(0,"JMPDBG LISTEN trouble (error='%s')",strerror(errno));
+(void) rou_alert(0,"JMPDBG [%s] get socket='%d' linger.onoff='%d', "
+                   "timeout linger='%d'",
+                   inf,socket,slg.l_onoff,slg.l_linger);
+}
 /*
 ^L
 */
index bb4213585158aa7e27629d9ff8b455699f49993b..e9e9fa2f26eb9ffb463511c08aac3df944210410 100644 (file)
@@ -38,6 +38,9 @@ extern SOCTYP **soc_freebindinf(SOCTYP **bindref);
 extern SOCTYP **soc_mkbindinf(SOCTYP **bindings,PROTYP proto,
                               const char *ip,const char *port,int iteration);
 
+//Procedure to set the linger value on the socket handle
+extern int soc_setlinger(int socket);
+
 //procedure to open ONE socket and return handle to socket
 extern int soc_onelisten(SOCTYP *binding);
 
@@ -51,6 +54,9 @@ extern int soc_mullisten(SOCTYP **bindings);
 //procedure to close all sockets
 extern void soc_mulclose(SOCTYP **bindings);
 
+//temporary JMPDBG
+extern void soc_getlinger(int socket,char *inf);
+
 //homework to be done before starting/stopping module.
 extern int soc_modeunisoc(_Bool mode);