]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - repday.c
Be more thorough when ensuring a file is correctly written
[thirdparty/sarg.git] / repday.c
index 0f7d40015328e104fb9a8345afc5d8b989c37e04..9a412609b0c2a3f6ce7c2519dd4a848158ec7ace 100644 (file)
--- a/repday.c
+++ b/repday.c
@@ -1,6 +1,6 @@
 /*
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
- *                                                            1998, 2010
+ *                                                            1998, 2012
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
@@ -66,7 +66,7 @@ void report_day(const struct userinfostruct *uinfo)
        }
 
        if((fp_in=fopen(wdirname,"r"))==NULL) {
-               debuga(_("(repday) Cannot open log file %s\n"),wdirname);
+               debuga(_("(repday) Cannot open log file %s: %s\n"),wdirname,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
@@ -119,7 +119,7 @@ void report_day(const struct userinfostruct *uinfo)
        fclose(fp_in);
 
        if((fp_ou=fopen(arqout,"w"))==NULL) {
-               debuga(_("(repday) Cannot open log file %s\n"),arqout);
+               debuga(_("(repday) Cannot open log file %s: %s\n"),arqout,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
@@ -140,8 +140,11 @@ void report_day(const struct userinfostruct *uinfo)
                label=_("BYTES");
                fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou);
                fputs("<tr><th class=\"header_c\"></th>",fp_ou);
-               for( i = 0; i < hours.len; i++ )
-                       fprintf(fp_ou, "<td class=\"header_c\">%02d%s<br>%s</td>\n", hours.list[ i ], _("H"), label );
+               for( i = 0; i < hours.len; i++ ) {
+                       /* TRANSLATORS: It is an hour in the hourly report */
+                       sprintf(data,_("%02dH"),hours.list[ i ]);
+                       fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td>\n", data, label );
+               }
                fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td></tr>\n", _("TOTAL"), label );
 
                memset(tttime,0,sizeof(tttime));
@@ -177,14 +180,23 @@ 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) {
                label=_("H:M:S");
                fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou);
                fputs("<tr><th class=\"header_c\"></th>",fp_ou);
-               for( i = 0; i < hours.len; i++ )
-                       fprintf(fp_ou, "<td class=\"header_c\">%02d%s<br>%s</td>\n", hours.list[ i ], _("H"), label );
+               for( i = 0; i < hours.len; i++ ) {
+                       sprintf(data,_("%02dH"),hours.list[ i ]);
+                       fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td>\n", data, label );
+               }
                fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td></tr>\n", _("TOTAL"), label );
 
                memset(tttime,0,sizeof(tttime));
@@ -220,11 +232,20 @@ 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)
                debuga(_("Write error in file %s\n"),arqout);
-       if (fclose(fp_ou)==EOF)
-               debuga(_("Failed to close file %s - %s\n"),arqout,strerror(errno));
+       if (fclose(fp_ou)==EOF) {
+               debuga(_("Write error in %s: %s\n"),arqout,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
        return;
 }