From 42e18a831b9e057481c1e2b36d05f64233b218db Mon Sep 17 00:00:00 2001 From: Frederic Marchal Date: Wed, 4 Mar 2015 19:52:18 +0100 Subject: [PATCH] Check the total downloaded size much earlier If there is a discrepancy between the total downloaded size computed when reading the access.log and computed later when building the report, it can be checked much earlier than it used to be. This check stops sarg sooner before creating many reports and wasting disk space. --- totday.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/totday.c b/totday.c index 3fcc58e..5a640d5 100644 --- a/totday.c +++ b/totday.c @@ -145,6 +145,9 @@ void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct * int daynum; int dayidx; char arqout[2048]; +#ifdef ENABLE_DOUBLE_CHECK_DATA + long long int tt=0; +#endif if (datetimeby==0) return; if (!ddata) return; @@ -176,11 +179,21 @@ void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct * if ((datetimeby & DATETIME_BYTE)!=0) fprintf(fp_ou,"\t%"PRIu64"",(uint64_t)ddata->bytes[i]); if ((datetimeby & DATETIME_ELAP)!=0) fprintf(fp_ou,"\t%"PRIu64"",(uint64_t)ddata->elap[i]); fputs("\n",fp_ou); +#ifdef ENABLE_DOUBLE_CHECK_DATA + tt+=ddata->bytes[i]; +#endif } if (fclose(fp_ou)==EOF) { debuga(_("Failed to close file \"%s\": %s\n"),arqout,strerror(errno)); exit(EXIT_FAILURE); } +#ifdef ENABLE_DOUBLE_CHECK_DATA + if (tt!=uinfo->nbytes) { + debuga(_("Total downloaded bytes is %"PRIi64" instead of %"PRIi64" in the hourly report of user %s\n"), + (int64_t)tt,(int64_t)uinfo->nbytes,uinfo->label); + exit(EXIT_FAILURE); + } +#endif return; } -- 2.47.2