]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Merge log file is working fine
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 27 Mar 2025 18:34:42 +0000 (14:34 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 27 Mar 2025 18:34:42 +0000 (14:34 -0400)
app/feeder.c
lib/devlog.c
lib/devsoc.c
lib/gestcp.c
lib/lvleml.c
lib/modrec.c
lib/subrou.c
lib/uniprc.c
lib/unisig.c

index 8936909b33c7a50f3567b5934c2b5a45d1ce2566..06287c23b28b5b88d15d43fbd1aaced618efb0fb 100644 (file)
@@ -93,7 +93,7 @@ return status;
 /*     Scanning data file.                             */
 /*                                                     */
 /********************************************************/
-static _Bool scanfile(SOCPTR *socptr,const char *filename)
+static _Bool scanonefile(SOCPTR *socptr,const char *filename)
 
 {
 _Bool status;
@@ -110,6 +110,7 @@ while (proceed==true) {
   //(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));
@@ -117,7 +118,6 @@ while (proceed==true) {
         }
       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
@@ -137,6 +137,51 @@ while (proceed==true) {
   }
 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
 */
@@ -153,14 +198,12 @@ int main(int argc,char *argv[])
 {
 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;
@@ -180,23 +223,10 @@ while (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);
index 8b1115a361f0d75f7746d49f8aeeb91db70d534a..dcbaa32f2c724e9e4211e3f1da1a92eef8b4ea1a 100644 (file)
@@ -9,6 +9,7 @@
 #include        <stdbool.h>
 #include        <stdio.h>
 #include        <string.h>
+#include        <unistd.h>
 
 #include        "subrou.h"
 #include        "uniprc.h"
@@ -60,14 +61,18 @@ static _Bool mergelog(const char *logname)
 #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;
@@ -75,15 +80,21 @@ 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;
@@ -93,17 +104,39 @@ while (proceed==true) {
         }
       (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;
@@ -141,7 +174,7 @@ if (inlog==true)
 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) {
@@ -168,6 +201,7 @@ while (proceed==true) {
       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;
@@ -203,7 +237,7 @@ log=(LOGTYP *)logptr;
 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) 
index 66faf382c4747a54dfe3f3f38232cebe16824cc9..fc54b7d61dcfc4dd1b93d80d6af45387807ce151 100644 (file)
@@ -997,8 +997,15 @@ if (soc!=(SOCTYP *)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;
@@ -1043,9 +1050,10 @@ if (soc!=(SOCTYP *)0) {
             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)",
index dbf30cb51033e7dbf1e9f556708b6127adb8df22..b70cec71fc2f95f479ebfb471413df394a84c5f6 100644 (file)
@@ -42,7 +42,7 @@ got=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      :
       if (socptr==(SOCPTR *)0) {
@@ -53,19 +53,17 @@ while (proceed==true) {
     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) {
index d42d59d17da243214a773d72921e1d4fa23260ff..f5c506ad984d20322485b3164022e7f0aefe58d4 100644 (file)
@@ -311,7 +311,7 @@ _Bool proceed;
 
 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);
@@ -325,7 +325,6 @@ while (proceed==true) {
   //(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);
@@ -401,7 +400,7 @@ contact=(CONTYP *)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      :       //check for binding
       if (socptr==(SOCPTR *)0) {
index caa05a0d840de825bbfc07e6a7a58a8314c850c6..fe5233725b678bc731972c8bbc2ceabfc992298e 100644 (file)
@@ -137,14 +137,13 @@ while (proceed==true) {
     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;
index 41e07b90ba3fa2a41aa77e7706921144f181858d..1ccf2eb5888ef508ce5f46b18c07e9b6f7e7a14a 100644 (file)
@@ -21,7 +21,7 @@
 
 //version definition 
 #define VERSION "0.6"
-#define RELEASE "19"
+#define RELEASE "20"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level
index 311aec931ae107744fe1df3e426adbad0b24bc47..e8d334c5019cec099b6fe681d73f8a7997c9f73d 100644 (file)
@@ -256,9 +256,9 @@ while (proceed==true) {
          (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 {
@@ -273,7 +273,7 @@ while (proceed==true) {
       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
index 18eec1532ed39179cc00cec743135ea1d489829a..69960c11295b36a9ba96360ae1562507928c273d 100644 (file)
@@ -116,6 +116,8 @@ switch (sig)
     (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));