#TESTPROT= smtps
EXTIP = safemail3.safe.ca
EXTPORT = 25
-TESTITER= 4
+TESTITER= 1
#--------------------------------------------------------------------
#To test sorter
dosorter: debug
EMLPAR = \
-r $(TESTDIR) \
-c ./conf/$(APPNAME).conf.dvl \
- -d 3 \
+ -d 2 \
$(TESTPROT):$(TESTIP):$(TESTPORT):
dorcvr : debug
#to kill all remaining emlrcvr process
killall :
- @ - kill -9 emlrcvr
+ @ - kill -HUP emlrcvr
@ - kill -9 sorter
#--------------------------------------------------------------------
(void) rou_setappname(SORTER);
(void) rou_loadconfig(config,true);
(void) openlog(appname,LOG_NDELAY|LOG_PID,LOG_DAEMON);
- (void) closelog();
break;
- case 2 : //check about signal
- if ((hangup==true)||(reload==true))
- phase=999; //Process
+ case 2 : //check about signal process
+ if (hangup==true) {
+ (void) rou_alert(0,"%s got hangup signal",OPEP);
+ phase=999; //exiting loop
+ }
+ if (reload==true) {
+ (void) rou_alert(0,"%s got reload signal",OPEP);
+ phase=999; //exiting loop
+ }
break;
case 3 : //Scanning all ".trans" file
(void) scantrans(EXTRANS,true);
(void) rou_loadconfig(config,false);
(void) sig_modeunisig(false);
(void) rou_modesubrou(false);
+ (void) closelog();
proceed=false;
break;
}
OPEP,soc->ip,soc->port,strerror(errno));
break;
case EINTR :
- (void) rou_alert(3,"%s Socket on IP/PORT <%s/%s> got a signal "
+ (void) rou_alert(5,"%s Socket on IP/PORT <%s/%s> got a signal "
"(errno=<%s>)",
OPEP,soc->ip,soc->port,strerror(errno));
break;
break;
case 2 : //waiting for new connection
if ((newsoc=waitincoming(soc))==(SOCPTR *)0) {
- (void) rou_alert(0,"%s, Contact from Remote not successful",OPEP);
+ (void) rou_alert(4,"%s, Contact from Remote not successful",OPEP);
phase=999; //no need to go further
}
break;
phase=0;
proceed=true;
while (proceed==true) {
+ //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
switch (phase) {
case 0 : //get database parameters
for (int i=0;i<(sizeof(dbenv)/sizeof(char *));i++) {
break;
case 3 : //checking if the database is properly open
if (sql->db.psql==(POSPTR *)0) {
+ (void) rou_alert(0,"%s data-base not properly connected (config?)",OPEP);
(void) free(sql);
sql=(SQLTYP *)0;
phase=999; //Trouble trouble
switch (phase) {
case 0 : //check if database available
if (sql==(SQLTYP *)0) {
- (void) rou_alert(0,"%s %s Datbase pointer null (bug?)",OPEP);
+ (void) rou_alert(0,"%s %s Database pointer is NULL (bug?)",OPEP);
phase=999;
}
break;
static CONTYP *freecontact(CONTYP *contact)
{
-#define OPEP "gestcp.c:freecontact"
+#define OPEP "lvleml.c:freecontact"
if (contact!=(CONTYP *)0) {
contact->sqlptr=sql_closesql(contact->sqlptr);
break;
case 2 : //waiting from contact
if ((contact->socptr=soc_accept(socptr,pos))==(SOCPTR *)0) {
- (void) rou_alert(0,"%s Unable to open contact",OPEP);
- contact->sqlptr=sql_closesql(contact->sqlptr);
+ (void) rou_alert(3,"%s Unable to open contact",OPEP);
contact=freecontact(contact);
phase=999; //no contact
}
{
#define OPEP "modrec.c:rec_handlesmtp"
+#define RELAX 5 //Relax time between process checking
pid_t *childs;
int nbrbind;
}
childs=(pid_t *)calloc(nbrbind,sizeof(pid_t));
break;
- case 1 : //Opening ALL channels
+ case 1 : //Detecting signal
+ if ((hangup==true)||(reload==true)) {
+ (void) prc_killchilds(childs,nbrbind,10);
+ phase=999; //No need to have sub process;
+ }
+ break;
+ case 2 : //Opening ALL channels
allbusy=true;
for (int i=0;i<nbrbind;i++) {
(void) prc_nozombie();
}
}
if (allbusy==true) { //all serveur up and running?
- (void) sleep(1); //yes then relax
+ (void) sleep(RELAX); //yes! then relax
phase=0; //Lets check again
}
break;
- case 2 : //starting one process only
+ case 3 : //starting one process only
if (foreground==true) {
(void) startwaiter(bindings[0]);
phase++; //no multiple fork
}
break;
- case 3 : //starting/restarting all waiting process
+ case 4 : //starting/restarting all waiting process
for (int i=0;i<nbrbind;i++) {
if (childs[i]!=(pid_t)0)
continue;
(void) rou_alert(0,"%s Unable to fork smtp handler (error=<%s>)",
OPEP,strerror(errno));
childs[i]=(pid_t)0;
- (void) sleep(1); //Weathering the storm
+ (void) sleep(2); //Weathering the storm
break;
case 0 : //Child process itself
(void) startwaiter(bindings[i]);
+ (void) exit(0);
break;
default : //Main process
(void) usleep(10000);
}
}
break;
- case 4 : //relax time
- if ((hangup==false)&&(reload==false)&&(foreground==false))
- phase=0; //Normal process, lets restart
- else
- (void) usleep(10000);
- break;
- case 5 : //we got a signal, kill all childs
- (void) prc_killchilds(childs,nbrbind,10);
+ case 5 : //lets continue within process loop
+ if (foreground==false)
+ phase=0;
break;
default : //SAFE Guard
if (childs!=(pid_t *)0)
}
phase++;
}
+
+#undef RELAX
#undef OPEP
}
{
if (debug>=dlevel)
{
- char *ptr;
char strloc[10000];
(void) memset(strloc,'\000',sizeof(strloc));
(void) vsnprintf(strloc,sizeof(strloc)-1,fmt,ap);
- ptr=strloc;
if (foreground==true)
(void) fprintf(stderr,"%s\n",strloc);
else {
+ char *ptr;
+ char lvl[10];
+
+ ptr=strloc;
+ (void) snprintf(lvl,sizeof(lvl),":%02d: ",dlevel);
while (strlen(ptr)>DEBMAX) {
char locline[DEBMAX+10];
(void) strncpy(locline,ptr,DEBMAX);
locline[DEBMAX]='\000';
- (void) syslog(LOG_INFO,"%s",locline);
+ (void) syslog(LOG_INFO,"%s%s",lvl,locline);
ptr +=DEBMAX;
+ (void) strcpy(lvl,"");
}
if (strlen(ptr)>0)
- (void) syslog(LOG_INFO,"%s",ptr);
+ (void) syslog(LOG_INFO,"%s%s",lvl,ptr);
}
}
}