From: Frédéric Marchal Date: Tue, 28 Aug 2012 06:09:58 +0000 (+0200) Subject: Don't trash the period when reading multiple log files X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cc6af4601cff36bace15e3e1e808538b8a045920;p=thirdparty%2Fsarg.git Don't trash the period when reading multiple log files 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. --- diff --git a/include/defs.h b/include/defs.h index 03f278a..03170ca 100755 --- a/include/defs.h +++ b/include/defs.h @@ -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); diff --git a/readlog_sarg.c b/readlog_sarg.c index 8f9a978..7a0b314 100644 --- a/readlog_sarg.c +++ b/readlog_sarg.c @@ -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 0c0c243..ac12246 100644 --- 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 (cdatestart,&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;