]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Don't trash the period when reading multiple log files
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 28 Aug 2012 06:09:58 +0000 (08:09 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 28 Aug 2012 06:09:58 +0000 (08:09 +0200)
Reading multiple input log files overwrite the period due to the
processing made before reading a new file in readlog_sarg.c.

This fix make sure the period is as big as the total period of all the logs
read by sarg. It doesn't take into account gaps in the logs.

include/defs.h
readlog_sarg.c
util.c

index 03f278acc7aae98ea195fb947b87c2d69f9b46c8..03170ca141346628bc5d6795c68e76ec836fbd8d 100755 (executable)
@@ -336,6 +336,7 @@ int builddia(int day, int month, int year);
 int vrfydir(const struct periodstruct *per1, const char *addr, const char *site, const char *us, const char *form);
 int getperiod_fromsarglog(const char *arqtt,struct periodstruct *period);
 void getperiod_fromrange(struct periodstruct *period,int dfrom,int duntil);
+void getperiod_merge(struct periodstruct *main,struct periodstruct *candidate);
 int getperiod_buildtext(struct periodstruct *period);
 void removetmp(const char *outdir);
 void zdate(char *ftime,int ftimesize, char DateFormat);
index 8f9a978f0a4eb9287ab715ee629e68d247008cba..7a0b314384b8e75b8452df4bc237c5b8a961d591 100644 (file)
@@ -31,6 +31,8 @@
 static bool InSargLog=false;
 //! \c True if the file name is invalid.
 static bool InvalidFileName=true;
+//! The last period extracted from the log file name.
+static struct periodstruct SargPeriod;
 
 /*!
 A new file is being read. The name of the file is \a FileName.
@@ -38,7 +40,7 @@ A new file is being read. The name of the file is \a FileName.
 static void Sarg_NewFile(const char *FileName)
 {
        InSargLog=false;
-       InvalidFileName=(getperiod_fromsarglog(FileName,&period)<0);
+       InvalidFileName=(getperiod_fromsarglog(FileName,&SargPeriod)<0);
 }
 
 /*!
@@ -70,6 +72,7 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct
                        debuga(_("The name of the file is invalid for a sarg log\n"));
                        exit(EXIT_FAILURE);
                }
+               getperiod_merge(&period,&SargPeriod);
                InSargLog=true;
                return(RLRC_Ignore);
        }
diff --git a/util.c b/util.c
index 0c0c2430625b641dd64e8706c525482a48514106..ac12246eecf19efc9de1ef871d767e410445afb4 100644 (file)
--- a/util.c
+++ b/util.c
@@ -948,6 +948,23 @@ void getperiod_fromrange(struct periodstruct *period,int dfrom,int duntil)
        period->end.tm_year=(duntil/10000)-1900;
 }
 
+/*!
+Update the \a main period to encompass the period in \a candidate.
+*/
+void getperiod_merge(struct periodstruct *main,struct periodstruct *candidate)
+{
+       int cdate;
+       int mdate;
+
+       mdate=(main->start.tm_year)*10000+(main->start.tm_mon)*100+main->start.tm_mday;
+       cdate=(candidate->start.tm_year)*10000+(candidate->start.tm_mon)*100+candidate->start.tm_mday;
+       if (cdate<mdate) memcpy(&main->start,&candidate->start,sizeof(struct tm));
+
+       mdate=(main->end.tm_year)*10000+(main->end.tm_mon)*100+main->end.tm_mday;
+       cdate=(candidate->end.tm_year)*10000+(candidate->end.tm_mon)*100+candidate->end.tm_mday;
+       if (cdate>mdate) memcpy(&main->end,&candidate->end,sizeof(struct tm));
+}
+
 int getperiod_buildtext(struct periodstruct *period)
 {
        int i;