]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Add a double check on the data at the user's level
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 1 Feb 2012 10:21:37 +0000 (11:21 +0100)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 1 Feb 2012 10:21:37 +0000 (11:21 +0100)
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
log.c
repday.c

index 403b335a4f6d4f973e829c6985283de9ee562810..690973bf043c49ff8c1760918ed14aa1b2832550 100755 (executable)
@@ -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 96838c1179188f9536cbae0bb3f467460857ff87..dd40024bd343dc8ac0a5aa4426a32fa1d43c07ad 100644 (file)
--- 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) {
index 08cff9ec0dc00755f7b9de382a889b30bb65710d..5fc8bed8c2e51e918dd2cb1c4e489846bb5181ef 100644 (file)
--- a/repday.c
+++ b/repday.c
@@ -177,6 +177,13 @@ void report_day(const struct userinfostruct *uinfo)
                }
                fprintf(fp_ou, "<td class=\"header_r\">%s</td></tr>\n",fixnum(tt,1));
                fputs("</table>\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, "<td class=\"header_r\">%s</td></tr>\n",fixtime(tt));
                fputs("</table>\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)