]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Don't abort if topusers is not in report_type
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Fri, 22 Jul 2011 08:19:14 +0000 (08:19 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Fri, 22 Jul 2011 08:19:14 +0000 (08:19 +0000)
If topusers is not set in report_type, sarg fails with a message indicating
that it can't open sarg-users.

This is expected as the file is not created if the top users list is not
generated.

Thanks to Peter for reporting this bug.

html.c

diff --git a/html.c b/html.c
index aa08c02928744f2c51d829967c994f3920466228..e7493854c24e94c0dc902897c669c9c9cd5b633a 100644 (file)
--- a/html.c
+++ b/html.c
@@ -37,7 +37,7 @@ void htmlrel(void)
        long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0;
        long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0;
        long long int ltemp;
-       long long int ntotuser;
+       long long int ntotuser=1;
        long long int userbytes, userelap;
        char *buf;
        char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN];
@@ -74,18 +74,20 @@ void htmlrel(void)
        totbytes=globstat.nbytes;
        totelap=globstat.elap;
 
-       snprintf(arqper,sizeof(arqper),"%s/sarg-users",outdirname);
-       if ((fp_in = fopen(arqper, "r")) == 0){
-               debuga(_("(html11) Cannot open file %s\n"),arqper);
-               exit(EXIT_FAILURE);
-       }
-       if (!fgets(totuser,sizeof(totuser),fp_in)) {
-               debuga(_("(html11) read error in %s\n"),arqper);
-               exit(EXIT_FAILURE);
+       if ((ReportType & REPORT_TYPE_TOPUSERS) != 0) {
+               snprintf(arqper,sizeof(arqper),"%s/sarg-users",outdirname);
+               if ((fp_in = fopen(arqper, "r")) == 0){
+                       debuga(_("(html11) Cannot open file %s - %s\n"),arqper,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
+               if (!fgets(totuser,sizeof(totuser),fp_in)) {
+                       debuga(_("(html11) read error in %s\n"),arqper);
+                       exit(EXIT_FAILURE);
+               }
+               fclose(fp_in);
+               ntotuser=my_atoll(totuser);
+               if (ntotuser<=0) ntotuser=1;
        }
-       fclose(fp_in);
-       ntotuser=my_atoll(totuser);
-       if (ntotuser<=0) ntotuser=1;
 
        greport_prepare();