taille=sizeof(addr);
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 :
if ((flags=fcntl(contact,F_GETFL,0))<0)
(void) rou_core_dump("%s Unable to get socket descripteur (error='%s')",
- OPEP,strerror(errno));
- if ((flags=fcntl(contact,F_SETFL,flags|O_NONBLOCK|O_ASYNC))<0)
- (void) rou_core_dump("%s Unable to set socket descripteur (error='%s')",
+ OPEP,strerror(errno));
+ if ((flags=fcntl(contact,F_SETFL,flags|O_NONBLOCK|O_ASYNC))<0)
+ (void) rou_core_dump("%s Unable to set socket descripteur (error='%s')",
OPEP,strerror(errno));
}
+(void) rou_alert(0,"JMPDBG got contact channel='%d'",contact);
return contact;
#undef OPEP
}
relax.tv_sec=1; //1 sec relax time
relax.tv_usec=0;
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) {
}
break;
}
- (void) rou_alert(0,"JMPDBG exiting from select phase='%d' contact='%d'",
- phase,contact);
break;
default : //SAFE Guard
proceed=false;
break;
}
phase++;
+ (void) rou_alert(0,"JMPDB waitlisten contat='%d' phase='%d'",contact,phase);
}
return contact;
#undef OPEP
*/
/********************************************************/
/* */
+/* Procedure to send data to a tcp socket. */
+/* return the number of character transmitted, is */
+/* unable to send char return -1; */
+/* */
+/********************************************************/
+PUBLIC int tcp_fprintf(CONTYP *contact,const char *format,...)
+
+{
+int sent;
+va_list args;
+
+sent=0;
+va_start(args,format);
+sent=vdprintf(contact->channel,format,args);
+va_end(args);
+return sent;
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
/* Procedure to wait for a remote client. */
/* return all reference to the established contact.*/
/* */
proceed=false;
break;
}
+ (void) rou_alert(0,"JMPDB tcp_getcontact contat='%p' phase='%d'",contact,phase);
phase++;
}
return contact;
}
break;
case 1 : //waiting from contact
+ (void) rou_alert(0,"JMPDBG shutdown contact channel='%d'",contact->channel);
if (shutdown(contact->channel,SHUT_RDWR)<0) {
switch (errno) {
case ENOTCONN : //already disconnect by other side!
SOCTYP *binding;//extablised contact context
}CONTYP;
+//Transmit formated data to the contact channel
+extern int tcp_fprintf(CONTYP *contact,const char *format,...);
+
+//Wait for an input coming from the contact channel
+extern int *tcp_fscanf(CONTYP *contact,const char *format,...);
+
//wait for an incoming contact
extern CONTYP *tcp_getcontact(SOCTYP *binding);
break;
case 2 : //do contact
for (int i=0;i<TESTL;i++) {
+ int sent;
+
(void) sleep(2);
if ((reload==true)||(hangup==true))
break;
if (prc_checkprocess(getppid())==false)
break;
- (void) dprintf(contact->channel,"JMPDBG pid=%d iteration=%d/%d\n",
- getpid(),i,TESTL);
-
+ sent=tcp_fprintf(contact,"JMPDBG pid=%d iter=%d/%d\n",getpid(),i,TESTL);
+ if (sent<0) {
+ (void) rou_alert(0,"JMPDBG tcp_fprintf error <%s>",strerror(errno));
+ break;
+ }
}
break;
case 3 : //close contact
(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 :
{
#define OPEP "modrec.c:release"
+SOCTYP **ptr;
int phase;
_Bool proceed;
+ptr=bindings;
phase=0;
proceed=true;
while (proceed==true) {
switch (phase) {
case 0 : //making sur the list is defined
- if (bindings==(SOCTYP **)0) {
+ if (ptr==(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)
+ ptr=bindings;
+ while (*ptr!=(SOCTYP *)0) {
+ for (int i=0;i<(*ptr)->iteration;i++) {
+ if ((*ptr)->childs[i]==(pid_t)0)
continue;
- if (prc_checkprocess((*bindings)->childs[i])==true) {
+ if (prc_checkprocess((*ptr)->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;
+ (*ptr)->childs[i]);
+ (void) kill((*ptr)->childs[i],SIGTERM);
+ (void) usleep(1000);
}
}
- bindings++;
+ ptr++;
+ }
+ break;
+ case 2 : //checking if ALL process are now terminated
+ sleep(1);
+ (void) prc_nozombie();
+ ptr=bindings;
+ while (*ptr!=(SOCTYP *)0) {
+ for (int i=0;i<(*ptr)->iteration;i++) {
+ if ((*ptr)->childs[i]==(pid_t)0)
+ continue;
+ if (prc_checkprocess((*ptr)->childs[i])==false) {
+ (*ptr)->childs[i]=(pid_t)0;
+ continue;
+ }
+ phase=0; //some process still remain killing again?
+ }
+ ptr++;
}
break;
default : //SAFE Guard
if ((hangup==false)&&(reload==false))
phase--; //normal cycle, lets proceed to actvate again
break;
- case 3 : //closing all socket currently opened
+ case 3 : //release current binding
(void) release(bindings);
+ break;
+ case 4 : //closing all socket currently opened
(void) soc_mulclose(bindings);
break;
default : //SAFE Guard
_Bool proceed;
handle=-1;
-(void) memset(&slg,'\000',sizeof(struct linger));
+slg.l_onoff=true;
+slg.l_linger=0; /*0 sec timeout on close*/
buf=calloc(BFSZ,sizeof(char));
flags=0;
phase=0;
phase=999; //trouble cleanup phase
}
break;
- case 3 : //SO_LINGER allow Connection reset by peer"
+ case 3 : //SO_LINGER allow Connection reset by peer
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')",
phase++;
}
(void) free(buf);
+(void) rou_alert(0,"JMPDBG got handle channel='%d'",handle);
return handle;
#undef OPEP
}