/********************************************************/
#include <errno.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
*/
/********************************************************/
/* */
+/* kleenex procedure */
+/* */
+/********************************************************/
+static void kludge(SOCTYP *binding,int attend)
+
+{
+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);
+ }
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to dispatch sub process */
+/* */
+/********************************************************/
+static void dispatching(SOCTYP *binding)
+
+{
+#define OPEP "modrec.c:dispatching"
+
+int phase;
+_Bool proceed;
+
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //dispatched process still alive
+ (void) prc_nozombie();
+ for (int i=0;i<binding->iteration;i++) {
+ if (binding->childs[i]==(pid_t)0)
+ continue;
+ if (prc_checkprocess(binding->childs[i])==false) {
+ (void) rou_alert(3,"%s, Process '%05d' exited",OPEP,binding->childs[i]);
+ binding->childs[i]=(pid_t)0;
+ }
+ }
+ break;
+ case 1 : //dispating need process
+ for (int i=0;i<binding->iteration;i++) {
+ int attend;
+
+ attend=(random()%60)+10;
+ if (binding->childs[i]!=(pid_t)0)
+ continue;
+ switch(binding->childs[i]=fork()) {
+ case -1 :
+ (void) rou_alert(0,"%s, Unable to start process to "
+ "handle <%s:%s> socket (config?)",
+ OPEP,binding->ip,binding->port);
+ break;
+ case 0 : //the dispatched process
+ (void) kludge(binding,attend);
+ (void) sleep(1); //avoiding avalanche
+ (void) exit(0);
+ break;
+ default :
+ (void) usleep(10000); //wait for next fork
+ break;
+ }
+ }
+ break;
+ default : //SAFE Guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to active child process if necessary */
+/* */
+/********************************************************/
+static void activate(SOCTYP **bindings)
+
+{
+#define OPEP "modrec.c:activate"
+
+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 dispatch a process
+ while (*bindings!=(SOCTYP *)0) {
+ (void) dispatching(*bindings);
+ bindings++;
+ }
+ break;
+ default : //SAFE Guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
/* Waiting and handling smtp request */
/* */
/********************************************************/
(void) rou_alert(0,"%s, Unable to open ALL socket (config?)",OPEP);
break;
case 2 : //Terminating all remaining process
- (void) fprintf(stderr,"JMPDBG wait 5 sec\n");
+ (void) activate(bindings);
(void) sleep(5);
- (void) fprintf(stderr,"JMPDBG wleep completed\n");
+ if ((hangup==false)&&(reload==false))
+ phase--; //normal cycle, lets proceed to actvate again
break;
case 3 : //closing all socket openend
(void) soc_mulclose(bindings);