/* Scanning data file. */
/* */
/********************************************************/
-static _Bool scanfile(SOCPTR *socptr,const char *filename)
+static _Bool scanonefile(SOCPTR *socptr,const char *filename)
{
_Bool status;
//(void) fprintf(stdout,"JMPDBG scanfile phase='%d'\n",phase);
switch (phase) {
case 0 : //checking parameters
+ (void) fprintf(stdout,"Scanning file <%s>\n",filename);
if ((fichier=fopen(filename,"r"))==(FILE *)0) {
(void) fprintf(stdout,"Unable to open file <%s> (error=<%s>\n",
filename,strerror(errno));
}
break;
case 1 : //reading line;
- (void) fprintf(stdout,"Scanning file <%s>\n",filename);
while (fgets(line,sizeof(line),fichier)!=(char *)0) {
if (scanline(socptr,line)==false) {
phase=999; //Trouble trouble exiting
}
return status;
}
+/********************************************************/
+/* */
+/* procedure to scan all files */
+/* */
+/********************************************************/
+static int scanallfiles(int argc,char *argv[])
+
+{
+int numfile;
+SOCPTR *socptr;
+int next;
+int phase;
+
+numfile=0;
+socptr=(SOCPTR *)0;
+next=2;
+phase=0;
+while (next<argc) {
+ switch (phase) {
+ case 0 : //display scanned file
+ break;
+ case 1 : //opening a socket
+ socptr=soc_openonesock(pro_smtp,argv[0],argv[1]);
+ if (socptr==(SOCPTR *)0) {
+ (void) fprintf(stdout,"Unable to contact remote!\n");
+ phase=999;
+ }
+ break;
+ case 2 : //scanning file
+ if (scanonefile(socptr,argv[next])==false)
+ next=argc; //do not check next file
+ socptr=soc_closeonesock(socptr);
+ break;
+ case 3 : //incrementing numfile scanned
+ numfile++;
+ break;
+ default : //still file to be scanned
+ next++;
+ phase=0;
+ break;
+ }
+ phase++;
+ }
+return numfile;
+}
/*
\f
*/
{
int status;
ARGTYP *params;
-SOCPTR *socptr;
int numfile;
int phase;
_Bool proceed;
status=0;
params=(ARGTYP *)0;
-socptr=(SOCPTR *)0;
numfile=0;
phase=0;
proceed=true;
}
break;
case 2 : //opening remote channel
- socptr=soc_openonesock(pro_smtp,params->argv[0],params->argv[1]);
- if (socptr==(SOCPTR *)0) {
- (void) fprintf(stdout,"Unable to contact remote!\n");
- phase=999; //can not go further
- }
- break;
- case 3 : //doing main task
- for (int i=2;i<params->argc;i++) {
- if (scanfile(socptr,params->argv[i])==false)
- break;
- numfile++;
- }
- (void) fprintf(stdout,"%d file successfully transmetted to <%s.%s>\n",
- numfile,params->argv[0],params->argv[1]);
- break;
- case 4 : //closing remote channel
- socptr=soc_closeonesock(socptr);
+ numfile=scanallfiles(params->argc,params->argv);
+ if (numfile==(params->argc-2))
+ (void) fprintf(stdout,"%d file successfully transmitted to <%s.%s>\n",
+ numfile,params->argv[0],params->argv[1]);
break;
default : //end of task
params=par_freeparams(params);
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include "subrou.h"
#include "uniprc.h"
#define EVENT "logevent"
_Bool status;
-time_t curtime;
char *event;
-char daily[200];
+FILE *fevent;
+FILE *flog;
+time_t curtime;
char asctemps[100];
+char daily[200];
int phase;
int proceed;
status=true;
+fevent=(FILE *)0;
+flog=(FILE *)0;
curtime=time((time_t)0);
(void) strftime(asctemps,sizeof(asctemps),UFTIME,localtime(&curtime));
event=(char *)0;
phase=0;
proceed=true;
while (proceed==true) {
- (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
+ //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
switch (phase) {
case 0 : //do we have a log name?
if (logname==(char *)0) {
(void) rou_alert(0,"%s logname is missing (Bug!?)",OPEP);
- phase=999;
+ proceed=false; //trouble trouble
}
break;
- case 1 : //duplicat logname
+ case 1 : //locking access to event file
+ if (prc_locking(EVENT,true,5)==false) {
+ (void) rou_alert(0,"%s Unable to log event (Timing!?)",OPEP);
+ proceed=false; //trouble trouble
+ }
+ break;
+ case 2 : //duplicat logname
(void) strncpy(daily,logname,sizeof(daily));
if (strlen(daily)>0) {
char *ptr;
}
(void) rou_asprintf(&event,"%s/event-%s.jrl",daily,asctemps);
break;
- case 2 : //locking access to event file
- if (prc_locking(EVENT,true,5)==false) {
- (void) rou_alert(0,"%s Unable to log event (Timing!?)",OPEP);
- phase=999; //Trouble trouble
+ case 3 : //opening log file
+ if ((flog=fopen(logname,"r"))==(FILE *)0) {
+ (void) rou_alert(0,"%s Unable to open log file <%s> (error=<%s>)",
+ OPEP,logname,strerror(errno));
+ phase=999; //no need to go further
}
break;
- case 3 : //merging file
- (void) rou_alert(0,"%s JMPDBG merging file=<%s>",OPEP,event);
- (void) prc_locking(EVENT,false,1);
+ case 4 : //opening log file
+ if ((fevent=fopen(event,"a+"))==(FILE *)0) {
+ (void) rou_alert(0,"%s Unable to open event file <%s> (error=<%s>)",
+ OPEP,event,strerror(errno));
+ (void) fclose(flog);
+ phase=999; //no need to go further
+ }
+ break;
+ case 5 : //merging file
+ if (fevent!=(FILE *)0) { //always
+ char ch;
+
+ while ((ch=fgetc(flog))!=EOF)
+ fputc(ch,fevent);
+ }
+ (void) fclose(fevent);
+ (void) fclose(flog);
+ break;
+ case 6 : //removing log file
+ if (unlink(logname)<0) {
+ (void) rou_alert(0,"%s Unable to delete log file <%s> (error=<%s>)",
+ OPEP,logname,strerror(errno));
+ }
break;
default : //SAFE guard
+ (void) prc_locking(EVENT,false,1);
event=rou_freestr(event);
proceed=false;
break;
phase=0;
proceed=true;
while (proceed==true) {
- (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
+ //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
switch (phase) {
case 0 : //do we have a log name?
if (logname==(char *)0) {
break;
case 3 : //writing a minimal data
(void) clock_gettime(CLOCK_REALTIME,&(log->start));
+ (void) fprintf(log->file,"\n#-----------------------------\n");
(void) fprintf(log->file,"#%s",ctime(&(log->start.tv_sec)));
(void) fflush(log->file);
log->start.tv_sec=0;
phase=0;
proceed=true;
while (proceed==true) {
- (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
+ //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
switch (phase) {
case 0 : //do we have a log reference?
if (log==(LOGTYP *)0)
break;
}
if (sent<0) {
- (void) rou_alert(0,"%s Unable to send data, error=%d <%s> (Bug)",
- OPEP,errno,strerror(errno));
+ switch (errno) {
+ case EPIPE :
+ (void) rou_alert(0,"%s broken pipe",OPEP);
+ break;
+ default :
+ (void) rou_alert(0,"%s Unable to send data, error=%d <%s> (Bug)",
+ OPEP,errno,strerror(errno));
+ break;
+ }
}
}
return sent;
errno=EAGAIN;
switch (errno) {
case EAGAIN : //no char available
+ (void) rou_alert(0,"%s JMPDBG NO char avail",OPEP);
break;
case ECONNRESET : //Connection reset by peer
- soc->connected=false;
+ (void) rou_alert(0,"%s JMPDBG connection reset by peer",OPEP);
break;
default :
(void) rou_alert(0,"%s Unexpected error=%d <%s> (Bug)",
phase=0;
proceed=true;
while (proceed==true) {
- (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
+ //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
switch (phase) {
case 0 :
if (socptr==(SOCPTR *)0) {
case 1 : //get nextline
if ((got=soc_getnextline(socptr,lineptr))>0)
phase=999; //we got a line.
- (void) rou_alert(0,"JMPDBG %s phase='%d' got='%d'",OPEP,phase,got);
break;
case 2 : //waiting for new character presence
got=soc_waitforchar(socptr,attend);
- (void) rou_alert(0,"JMPDBG %s phase='%d' got='%d'",OPEP,phase,got);
switch (got) {
case -1 : //trouble? signal?
if ((hangup==true)||(reload==true))
phase=999; //we got a real signal
break; //no need to read line
case 0 : //normal time out
- phase=999; //no need to go further
- break; //no need to read line
+ phase=999; //no need to go further, no need to read line
+ break;
default : //char available
phase=0; //check for new line
if (soc_receive(socptr)<0) {
status=1;
delay=300; //5 minutes standard delay
-if (debug>5)
+if (debug>1)
delay/=5; //one minute in debug mode
proceed=true;
(void) signon(contact);
//(void) rou_alert(0,"%s, JMPDBG tcp_getline status='%d'",OPEP,status);
if (status<=0) { //timeout or trouble?
(void) log_fprintlog(contact->logptr,false,"%s","Lost contact with remote");
- (void) rou_alert(0,"%s, JMPDBG lost contact",OPEP);
break; //no need to go further
}
(void) log_fprintlog(contact->logptr,false,"%s",line);
phase=0;
proceed=true;
while (proceed==true) {
- (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
+ //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
switch (phase){
case 0 : //check for binding
if (socptr==(SOCPTR *)0) {
case 2 : //do contact
switch (eml_docontact(contact)) {
case -1 : //Signal received
- (void) rou_alert(0,"JMPDBG got signal within contact");
+ (void) rou_alert(0,"Signal received within contact");
break;
case 0 : //exit under timeout
- (void) rou_alert(0,"Contact with peer <%s> closed by timeout",
- contact->peerip);
+ (void) rou_alert(0,"Lost contact with peer <%s>",contact->peerip);
break;
default : //exit under quit
- (void) rou_alert(0,"JMPDBG exit under quit");
+ (void) rou_alert(0,"Contact terminated by 'quit'");
break;
}
break;
//version definition
#define VERSION "0.6"
-#define RELEASE "19"
+#define RELEASE "20"
//Public variables
PUBLIC int debug=0; //debug level
(void) fgets(strloc,sizeof(strloc)-1,fichier);
(void) fclose(fichier);
if (sscanf(strloc,"%lu",(u_long *)(&pid))==1) {
- (void) rou_alert(2,"Locking, check %d process active",pid);
+ (void) rou_alert(5,"Locking, check %d process active",pid);
if (prc_checkprocess(pid)==false) {
- (void) rou_alert(2,"Locking, removing pid=%d unactive lock",pid);
+ (void) rou_alert(6,"Locking, removing pid=%d unactive lock",pid);
(void) unlink(fullname);
}
else {
break;
case 5 : //do we need to unlock ?
if (lock==LCK_UNLOCK) {
- (void) rou_alert(9,"%s Request unlocking <%s>",OPEP,fullname);
+ (void) rou_alert(6,"%s Request unlocking <%s>",OPEP,fullname);
(void) unlink(fullname);
done=true;
phase=999; //No need to go further
(void) rou_alert(0,"%s deamon, new decreased debug level now set to '%d'",
APPNAME,debug);
break;
+ case SIGPIPE :
+ break;
default :
(void) rou_alert(0,"Unexpected Signal [%d]/<%s> received",
sig,strsignal(sig));