From 56bb88b443036c2f4e4ca891a51db38da0e07954 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Mon, 15 Jul 2024 09:36:46 -0400 Subject: [PATCH] missing emlrec detection contact subprocess working fine --- lib/gestcp.c | 31 +++++++++++++++++++++++++------ lib/modrec.c | 33 ++++++++++++++++++++++----------- lib/subrou.c | 12 ++++++++---- lib/unisoc.c | 4 ++-- 4 files changed, 57 insertions(+), 23 deletions(-) diff --git a/lib/gestcp.c b/lib/gestcp.c index 20cbe2e..e0107fa 100644 --- a/lib/gestcp.c +++ b/lib/gestcp.c @@ -36,15 +36,18 @@ int contact; socklen_t taille; struct sockaddr addr; -contact=-1; taille=sizeof(addr); -if ((contact=accept(binding->handle,&addr,&taille))<0) { +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 : /*well process not quick enough the handle was already */ /*accepted by another clement???. */ break; case EINVAL : /*no socket avail anymore */ + contact--; //There is NO main process anymore break; default : (void) rou_alert(0,"%s Unexpected error on IP/PORT <%s/%s> errno=<%s>", @@ -105,18 +108,23 @@ while (proceed==true) { case 2 : //listening on the handle fd_set reading; struct timeval relax; + int status; + 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)) { + 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) { case EINTR : //Received a signal, get out! fast! + (void) rou_alert(0,"JMPDBG select received a signal!"); phase=999; break; default : //Unexpected error? - (void) rou_core_dump("%, Unexpected select status (error=<%s>)", + (void) rou_core_dump("%s, Unexpected select status (error=<%s>)", OPEP,strerror(errno)); break; //never reached } @@ -132,10 +140,21 @@ while (proceed==true) { phase=999; //exiting break; default : //we got a contact - if ((contact=getcontact(binding))<0) - phase--; //not quick enough, lets continue to wait + contact=getcontact(binding); + switch (contact) { + case -2 : //no handle anymore exiting + break; + case -1 : //not quick enough + phase--; //let continue to wait + (void) sleep(1); + break; + default : //we have a contact + break; + } break; } + (void) rou_alert(0,"JMPDBG exiting from select phase='%d' contact='%d'", + phase,contact); break; default : //SAFE Guard proceed=false; diff --git a/lib/modrec.c b/lib/modrec.c index cca6036..625b7f9 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "subrou.h" @@ -27,10 +28,11 @@ static _Bool modopen; //boolean module open/close /* a remote TCP connection. */ /* */ /********************************************************/ -void contact(SOCTYP *binding) +void docontact(SOCTYP *binding) { #define OPEP "modrec.c:contact" +#define TESTL 4 CONTYP *contact; int phase; @@ -41,22 +43,27 @@ phase=0; proceed=true; while (proceed==true) { switch (phase) { - case 0 : //do we have a contact + case 0 : //display waiting contact + (void) prc_settitle("Waiting contact on %s:%s",binding->ip,binding->port); + break; + case 1 : //do we have a contact if ((contact=tcp_getcontact(binding))==(CONTYP *)0) { phase=999; //no going further } break; - case 1 : //do contact - for (int i=0;i<20;i++) { - (void) sleep(3); + case 2 : //do contact + for (int i=0;ichannel,"JMPDBG pid=%d iteration=%d/%d\n", - getpid(),i,20); + getpid(),i,TESTL); } break; - case 2 : //close contact + case 3 : //close contact contact=tcp_dropcontact(contact); break; default : //SAFE guard @@ -109,8 +116,12 @@ while (proceed==true) { OPEP,binding->ip,binding->port); break; case 0 : //the dispatched process - (void) contact(binding); //waiting, handling remote contact + (void) closelog(); + (void) openlog("Contact",LOG_PID,LOG_DAEMON); + (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 : @@ -234,14 +245,14 @@ int phase; _Bool proceed; bindings=(SOCTYP **)0; -bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.25","2525",2); -bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",3); +bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.25","2525",1); +//bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",3); phase=0; proceed=true; while (proceed==true) { switch (phase) { case 0 : //looping forever email receiving processes - (void) prc_settitle("emlrec with pid='%06d'",getpid()); + (void) prc_settitle("Emlrec Daemon"); break; case 1 : //Opening ALL channels if (soc_mullisten(bindings)==false) diff --git a/lib/subrou.c b/lib/subrou.c index 7c4a87b..6d3809c 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -5,6 +5,7 @@ /* */ /********************************************************/ #include +#include #include #include #include @@ -45,13 +46,13 @@ static time_t off_date=(time_t)0; static char *get_dropzone() { -const char *dropzone="/tmp/"APPNAME"-crash"; - +char *dropzone; char command[100]; +dropzone=rou_apppath("/tmp/"APPNAME"-crash"); (void) snprintf(command,sizeof(command)-2,"mkdir -p %s",dropzone); (void) system(command); -return strdup(dropzone); +return dropzone; } /* ^L @@ -323,7 +324,7 @@ while (proceed==true) { (void) rou_alert(0,"Trying to store core-dump within directory <%s>", crashdir); - if ((dirp=opendir(crashdir))!=(DIR *)0) { + if ((dirp=opendir("."))!=(DIR *)0) { int nument; struct dirent *entry; @@ -340,6 +341,9 @@ while (proceed==true) { phase=999; //No allowed to do abort } } + else + (void) rou_alert(0,"Unable to open crashdir <%s> PWD=%s (error=<%s>", + crashdir,get_current_dir_name(),strerror(errno)); (void) free(crashdir); break; case 3 : //Ok we can call abort diff --git a/lib/unisoc.c b/lib/unisoc.c index c9affa2..867d0dd 100644 --- a/lib/unisoc.c +++ b/lib/unisoc.c @@ -302,13 +302,13 @@ while (proceed==true) { break; case 2 : //check if time to retry binding if (shutdown(binding->handle,SHUT_RDWR)<0) - (void) rou_alert(0,"%s Unbale to shutdown socket (Bug!?, error=<%s>)", + (void) rou_alert(0,"%s Unable To shutdown socket (Bug!?, error=<%s>)", OPEP,strerror(errno)); break; case 3 : //closing the the socket if (close(binding->handle)<0) - (void) rou_alert(0,"%s Unbale to close socket (Bug!?, error=<%s>)", + (void) rou_alert(0,"%s Unable to close socket (Bug!?, error=<%s>)", OPEP,strerror(errno)); binding->handle=-1; break; -- 2.47.3