]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starting to have a "JMPDBG" signon
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 14 Jul 2024 19:26:20 +0000 (15:26 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 14 Jul 2024 19:26:20 +0000 (15:26 -0400)
lib/gestcp.c
lib/gestcp.h
lib/modrec.c
lib/unisoc.c
lib/unisoc.h

index 9db35fec2c41ff01664bee52f749613eaa662e7e..39fb9d9ced529d73b264bd0b8d18208234ffd4dd 100644 (file)
 /*                                                     */
 /********************************************************/
 #include        <sys/wait.h>
+#include        <sys/socket.h>
+#include        <errno.h>
+#include        <fcntl.h>
 #include        <stdlib.h>
 #include        <stdio.h>
 #include        <string.h>
+#include        <unistd.h>
 
 #include        "subrou.h"
+#include        "unisig.h"
+#include        "uniprc.h"
 #include        "gestcp.h"
 
 static  _Bool modopen;          //boolean module open/close
 /*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to get the handle related to a remote */
+/*     contact.                                        */
+/*                                                      */
+/********************************************************/
+static int getcontact(SOCTYP *binding)
+
+{
+#define OPEP    "gestcp.c:getcontact"
+int contact;
+socklen_t taille;
+struct sockaddr addr;
+
+contact=-1;
+taille=sizeof(addr);
+if ((contact=accept(binding->handle,&addr,&taille))<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       */
+      break;
+    default             :
+      (void) rou_alert(0,"%s Unexpected error on IP/PORT <%s/%s> errno=<%s>",
+                         OPEP,binding->ip,binding->port,strerror(errno));
+      break;
+    }
+  }
+else {
+  int flags;
+
+  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));
+  }
+return contact;
+#undef  OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/*                                                     */
+/*      Procedure to wait for an incoming connection    */
+/*      from a remote client.                           */
+/*      return a socket handle or -1 if trouble.        */
+/*                                                     */
+/********************************************************/
+static int waitlisten(SOCTYP *binding)
+
+{
+#define OPEP    "gesttcp.c:waitlisten"
+
+int contact;
+int phase;
+_Bool proceed;
+
+contact=-1;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //checking if the point is ready; 
+      if (binding==(SOCTYP *)0) {
+        (void) rou_alert(0,"%s binding pointer is NULL (Bug!?)",OPEP);
+        phase=999;      //not going further
+        }
+      break;
+    case 1      :       //checking if the handle is properly set
+      if (binding->handle<0) {
+        (void) rou_alert(0,"%s trouble with handle (handle value ='%d', Bug!?)",
+                            OPEP,binding->handle);
+        phase=999;      //not going further
+        }
+      break;
+    case 2      :       //listening on the handle
+      fd_set reading;
+      struct timeval relax;
+      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)) {
+        case     -1     :     //got a wrong return
+          switch (errno) {
+            case EINTR  :       //Received a signal, get out! fast!
+              phase=999;
+              break;
+            default     :       //Unexpected error?
+              (void) rou_core_dump("%, Unexpected select status (error=<%s>)",
+                                    OPEP,strerror(errno));
+              break;            //never reached
+            }
+          break;
+        case      0     :       //normal time out.
+          phase--;              //lets continue to wait for incoming
+          if (prc_checkprocess(getppid())==false) {
+            (void) rou_alert(0,"%s parent process missing (daemon restart?)",
+                               OPEP);
+            phase=999;          //exiting
+            }
+          if ((hangup==true)||(reload==true))
+            phase=999;          //exiting
+          break;
+        default         :       //we got a contact
+          if ((contact=getcontact(binding))<0) 
+            phase--;            //not quick enough, lets continue to wait
+          break;
+        }
+      break;
+    default     :       //SAFE Guard
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return contact;
+#undef  OPEP
+}
+/*
 ^L
 */
 /********************************************************/
@@ -31,7 +164,8 @@ CONTYP *contact;
 int phase;
 _Bool proceed;
 
-contact=(CONTYP *)0;
+contact=calloc(1,sizeof(CONTYP));
+contact->binding=binding;
 phase=0;
 proceed=true;
 while (proceed==true) {
@@ -43,6 +177,15 @@ while (proceed==true) {
         }
       break;
     case 1      :       //waiting from contact
+      if ((contact->channel=waitlisten(binding))<0) {
+        (void) rou_alert(0,"%s Unable to open contact",OPEP);
+        (void) free(contact);
+        contact=(CONTYP *)0;
+        phase=999;      //no contact 
+        }
+      break;
+    case 2      :       //check is contactis ok
+      (void) dprintf(contact->channel,"JMPDBG Bingo!\n");
       break;
     default     :       //SAFE guard
       break;
@@ -90,8 +233,12 @@ if (mode!=modopen) {
     case true     :
       (void) rou_modesubrou(mode);
       (void) soc_modeunisoc(mode);
+      (void) sig_modeunisig(mode);
+      (void) prc_modeuniprc(mode);
       break;
     case false    :
+      (void) sig_modeunisig(mode);
+      (void) prc_modeuniprc(mode);
       (void) soc_modeunisoc(mode);
       (void) rou_modesubrou(mode);
       break;
index 0cc20ef593dc83f250a134d745430386592ad62d..55c3cb560fa4dd3a48a3a9ded34a60cc306b4461 100644 (file)
@@ -12,7 +12,8 @@
 #include        "unisoc.h"
 
 typedef struct  {
-        void    *ptr;   //JMPDBG
+        int channel;    //xchang channle handle
+        SOCTYP *binding;//extablised contact context
         }CONTYP;
 
 //wait for an incoming contact
index 1b3c535dd8d334b8d20463f30c8774329a0bcfde..ad664fa2f1a8223494e8e64ac3c35d4ed543881e 100644 (file)
@@ -226,8 +226,8 @@ int phase;
 _Bool proceed;
 
 bindings=(SOCTYP **)0;
-bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.25","2525",10);
-bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",10);
+bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.25","2525",2);
+bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",3);
 phase=0;
 proceed=true;
 while (proceed==true) {
index 4b5c6fb05531f6f8c236def3fed808e482f2cf21..c9affa2cda48dae5da57d2682fe53b3d5134f331 100644 (file)
@@ -33,52 +33,6 @@ static  _Bool modopen;        //module open/close status
 */
 /********************************************************/
 /*                                                      */
-/*     Procedure to get the handle related to a remote */
-/*     contact.                                        */
-/*                                                      */
-/********************************************************/
-static int getcontact(SOCTYP *binding)
-
-{
-#define OPEP    "unisoc.c:getcontac"
-int contact;
-socklen_t taille;
-struct sockaddr addr;
-
-contact=-1;
-taille=sizeof(addr);
-if ((contact=accept(binding->handle,&addr,&taille))<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       */
-      break;
-    default             :
-      (void) rou_alert(0,"%s Unexpected error on IP/PORT <%s/%s> errno=<%s>",
-                         OPEP,binding->ip,binding->port,strerror(errno));
-      break;
-    }
-  }
-else {
-  int flags;
-
-  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));
-  }
-return contact;
-#undef  OPEP
-}
-/*
-\f
-*/
-/********************************************************/
-/*                                                      */
 /*     Procedure to free memory used by a              */
 /*     binding info.                                   */
 /*                                                     */
@@ -472,80 +426,6 @@ while (proceed==true) {
 ^L
 */
 /********************************************************/
-/*                                                     */
-/*      Procedure to wait for an incoming connecion     */
-/*      from a remote client.                           */
-/*      return a socket handle or -1 if trouble.        */
-/*                                                     */
-/********************************************************/
-PUBLIC int soc_listen(SOCTYP *binding)
-
-{
-#define OPEP    "unisoc.c:soc_listen"
-
-int contact;
-int phase;
-_Bool proceed;
-
-contact=-2;
-phase=0;
-proceed=true;
-while (proceed==true) {
-  switch (phase) {
-    case 0      :       //checking if the point is ready; 
-      if (binding==(SOCTYP *)0) {
-        (void) rou_alert(0,"%s binding pointer is NULL (Bug!?)",OPEP);
-        phase=999;      //not going further
-        }
-      break;
-    case 1      :       //checking if the handle is properly set
-      if (binding->handle<0) {
-        (void) rou_alert(0,"%s trouble with handle (handle value ='%d', Bug!?)",
-                            OPEP,binding->handle);
-        phase=999;      //not going further
-        }
-      break;
-    case 2      :       //listening on the handle
-      fd_set reading;
-      struct timeval relax;
-      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)) {
-        case     -1     :     //got a wrong return
-          switch (errno) {
-            case EINTR  :       //Received a signal, get out! fast!
-              phase=999;
-              break;
-            default     :       //Unexpected error?
-              (void) rou_core_dump("%, Unexpected select status (error=<%s>)",
-                                    OPEP,strerror(errno));
-              break;            //never reached
-            }
-          break;
-        case      0     :       //normal time out.
-          phase--;              //lets continue to wait for incoming
-          break;
-        default         :       //we got a contact
-          if ((contact=getcontact(binding))<0) 
-            phase--;            //not quick enough, lets continue to wait
-          break;
-        }
-      break;
-    default     :       //SAFE Guard
-      proceed=false;
-      break;
-    }
-  phase++;
-  }
-return contact;
-#undef  OPEP
-}
-/*
-^L
-*/
-/********************************************************/
 /*                                                      */
 /*     Procedure to "open/close" module and do         */
 /*      homework purpose                                */
index 4f228fc6a2e66c7287266f4fd92dc5e3d75aa082..bb4213585158aa7e27629d9ff8b455699f49993b 100644 (file)
@@ -51,9 +51,6 @@ extern int soc_mullisten(SOCTYP **bindings);
 //procedure to close all sockets
 extern void soc_mulclose(SOCTYP **bindings);
 
-//procedure to wait for a connection from a remote client
-extern int soc_listen(SOCTYP *binding);
-
 //homework to be done before starting/stopping module.
 extern int soc_modeunisoc(_Bool mode);