]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Check the total downloaded size much earlier
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Wed, 4 Mar 2015 18:52:18 +0000 (19:52 +0100)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Wed, 4 Mar 2015 18:52:18 +0000 (19:52 +0100)
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

index 3fcc58e15467e7cb480d02216b2fc2d25bcffad9..5a640d562995328b95e369db9f7dcd36c8788041 100644 (file)
--- 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;
 }