From d91457d25a030fddc63bbfa1220363704cdaeff2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Wed, 1 Feb 2012 11:21:37 +0100 Subject: [PATCH] Add a double check on the data at the user's level There already was a check on the global data collected from the access log to ensure no data was lost. There is now a check on the amount of bytes download by the user and the time elapsed. The detection of a failure is therefore more accurate and make it easier to locate the leak. --- include/defs.h | 6 ++++++ log.c | 24 +++++++++++++++++------- repday.c | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/include/defs.h b/include/defs.h index 403b335..690973b 100755 --- a/include/defs.h +++ b/include/defs.h @@ -55,6 +55,12 @@ struct userinfostruct int topuser; //! A general purpose flag that can be set when scanning the user's list. int flag; +#ifdef ENABLE_DOUBLE_CHECK_DATA + //! Total number of bytes. + long long int nbytes; + //! Total time spent processing the requests. + long long int elap; +#endif }; //! Scan through the known users. diff --git a/log.c b/log.c index 96838c1..dd40024 100644 --- a/log.c +++ b/log.c @@ -126,6 +126,8 @@ int main(int argc,char *argv[]) int iarq=0; int isa_ncols=0,isa_cols[ISACOL_Last]; int lastlog=-1; + long int nbytes; + long int elap_time; bool from_stdin; bool from_pipe; int blen; @@ -1411,10 +1413,14 @@ int main(int argc,char *argv[]) if(strcmp(user,"-") ==0 || strcmp(user," ") ==0 || strcmp(user,"") ==0 || strcmp(user,":") ==0) continue; + nbytes=atol(tam); + if (nbytes<0) nbytes=0; + + elap_time=atol(elap); + if (elap_time<0) elap_time=0; if(max_elapsed) { - if(atol(elap)>max_elapsed) { - elap[0]='0'; - elap[1]='\0'; + if(elap_time>max_elapsed) { + elap_time=0; } } @@ -1448,6 +1454,10 @@ int main(int argc,char *argv[]) first_user_file=ufile; } } +#ifdef ENABLE_DOUBLE_CHECK_DATA + ufile->user->nbytes+=nbytes; + ufile->user->elap+=elap_time; +#endif if (ufile->file==NULL) { if (nopen>=maxopenfiles) { @@ -1486,13 +1496,13 @@ int main(int argc,char *argv[]) } strcpy( sz_Last_User , user ) ; }*/ - if (fprintf(ufile->file, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,ip,url,tam,code,elap,smartfilter)<=0) { + if (fprintf(ufile->file, "%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,ip,url,nbytes,code,elap_time,smartfilter)<=0) { debuga(_("Write error in the log file of user %s\n"),user); exit(EXIT_FAILURE); } if(fp_log && ilf!=ILF_Sarg) - fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter); + fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,user,ip,url,nbytes,code,elap_time,smartfilter); totregsg++; @@ -1537,13 +1547,13 @@ int main(int argc,char *argv[]) if(debugm){ printf("IP=\t%s\n",ip); printf("USER=\t%s\n",user); - printf("ELAP=\t%s\n",elap); + printf("ELAP=\t%ld\n",elap_time); printf("DATE=\t%s\n",dia); printf("TIME=\t%s\n",hora); printf("FUNC=\t%s\n",fun); printf("URL=\t%s\n",url); printf("CODE=\t%s\n",code); - printf("LEN=\t%s\n",tam); + printf("LEN=\t%ld\n",nbytes); } } if (!from_stdin) { diff --git a/repday.c b/repday.c index 08cff9e..5fc8bed 100644 --- a/repday.c +++ b/repday.c @@ -177,6 +177,13 @@ void report_day(const struct userinfostruct *uinfo) } fprintf(fp_ou, "%s\n",fixnum(tt,1)); fputs("\n",fp_ou); +#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 } if((datetimeby & DATETIME_ELAP)!=0) { @@ -220,6 +227,13 @@ void report_day(const struct userinfostruct *uinfo) } fprintf(fp_ou, "%s\n",fixtime(tt)); fputs("\n",fp_ou); +#ifdef ENABLE_DOUBLE_CHECK_DATA + if (tt!=uinfo->elap) { + debuga(_("Total elapsed time is %"PRIi64" instead of %"PRIi64" in the hourly report of user %s\n"), + (int64_t)tt,(int64_t)uinfo->elap,uinfo->label); + exit(EXIT_FAILURE); + } +#endif } if (write_html_trailer(fp_ou)<0) -- 2.47.2