]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Improving the debug function within Makefile
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 25 Mar 2025 22:41:45 +0000 (18:41 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 25 Mar 2025 22:41:45 +0000 (18:41 -0400)
Makefile
app/Makefile
app/emlrcvr.c
app/res/maild.c [moved from app/maild.c with 100% similarity]
lib/modrec.c
lib/subrou.c
vgcore.4405 [new file with mode: 0644]

index c9b0917c315fd851ef50e0a3479732ef6053923a..50f47a21375dd92c86230790ce8815d8becd2cea 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -32,7 +32,7 @@ TESTPORT=     1025
 #--------------------------------------------------------------------
 #testing feed
 FEEDPAR        =                                               \
-               -d 3                                    \
+               -d                                    \
                $(TESTIP)                               \
                $(TESTPORT)                             \
                $(TESTDIR)/$(DATATST)/feed*.tst         \
@@ -42,7 +42,7 @@ tstfeed       :       debug
                @ bin/feeder $(FEEDPAR)
 
 #using gdb
-gdbfeed        :       debug
+dbgfeed        :       debug
                @ gdb --args                            \
                        bin/feeder $(FEEDPAR)
 
@@ -50,17 +50,47 @@ gdbfeed     :       debug
 #starting email receiver
 
 EMLPAR =                                               \
-          -r $(TSTDIR)                                 \
-          -d 8                                         \
+          -r $(TESTDIR)                                        \
+          -d                                         \
           :$(TESTIP):$(TESTPORT)                       \
 
 emlrcvr        :  debug newtest
           @ echo
           @ echo "--------------"
           @ echo "starting $@"
-          @ bin/$@ $(EMLPAR) 
+          @ $(TESTDIR)/$(SBINDIR)/$@ $(EMLPAR) 
           @ echo "--------------"
-               
+
+valrcvr        :  clean debug newtest          #valgrin dest
+          @ echo "emlrec valgrind test"
+          @ valgrind                                   \
+               --leak-check=full                       \
+               --show-leak-kinds=all                   \
+               --track-origins=yes                     \
+               --trace-children=no                     \
+               --track-fds=yes                         \
+                $(TESTDIR)/$(SBINDIR)/emlrcvr          \
+                       -f                              \
+                       $(EMLPAR)
+            
+dbgrcvr        :  clean debug newtest          #using gdb
+          @ gdb --args                                 \
+               $(TESTDIR)/$(SBINDIR)/emlrcvr           \
+               -f                                      \
+               $(EMLPAR) 
+
+#--------------------------------------------------------------------
+#preparing a test area
+newtest        :  deltest
+#--------------------------------------------------------------------
+#test procedure
+#--------------------------------------------------------------------
+tstspf :  clean debug
+          @ shell/test-spf.sh data-tst/spf.tst
+
+#todo a specfic test
+DATA   =  chkaddr.spf.example.com 127.0.1.255
+
 #--------------------------------------------------------------------
 #preparing a test area
 newtest        :  deltest
@@ -68,7 +98,7 @@ newtest       :  deltest
           @ mkdir -p $(TESTDIR)/var/spool/clement/{in,out}-logs
           @ mkdir -p $(TESTDIR)/$(SBINDIR)
           @ cp -a                                              \
-               bin/{chkspf,emlrcvr,maild}                      \
+               bin/{chkspf,emlrcvr}                            \
                $(TESTDIR)/$(SBINDIR)
           @ cp -a                                              \
                $(DATATST)                                      \
@@ -77,21 +107,6 @@ newtest     :  deltest
 deltest        :  
           @ rm -fr $(TSTDIR)
 
-#--------------------------------------------------------------------
-#test procedure
-#--------------------------------------------------------------------
-test   :  clean debug
-          @ shell/test-spf.sh data-tst/spf.tst
-
-#todo a specfic test
-DATA   =  chkaddr.spf.example.com 127.0.1.255
-dbgtst :  debug
-          @ echo "doing chkspf with \"$(DATA)\""
-          @ valgrind                           \
-               --leak-check=full               \
-               --show-leak-kinds=all           \
-               ./bin/chkspf $(DATA)
-
 #--------------------------------------------------------------------
 #Installation procedure
 #--------------------------------------------------------------------
@@ -107,3 +122,7 @@ SUBDIR      =                                                               \
 #definitions globale
 APPNAME        =  MAILLEUR
 #--------------------------------------------------------------------
+#Managing testarea
+SBINDIR = usr/sbin
+CURDIR  = `pwd`
+#===================================================================
index 4b08821676cbc0eb234a9b4b4195855a55def828..ffae3413d0116962dd5c52d6f2a444c2a90d0784 100644 (file)
@@ -23,13 +23,11 @@ clean       :
 EXE=                                                           \
        emlrcvr                                                 \
        feeder                                                  \
-       maild                                                   \
        chkspf                                                  \
 
 SRC=                                                           \
        emlrcvr.c                                               \
        freeder.c                                               \
-       maild.c                                                 \
        chkspf.c                                                \
 
 #--------------------------------------------------------------------
@@ -52,9 +50,6 @@ emlrcvr       :  toremake emlrcvr.o
 feeder :  toremake feeder.o
           @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS)
 
-maild  :  toremake maild.o
-          @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS)
-
 chkspf :  toremake chkspf.o
           @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS)
 
@@ -75,13 +70,6 @@ feeder.o:  feeder.c                          \
           ../lib/subrou.h
 
 
-maild.o        :  maild.c                              \
-          ../lib/uniprc.h                      \
-          ../lib/unisig.h                      \
-          ../lib/unipar.h                      \
-          ../lib/subrou.h                      \
-
-
 toremake:  Makefile $(LIBAI)
           touch toremake
           - rm -f $(EXE) *.o
index c8b93cafb79a054d14bfc1fbde3d518f35d104a1..e02ddd0e8505d8f339a641f8c4bb66d634c77ee1 100644 (file)
@@ -60,6 +60,8 @@ while (proceed==true) {
       (void) sig_trapsignal(true,sig_alrm);
       break;
     case 2      :       //doing main task
+      if (foreground==true)
+        (void) fprintf(stdout,"Running application in foreground\n");
       (void) rec_handlesmtp(params->argc,params->argv);
       break;
     case 3      :       //doing main task
similarity index 100%
rename from app/maild.c
rename to app/res/maild.c
index ba1022d550065e43eb6792dbf74af6f0938797a8..3b1b9b829ddc81ee0c206427f51f9f5b9d631c71 100644 (file)
@@ -106,7 +106,7 @@ return rou_nbrlist(*bindings);
 /*      a remote TCP connection.                        */
 /*                                                     */
 /********************************************************/
-void docontact(SOCPTR *socptr,int pos) 
+static void docontact(SOCPTR *socptr,int pos) 
 
 {
 #define OPEP    "modrec.c:contact"
@@ -189,7 +189,13 @@ while (proceed==true) {
       else
         proceed=false;  //Empty Soc!?!
       break;
-    case 1      :       //check need to dispatch a process
+    case 1      :       //empty phase
+      if (foreground==true) {
+        (void) docontact(socptr,1);
+        phase++;        //no fork
+        }
+      break;
+    case 2      :       //check need to dispatch a process
       for (int i=0;i<iterations;i++) {
         (void)  prc_nozombie();
         if (prc_checkprocess(childs[i])==true)
@@ -212,9 +218,9 @@ while (proceed==true) {
         }
       if ((hangup==true)||(reload==true))
         phase=999;
-      break;
-    case 2      :       //Relax time
       (void) sleep(5);
+      break;
+    case 3      :       //Relax time
       if ((hangup==false)&&(reload==false))
         phase=0;        //lets continue to check childs
       break;
@@ -236,7 +242,7 @@ while (proceed==true) {
 /*      Procedure to start a binding+waiting process    */
 /*                                                     */
 /********************************************************/
-PUBLIC void startwaiter(SOCPTR *socptr,int offset)
+static void startwaiter(SOCPTR *socptr)
 
 {
 #define OPEP    "moderec.c:startwaiter"
@@ -250,6 +256,7 @@ while (proceed==true) {
   //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
   switch (phase) {
     case 0      :       //Opening logs
+      (void) closelog();
       (void) openlog(appname,LOG_NDELAY|LOG_PID,LOG_DAEMON);
       break;
     case 1      :       //binding on channel
@@ -317,28 +324,40 @@ while (proceed==true) {
           childs[i]=(pid_t)0;
         }
       break;
-    case 2      :       //starting/restarting all waiting process
+    case 2      :       //starting one process only
+      if (foreground==true) {
+        (void) startwaiter(bindings[0]);
+        phase++;        //no multiple fork
+        }
+      break;
+    case 3      :       //starting/restarting all waiting process
       for (int i=0;i<nbrbind;i++) {
-        int offset;
-
-        offset=random()%10;
         if (childs[i]!=(pid_t)0)
           continue;
+        (void) fprintf(stdout,"JMPDBG nbrint='%d' i='%d'\n",nbrbind,i);
         childs[i]=fork();
-        if (childs[i]==(pid_t)0) {
-          (void) closelog();
-          (void) startwaiter(bindings[i],offset);
-          (void) exit(0);
+        switch (childs[i]) {
+          case  -1      :       //trouble trouble to fork?
+            (void) rou_alert(0,"%s Unable to fork smtp handler (error=<%s>)",
+                                OPEP,strerror(errno));
+            childs[i]=(pid_t)0;
+            (void) sleep(1);    //Weathering the storm
+            break;
+          case   0      :       //Child process itself
+            (void) startwaiter(bindings[i]);
+            break;
+          default       :       //Main process
+            (void) usleep(10000);
+            break;
           }
-        (void) usleep(10000);   //avoid avalanche
         }
       break;
-    case 3      :       //relax time
+    case 4      :       //relax time
       (void) sleep(5);  //Waiting for signal
       if ((hangup==false)&&(reload==false))
         phase=0;        //Normal process, lets restart
       break;
-    case 4      :       //we got a signal, kill all childs
+    case 5      :       //we got a signal, kill all childs
       (void) prc_killchilds(childs,nbrbind,10);
       break;
     default     :       //SAFE Guard
index d49c119c81d74c81ca4bbcb4c02193eab457acb9..295061669c9af05cc1a5e44fe1d6550db307e0dd 100644 (file)
@@ -21,7 +21,7 @@
 
 //version definition 
 #define VERSION "0.6"
-#define RELEASE "11"
+#define RELEASE "12"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level
diff --git a/vgcore.4405 b/vgcore.4405
new file mode 100644 (file)
index 0000000..af9c107
Binary files /dev/null and b/vgcore.4405 differ