]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Proble with TIME_WAIT still remain
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 15 Jul 2024 19:26:09 +0000 (15:26 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 15 Jul 2024 19:26:09 +0000 (15:26 -0400)
lib/gestcp.c
lib/gestcp.h
lib/modrec.c
lib/unisoc.c

index 89475e47855945727a70adfbb8264ebf9e99fcd2..6594a63e1c61a610d044099d9964bebfdd1d656f 100644 (file)
@@ -38,8 +38,6 @@ struct sockaddr addr;
 
 taille=sizeof(addr);
 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         :
@@ -60,11 +58,12 @@ else {
 
   if ((flags=fcntl(contact,F_GETFL,0))<0)
     (void) rou_core_dump("%s Unable to get socket descripteur (error='%s')",
-                         OPEP,strerror(errno));
-   if ((flags=fcntl(contact,F_SETFL,flags|O_NONBLOCK|O_ASYNC))<0)
-     (void) rou_core_dump("%s Unable to set socket descripteur (error='%s')",
+                          OPEP,strerror(errno));
+  if ((flags=fcntl(contact,F_SETFL,flags|O_NONBLOCK|O_ASYNC))<0)
+    (void) rou_core_dump("%s Unable to set socket descripteur (error='%s')",
                           OPEP,strerror(errno));
   }
+(void) rou_alert(0,"JMPDBG got contact channel='%d'",contact);
 return contact;
 #undef  OPEP
 }
@@ -115,7 +114,6 @@ while (proceed==true) {
       relax.tv_sec=1;   //1 sec relax time
       relax.tv_usec=0;
       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) {
@@ -153,14 +151,13 @@ while (proceed==true) {
             }
           break;
         }
-      (void) rou_alert(0,"JMPDBG exiting from select phase='%d' contact='%d'",
-                          phase,contact);
       break;
     default     :       //SAFE Guard
       proceed=false;
       break;
     }
   phase++;
+  (void) rou_alert(0,"JMPDB waitlisten contat='%d' phase='%d'",contact,phase);
   }
 return contact;
 #undef  OPEP
@@ -170,6 +167,28 @@ return contact;
 */
 /********************************************************/
 /*                                                      */
+/*     Procedure to send data to a tcp socket.         */
+/*      return the number of character transmitted, is  */
+/*      unable to send char return -1;                  */
+/*                                                      */
+/********************************************************/
+PUBLIC int tcp_fprintf(CONTYP *contact,const char *format,...)
+
+{
+int sent;
+va_list args;
+
+sent=0;
+va_start(args,format);
+sent=vdprintf(contact->channel,format,args);
+va_end(args);
+return sent;
+}
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
 /*     Procedure to wait for a remote client.          */
 /*      return all reference to the established contact.*/
 /*                                                      */
@@ -210,6 +229,7 @@ while (proceed==true) {
       proceed=false;
       break;
     }
+  (void) rou_alert(0,"JMPDB tcp_getcontact contat='%p' phase='%d'",contact,phase);
   phase++;
   }
 return contact;
@@ -243,6 +263,7 @@ while (proceed==true) {
         }
       break;
     case 1      :       //waiting from contact
+      (void) rou_alert(0,"JMPDBG shutdown contact channel='%d'",contact->channel);
       if (shutdown(contact->channel,SHUT_RDWR)<0) {
         switch (errno) {
           case ENOTCONN :       //already disconnect by other side!
index 55c3cb560fa4dd3a48a3a9ded34a60cc306b4461..9a1fd364dab0c7267fdb1eb9392f25ce449bf202 100644 (file)
@@ -16,6 +16,12 @@ typedef struct  {
         SOCTYP *binding;//extablised contact context
         }CONTYP;
 
+//Transmit formated data to the contact channel
+extern int tcp_fprintf(CONTYP *contact,const char *format,...);
+
+//Wait for an input coming from the contact channel
+extern int *tcp_fscanf(CONTYP *contact,const char *format,...);
+
 //wait for an incoming contact
 extern CONTYP *tcp_getcontact(SOCTYP *binding);
 
index 625b7f94a31dd7fd5f578febc5524537484f46df..4739ff13cf9d604e6da7920f4d83c4205258412a 100644 (file)
@@ -53,14 +53,18 @@ while (proceed==true) {
       break;
     case 2      :       //do contact
       for (int i=0;i<TESTL;i++) {
+        int sent;
+
         (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,TESTL);
-        
+        sent=tcp_fprintf(contact,"JMPDBG pid=%d iter=%d/%d\n",getpid(),i,TESTL);
+        if (sent<0) {
+          (void) rou_alert(0,"JMPDBG tcp_fprintf error <%s>",strerror(errno));
+          break;
+          }
         }
       break;
     case 3      :       //close contact
@@ -121,7 +125,6 @@ while (proceed==true) {
             (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       :
@@ -191,32 +194,52 @@ static void release(SOCTYP **bindings)
 {
 #define OPEP    "modrec.c:release"
 
+SOCTYP **ptr;
 int phase;
 _Bool proceed;
 
+ptr=bindings;
 phase=0;
 proceed=true;
 while (proceed==true) {
   switch (phase) {
     case 0      :       //making sur the list is defined
-       if (bindings==(SOCTYP **)0) {
+       if (ptr==(SOCTYP **)0) {
         (void) rou_alert(0,"%s bindings list pointer is NULL (Bug!?)",OPEP);
         phase=999;      //not going further
         }
       break;
     case 1      :       //check need to kill a dispatched process
-      while (*bindings!=(SOCTYP *)0) {
-        for (int i=0;i<(*bindings)->iteration;i++) {
-          if ((*bindings)->childs[i]==(pid_t)0)
+      ptr=bindings;
+      while (*ptr!=(SOCTYP *)0) {
+        for (int i=0;i<(*ptr)->iteration;i++) {
+          if ((*ptr)->childs[i]==(pid_t)0)
             continue;
-          if (prc_checkprocess((*bindings)->childs[i])==true) {
+          if (prc_checkprocess((*ptr)->childs[i])==true) {
             (void) rou_alert(0,"JMPDBG sending a SIGTERM process to '%d'",
-                                (*bindings)->childs[i]);
-            (void) kill((*bindings)->childs[i],SIGTERM);
-            (*bindings)->childs[i]=(pid_t)0;
+                                (*ptr)->childs[i]);
+            (void) kill((*ptr)->childs[i],SIGTERM);
+            (void) usleep(1000);
             }
           }
-        bindings++;
+        ptr++;
+        }
+      break;
+    case 2      :       //checking if ALL process are now terminated
+      sleep(1);
+      (void) prc_nozombie();
+      ptr=bindings;
+      while (*ptr!=(SOCTYP *)0) {
+        for (int i=0;i<(*ptr)->iteration;i++) {
+          if ((*ptr)->childs[i]==(pid_t)0)
+            continue;
+          if (prc_checkprocess((*ptr)->childs[i])==false) {
+            (*ptr)->childs[i]=(pid_t)0;
+            continue;
+            }
+          phase=0;      //some process still remain killing again?
+          }
+        ptr++;
         }
       break;
     default     :       //SAFE Guard
@@ -264,8 +287,10 @@ while (proceed==true) {
       if ((hangup==false)&&(reload==false))
         phase--;        //normal cycle, lets proceed to actvate again
       break;
-    case 3      :       //closing all socket currently opened
+    case 3      :       //release current binding
       (void) release(bindings);
+      break;
+    case 4      :       //closing all socket currently opened
       (void) soc_mulclose(bindings);
       break;
     default     :       //SAFE Guard
index 867d0dd0589a0cf30ed635abbcf24499ec522732..6070fc2c8964bb66c3674177d26d3c4cef631a46 100644 (file)
@@ -73,7 +73,8 @@ int phase;
 _Bool proceed;
 
 handle=-1;
-(void) memset(&slg,'\000',sizeof(struct linger));
+slg.l_onoff=true;
+slg.l_linger=0; /*0 sec timeout on close*/
 buf=calloc(BFSZ,sizeof(char));
 flags=0;
 phase=0;
@@ -103,7 +104,7 @@ while (proceed==true) {
         phase=999;     //trouble cleanup phase
         }
       break;
-    case 3     :       //SO_LINGER allow  Connection reset by peer"
+    case 3     :       //SO_LINGER allow  Connection reset by peer
       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')",
@@ -155,6 +156,7 @@ while (proceed==true) {
   phase++;
   }
 (void) free(buf);
+(void) rou_alert(0,"JMPDBG got handle channel='%d'",handle);
 return handle;
 #undef OPEP
 }