From: Jean-Marc Pigeon (Delson) Date: Wed, 17 Jul 2024 07:43:18 +0000 (-0400) Subject: This phase is an echec some memory is over written X-Git-Tag: tag-0.3 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=48894699e5df8b399ae876d75923ad7951f9c53d;p=jmp%2Fmailleur This phase is an echec some memory is over written --- diff --git a/lib/gestcp.c b/lib/gestcp.c index 6594a63..2d44d27 100644 --- a/lib/gestcp.c +++ b/lib/gestcp.c @@ -56,6 +56,7 @@ if (contact<0) { else { int flags; + (void) rou_alert(0,"JMPDBG binding->handle '%d'",binding->handle); if ((flags=fcntl(contact,F_GETFL,0))<0) (void) rou_core_dump("%s Unable to get socket descripteur (error='%s')", OPEP,strerror(errno)); @@ -105,6 +106,10 @@ while (proceed==true) { } break; case 2 : //listening on the handle + (void) soc_setlinger(binding->handle); + (void) soc_getlinger(binding->handle,"waitlisten"); + break; + case 3 : //listening on the handle fd_set reading; struct timeval relax; int status; @@ -118,7 +123,8 @@ while (proceed==true) { 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!"); + (void) fprintf(stderr,"JMPDBG pid='%05d select received a signal!\n", + getpid()); phase=999; break; default : //Unexpected error? @@ -157,7 +163,7 @@ while (proceed==true) { break; } phase++; - (void) rou_alert(0,"JMPDB waitlisten contat='%d' phase='%d'",contact,phase); + //(void) rou_alert(0,"JMPDB waitlisten contat='%d' phase='%d'",contact,phase); } return contact; #undef OPEP @@ -181,6 +187,7 @@ va_list args; sent=0; va_start(args,format); sent=vdprintf(contact->channel,format,args); +//(void) fdatasync(contact->channel); va_end(args); return sent; } @@ -229,7 +236,7 @@ while (proceed==true) { proceed=false; break; } - (void) rou_alert(0,"JMPDB tcp_getcontact contat='%p' phase='%d'",contact,phase); + //(void) rou_alert(0,"JMPDBG tcp_getcontact contat='%p' phase='%d'",contact,phase); phase++; } return contact; diff --git a/lib/modrec.c b/lib/modrec.c index 4739ff1..7e0420e 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -54,17 +54,19 @@ while (proceed==true) { case 2 : //do contact for (int i=0;i",strerror(errno)); break; } + (void) read(contact->channel,tmpbuf,sizeof(tmpbuf)); + (void) sleep(2); } break; case 3 : //close contact @@ -113,6 +115,7 @@ while (proceed==true) { for (int i=0;iiteration;i++) { if (binding->childs[i]!=(pid_t)0) continue; + (void) soc_getlinger(binding->handle,"before fork"); switch(binding->childs[i]=fork()) { case -1 : (void) rou_alert(0,"%s, Unable to start process to " @@ -121,10 +124,11 @@ while (proceed==true) { break; case 0 : //the dispatched process (void) closelog(); - (void) openlog("Contact",LOG_PID,LOG_DAEMON); + (void) openlog("Contact",LOG_NDELAY|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 : @@ -169,6 +173,7 @@ while (proceed==true) { break; case 1 : //check need to dispatch a process while (*bindings!=(SOCTYP *)0) { + (void) soc_getlinger((*bindings)->handle,"before displatching"); (void) dispatching(*bindings); bindings++; } @@ -268,8 +273,8 @@ int phase; _Bool proceed; bindings=(SOCTYP **)0; -bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.25","2525",1); -//bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",3); +bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.25","2525",2); +//bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",1); phase=0; proceed=true; while (proceed==true) { diff --git a/lib/subrou.c b/lib/subrou.c index 6d3809c..fb93f4a 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -394,7 +394,7 @@ if (mode!=modopen) { (void) srand((int)(M_PI*100000000)); if (appname==(char *)0) appname=strdup(APPNAME); - (void) openlog(appname,LOG_PID,LOG_DAEMON); + (void) openlog(appname,LOG_NDELAY|LOG_PID,LOG_DAEMON); (void) rou_alert(0,"Starting: %s-%s",appname,rou_getversion()); break; case false : diff --git a/lib/unisoc.c b/lib/unisoc.c index 6070fc2..0b4d032 100644 --- a/lib/unisoc.c +++ b/lib/unisoc.c @@ -80,6 +80,12 @@ flags=0; phase=0; proceed=true; while (proceed==true) { + if (handle>=0) { + char bigre[50]; + + (void) sprintf(bigre,"Phase='%02d'",phase); + (void) soc_getlinger(handle,bigre); + } switch (phase) { case 0 : //lets get a socket if ((handle=socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol))<0) { @@ -108,11 +114,12 @@ while (proceed==true) { if (setsockopt(handle,SOL_SOCKET,SO_LINGER,&slg,sizeof(slg))<0) { (void) rou_alert(0,"%s Unable to set socket option " "SO_LINGER for <%s> (error='%s')", - OPEP,ai->ai_canonname,strerror(errno)); + OPEP,strerror(errno)); phase=999; //trouble cleanup phase } break; case 4 : /*getting socket option */ + (void) soc_getlinger(handle,"binhandle"); if ((flags=fcntl(handle,F_GETFL,0))<0) { (void) rou_alert(0,"%s Unable to set socket descriptor " "for <%s> (error='%s')", @@ -129,6 +136,7 @@ while (proceed==true) { } break; case 6 : //getting socket option + (void) soc_getlinger(handle,"before bind"); if (bind(handle,ai->ai_addr,ai->ai_addrlen)<0) { (void) rou_alert(0,"%s Unable to bind on IP/port <%s/%s> (error='%s')", OPEP,ai->ai_canonname,binding->port,strerror(errno)); @@ -136,6 +144,7 @@ while (proceed==true) { } break; case 7 : /*preparing listen */ + (void) soc_getlinger(handle,"after bind"); if (listen(handle,5)<0) { (void) rou_alert(0,"%s Unable to listen on IP/port <%s/%s> (error='%s')", OPEP,ai->ai_canonname,binding->port,strerror(errno)); @@ -143,6 +152,7 @@ while (proceed==true) { } break; case 8 : /*reporting listen */ + (void) soc_getlinger(handle,"after listen"); (void) rou_alert(1,"Now Listening on IP/PORT <%s/%s>", ai->ai_canonname,binding->port); proceed=false; //evrything fine no need to go further @@ -157,6 +167,7 @@ while (proceed==true) { } (void) free(buf); (void) rou_alert(0,"JMPDBG got handle channel='%d'",handle); +(void) soc_getlinger(handle,"exiting from bindhandle"); return handle; #undef OPEP } @@ -208,6 +219,44 @@ bindings=(SOCTYP **)rou_addlist((void **)bindings,(void *)bininf); return bindings; } /* + +*/ +/********************************************************/ +/* */ +/* Procedure to set set the linger mode on the */ +/* socket device. */ +/* return -1 if trouble. */ +/* */ +/********************************************************/ +PUBLIC int soc_setlinger(int socket) + +{ +#define OPEP "unisoc.c:soc_setlinger" +#define BFSZ 30 + +int status; +int flags; +char *buf; +struct linger slg; + +status=-1; +slg.l_onoff=true; +slg.l_linger=0; +buf=calloc(BFSZ,sizeof(char)); +flags=fcntl(socket,F_GETFL,0); +(void) fcntl(socket,F_SETFL,flags|O_NONBLOCK|O_ASYNC); +(void) setsockopt(socket,SOL_SOCKET,SO_REUSEADDR,buf,BFSZ*sizeof(char)); +(void) setsockopt(socket,SOL_SOCKET,SO_REUSEPORT,buf,BFSZ*sizeof(char)); +status=setsockopt(socket,SOL_SOCKET,SO_LINGER,&slg,sizeof(slg)); +if (status<0) + (void) rou_alert(0,"%s Unable to set socket option " + "SO_LINGER for <%s> (error='%s' bug?)", + OPEP,strerror(errno)); +(void) free(buf); +return status; +#undef OPEP +} +/* ^L */ /********************************************************/ @@ -260,7 +309,8 @@ while (proceed==true) { break; case 3 : //binding socket soc=bindhandle(tobind,binding); - (void) freeaddrinfo(tobind); + (void) soc_getlinger(soc,"result from bindhandle"); + //(void) freeaddrinfo(tobind); JMPDBG ALARM break; default : //SAFE Guard proceed=false; @@ -268,6 +318,7 @@ while (proceed==true) { } phase++; } +(void) soc_getlinger(soc,"exiting from soc_onelisten"); return soc; #undef OPEP } @@ -366,9 +417,16 @@ while (proceed==true) { case 2 : //binding on all interface ready=true; while (*bindings!=(SOCTYP *)0) { - (*bindings)->handle=soc_onelisten(*bindings); + int soc; + + soc=soc_onelisten(*bindings); + (void) soc_getlinger(soc,"after onelisten"); + (*bindings)->handle=soc; + (void) soc_getlinger((*bindings)->handle,"after binding onelisten"); if ((*bindings)->handle<0) ready=false; //Trouble? + else + (void) soc_getlinger((*bindings)->handle,"mullisten"); bindings++; } break; @@ -424,6 +482,19 @@ while (proceed==true) { } #undef OPEP } +//temporary JMPDBG +void soc_getlinger(int socket,char *inf) + +{ +socklen_t len; +struct linger slg; + +if (getsockopt(socket,SOL_SOCKET,SO_LINGER,&slg,&len)<0) + (void) rou_alert(0,"JMPDBG LISTEN trouble (error='%s')",strerror(errno)); +(void) rou_alert(0,"JMPDBG [%s] get socket='%d' linger.onoff='%d', " + "timeout linger='%d'", + inf,socket,slg.l_onoff,slg.l_linger); +} /* ^L */ diff --git a/lib/unisoc.h b/lib/unisoc.h index bb42135..e9e9fa2 100644 --- a/lib/unisoc.h +++ b/lib/unisoc.h @@ -38,6 +38,9 @@ extern SOCTYP **soc_freebindinf(SOCTYP **bindref); extern SOCTYP **soc_mkbindinf(SOCTYP **bindings,PROTYP proto, const char *ip,const char *port,int iteration); +//Procedure to set the linger value on the socket handle +extern int soc_setlinger(int socket); + //procedure to open ONE socket and return handle to socket extern int soc_onelisten(SOCTYP *binding); @@ -51,6 +54,9 @@ extern int soc_mullisten(SOCTYP **bindings); //procedure to close all sockets extern void soc_mulclose(SOCTYP **bindings); +//temporary JMPDBG +extern void soc_getlinger(int socket,char *inf); + //homework to be done before starting/stopping module. extern int soc_modeunisoc(_Bool mode);