]> SAFE projects GIT repository - jmp/mailleur/commitdiff
modrec.c kludge function is exit properly
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 13 Jul 2024 07:43:43 +0000 (03:43 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 13 Jul 2024 07:43:43 +0000 (03:43 -0400)
lib/modrec.c

index 1a3b3adb23e9d6ae2a080da5e1aaff0c15502baf..17ce74202b30f5ada80562d358e645b408d97e5d 100644 (file)
@@ -32,6 +32,10 @@ for (int i=0;i<attend;i++) {
   (void) prc_settitle("Kluge for %d seconds, ip:port=<%s:%s>",
                      attend-i,binding->ip,binding->port);
   (void) sleep(1);
+  if ((hangup==true)||(reload==true)){
+    (void) rou_alert(0,"JMPDBG process terminated");
+    break;
+    }
   }
 }
 /*
@@ -102,7 +106,7 @@ while (proceed==true) {
 */
 /********************************************************/
 /*                                                     */
-/*      Procedure to active child process if necessary  */
+/*      Procedure to activate child process if necessary*/
 /*                                                     */
 /********************************************************/
 static void activate(SOCTYP **bindings)
@@ -142,6 +146,55 @@ while (proceed==true) {
 */
 /********************************************************/
 /*                                                     */
+/*      Procedure to kill all child process if necessary*/
+/*                                                     */
+/********************************************************/
+static void release(SOCTYP **bindings)
+
+{
+#define OPEP    "modrec.c:release"
+
+int phase;
+_Bool proceed;
+
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //making sur the list is defined
+       if (bindings==(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)
+            continue;
+          if (prc_checkprocess((*bindings)->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;
+            }
+          }
+        bindings++;
+        }
+      break;
+    default     :       //SAFE Guard
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
 /*      Waiting and handling smtp request               */
 /*                                                     */
 /********************************************************/
@@ -174,7 +227,8 @@ while (proceed==true) {
       if ((hangup==false)&&(reload==false))
         phase--;        //normal cycle, lets proceed to actvate again
       break;
-    case 3      :       //closing all socket openend
+    case 3      :       //closing all socket currently opened
+      (void) release(bindings);
       (void) soc_mulclose(bindings);
       break;
     default     :       //SAFE Guard