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>",
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
}
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;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <unistd.h>
#include "subrou.h"
/* a remote TCP connection. */
/* */
/********************************************************/
-void contact(SOCTYP *binding)
+void docontact(SOCTYP *binding)
{
#define OPEP "modrec.c:contact"
+#define TESTL 4
CONTYP *contact;
int phase;
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;i<TESTL;i++) {
+ (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,20);
+ getpid(),i,TESTL);
}
break;
- case 2 : //close contact
+ case 3 : //close contact
contact=tcp_dropcontact(contact);
break;
default : //SAFE guard
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 :
_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)
/* */
/********************************************************/
#include <dirent.h>
+#include <errno.h>
#include <math.h>
#include <signal.h>
#include <stdio.h>
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
(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;
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
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;