From: Frédéric Marchal Date: Fri, 22 Jul 2011 08:19:14 +0000 (+0000) Subject: Don't abort if topusers is not in report_type X-Git-Tag: v2.3.2~31 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a7421b06d19b6613a1d4acf0a3e7730cd879cb18;p=thirdparty%2Fsarg.git Don't abort if topusers is not in report_type 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. --- diff --git a/html.c b/html.c index aa08c02..e749385 100644 --- 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();