From: Frédéric Marchal Date: Wed, 12 Sep 2012 17:40:48 +0000 (+0200) Subject: Be more thorough when ensuring a file is correctly written X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=507460aefaddc24a2e53a9f4a6399098c23dc7c5;p=thirdparty%2Fsarg.git Be more thorough when ensuring a file is correctly written The return status of every written file is checked when the file is closed. Any incorrectly written file should be detected early and a proper message should be reported. --- diff --git a/auth.c b/auth.c index 9d2d03f..718dff0 100644 --- a/auth.c +++ b/auth.c @@ -61,7 +61,10 @@ void htaccess(const struct userinfostruct *uinfo) fputc(line[i],fp_auth); } } - fclose(fp_auth); + if (fclose(fp_auth)==EOF) { + debuga(_("Write error in %s: %s\n"),htname,strerror(errno)); + exit(EXIT_FAILURE); + } fclose(fp_in); return; diff --git a/authfail.c b/authfail.c index e10593f..d27e947 100644 --- a/authfail.c +++ b/authfail.c @@ -82,8 +82,7 @@ void authfail_close(void) { if (fp_authfail) { - if (fclose(fp_authfail)==EOF) - { + if (fclose(fp_authfail)==EOF) { debuga(_("Write error in %s: %s\n"),authfail_unsort,strerror(errno)); exit(EXIT_FAILURE); } @@ -272,8 +271,10 @@ void authfail_report(void) fputs("\n",fp_ou); if (write_html_trailer(fp_ou)<0) debuga(_("Write error in file %s\n"),report); - if (fclose(fp_ou)==EOF) - debuga(_("Failed to close file %s - %s\n"),report,strerror(errno)); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),report,strerror(errno)); + exit(EXIT_FAILURE); + } if (!KeepTempLog && unlink(authfail_sort)) { debuga(_("Cannot delete %s - %s\n"),authfail_sort,strerror(errno)); @@ -288,9 +289,11 @@ Remove any temporary file left by the authfail module. */ void authfail_cleanup(void) { - if (fp_authfail) - { - fclose(fp_authfail); + if (fp_authfail) { + if (fclose(fp_authfail)==EOF) { + debuga(_("Write error in %s: %s\n"),authfail_unsort,strerror(errno)); + exit(EXIT_FAILURE); + } fp_authfail=NULL; } if(authfail_unsort[0]) { diff --git a/convlog.c b/convlog.c index df75639..4b5600f 100644 --- a/convlog.c +++ b/convlog.c @@ -79,6 +79,7 @@ void convlog(const char *arq, char df, int dfrom, int duntil) longline_destroy(&line); if (fclose(fp_in)==EOF) { - debuga(_("Failed to close file %s - %s\n"),arq,strerror(errno)); + debuga(_("Failed to close file %s: %s\n"),arq,strerror(errno)); + exit(EXIT_FAILURE); } } diff --git a/dansguardian_log.c b/dansguardian_log.c index 874fa06..7af74e3 100644 --- a/dansguardian_log.c +++ b/dansguardian_log.c @@ -142,7 +142,10 @@ void dansguardian_log(void) if(fp_in) fclose(fp_in); if(fp_guard) fclose(fp_guard); - if(fp_ou) fclose(fp_ou); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s"),guard_in,strerror(errno)); + exit(EXIT_FAILURE); + } if(debug) debuga(_("Sorting file: %s\n"),guard_ou); diff --git a/dansguardian_report.c b/dansguardian_report.c index 938820a..d4e07ba 100644 --- a/dansguardian_report.c +++ b/dansguardian_report.c @@ -167,8 +167,10 @@ void dansguardian_report(void) fputs("\n",fp_ou); if (write_html_trailer(fp_ou)<0) debuga(_("Write error in file %s\n"),report); - if (fclose(fp_ou)==EOF) - debuga(_("Failed to close file %s - %s\n"),report,strerror(errno)); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),report,strerror(errno)); + exit(EXIT_FAILURE); + } if (!KeepTempLog && unlink(dansguardian_in)) { debuga(_("Cannot delete \"%s\": %s\n"),dansguardian_in,strerror(errno)); diff --git a/datafile.c b/datafile.c index b6e3998..72ea06c 100644 --- a/datafile.c +++ b/datafile.c @@ -192,7 +192,10 @@ void data_file(char *tmp) } userinfo_stopscan(uscan); if (oldurl) free(oldurl); - if (fp_ou) fclose(fp_ou); + if (fp_ou && fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),DataFile,strerror(errno)); + exit(EXIT_FAILURE); + } if(debug) debuga(_("Datafile %s written successfully\n"),DataFile); diff --git a/denied.c b/denied.c index 1eda2e9..303af0f 100644 --- a/denied.c +++ b/denied.c @@ -80,10 +80,8 @@ Close the file opened by denied_open(). */ void denied_close(void) { - if (fp_denied) - { - if (fclose(fp_denied)==EOF) - { + if (fp_denied) { + if (fclose(fp_denied)==EOF) { debuga(_("Write error in %s: %s\n"),denied_unsort,strerror(errno)); exit(EXIT_FAILURE); } @@ -271,8 +269,10 @@ void gen_denied_report(void) fputs("\n",fp_ou); if (write_html_trailer(fp_ou)<0) debuga(_("Write error in file %s\n"),report); - if (fclose(fp_ou)<0) - debuga(_("Failed to close file %s - %s\n"),report,strerror(errno)); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),report,strerror(errno)); + exit(EXIT_FAILURE); + } if (!KeepTempLog && unlink(denied_sort)==-1) debuga(_("Cannot delete \"%s\": %s\n"),denied_sort,strerror(errno)); @@ -285,9 +285,11 @@ Remove any temporary file left by the denied module. */ void denied_cleanup(void) { - if (fp_denied) - { - fclose(fp_denied); + if (fp_denied){ + if (fclose(fp_denied)==EOF) { + debuga(_("Write error in %s: %s\n"),denied_unsort,strerror(errno)); + exit(EXIT_FAILURE); + } fp_denied=NULL; } if (!KeepTempLog && denied_unsort[0]) { diff --git a/download.c b/download.c index 6028ecf..0a20cca 100644 --- a/download.c +++ b/download.c @@ -100,8 +100,7 @@ void download_close(void) { if (fp_download) { - if (fclose(fp_download)==EOF) - { + if (fclose(fp_download)==EOF) { debuga(_("Write error in %s: %s\n"),download_unsort,strerror(errno)); exit(EXIT_FAILURE); } @@ -300,8 +299,10 @@ void download_report(void) fputs("\n",fp_ou); if (write_html_trailer(fp_ou)<0) debuga(_("Write error in file %s\n"),report); - if (fclose(fp_ou)==EOF) - debuga(_("Failed to close file %s - %s\n"),report,strerror(errno)); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),report,strerror(errno)); + exit(EXIT_FAILURE); + } if (!KeepTempLog && unlink(report_in)) { debuga(_("Cannot delete \"%s\": %s\n"),report_in,strerror(errno)); @@ -445,9 +446,11 @@ Remove any temporary file left by the download module. */ void download_cleanup(void) { - if (fp_download) - { - fclose(fp_download); + if (fp_download) { + if (fclose(fp_download)==EOF) { + debuga(_("Write error in %s: %s\n"),download_unsort,strerror(errno)); + exit(EXIT_FAILURE); + } fp_download=NULL; } if (download_unsort[0]) { diff --git a/email.c b/email.c index 84a6d6c..e119cd7 100644 --- a/email.c +++ b/email.c @@ -122,7 +122,10 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema ttnelap+=tnelap; } - fclose(fp_top2); + if (fclose(fp_top2)==EOF) { + debuga(_("Write error in %s: %s\n"),top2,strerror(errno)); + exit(EXIT_FAILURE); + } #ifdef ENABLE_DOUBLE_CHECK_DATA if (ttnacc!=globstat.nacc || ttnbytes!=globstat.nbytes || ttnelap!=globstat.elap) { @@ -262,7 +265,10 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema local = localtime(&t); fprintf(fp_top3, "\n%s\n", asctime(local)); - fclose(fp_top3); + if (fclose(fp_top3)==EOF) { + debuga(_("Write error in %s: %s\n"),top3,strerror(errno)); + exit(EXIT_FAILURE); + } if(strcmp(email,"stdout") == 0) { if((fp_top3=fopen(top3,"r"))==NULL) { diff --git a/grepday.c b/grepday.c index 48ea142..0458004 100644 --- a/grepday.c +++ b/grepday.c @@ -622,7 +622,9 @@ static void greport_plot(const struct userinfostruct *uinfo,struct PlotStruct *p exit(EXIT_FAILURE); } gdImagePng(gdata.im, pngout); - fclose(pngout); + if (fclose(pngout)==EOF) { + debuga(_("Write error in %s: %s\n"),graph,strerror(errno)); + } gdImageDestroy(gdata.im); if (gdata.string) free(gdata.string); @@ -772,7 +774,7 @@ void greport_day(const struct userinfostruct *uinfo) if (write_html_trailer(fp_ou)<0) debuga(_("Write error in file %s\n"),wdirname); if (fclose(fp_ou)==EOF) - debuga(_("Failed to close file %s - %s\n"),wdirname,strerror(errno)); + debuga(_("Write error in %s: %s\n"),wdirname,strerror(errno)); #endif //HAVE_GD return; diff --git a/html.c b/html.c index 5545117..effd993 100644 --- a/html.c +++ b/html.c @@ -382,7 +382,10 @@ void htmlrel(void) longline_destroy(&line1); fclose(fp_ip); - fclose(fp_ip2); + if (fclose(fp_ip2)==EOF) { + debuga(_("Write error in %s: %s\n"),tmp2,strerror(errno)); + exit(EXIT_FAILURE); + } if (snprintf(csort,sizeof(csort),"sort -n -t \"\t\" -T \"%s\" -k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp,tmp3,tmp2)>=sizeof(csort)) { debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),tmp2,tmp3); @@ -549,7 +552,10 @@ void htmlrel(void) exit(EXIT_FAILURE); } fprintf(fp_usr,"%s\n",uinfo->label); - fclose(fp_usr); + if (fclose(fp_usr)==EOF) { + debuga(_("Write error in %s: %s\n"),PerUserLimitFile,strerror(errno)); + exit(EXIT_FAILURE); + } if(debug) debuga(_("User %s limit exceeded (%d MB). Added to file %s\n"),uinfo->label,PerUserLimit,PerUserLimitFile); @@ -584,8 +590,10 @@ void htmlrel(void) fputs("\n",fp_ou); if (write_html_trailer(fp_ou)<0) debuga(_("Write error in file %s\n"),arqou); - if (fclose(fp_ou)==EOF) - debuga(_("Failed to close file %s - %s\n"),arqou,strerror(errno)); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),arqou,strerror(errno)); + exit(EXIT_FAILURE); + } htaccess(uinfo); } diff --git a/include/conf.h b/include/conf.h index 8556c64..baf1355 100755 --- a/include/conf.h +++ b/include/conf.h @@ -300,7 +300,6 @@ char code[MAXLEN]; char code2[MAXLEN]; char tmp[MAXLEN]; char parse_out[MAXLEN]; -char arqtt[MAXLEN]; char html[MAXLEN]; char ConfigFile[MAXLEN]; char df; diff --git a/index.c b/index.c index 6b306e2..d6b0b8e 100644 --- a/index.c +++ b/index.c @@ -278,21 +278,27 @@ static void make_date_index(void) fputs("\n",fp_ou3); if (write_html_trailer(fp_ou3)<0) debuga(_("Write error in the index %s\n"),dayindex); - if (fclose(fp_ou3)==EOF) - debuga(_("Failed to close the index file %s - %s\n"),dayindex,strerror(errno)); + if (fclose(fp_ou3)==EOF) { + debuga(_("Write error in %s: %s\n"),dayindex,strerror(errno)); + exit(EXIT_FAILURE); + } } fputs("\n",fp_ou2); if (write_html_trailer(fp_ou2)<0) debuga(_("Write error in the index %s\n"),monthindex); - if (fclose(fp_ou2)==EOF) - debuga(_("Failed to close the index file %s - %s\n"),monthindex,strerror(errno)); + if (fclose(fp_ou2)==EOF) { + debuga(_("Write error in %s: %s\n"),monthindex,strerror(errno)); + exit(EXIT_FAILURE); + } } fputs("\n",fp_ou); if (write_html_trailer(fp_ou)<0) debuga(_("Write error in the index %s\n"),yearindex); - if (fclose(fp_ou)==EOF) - debuga(_("Failed to close the index file %s - %s\n"),yearindex,strerror(errno)); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),yearindex,strerror(errno)); + exit(EXIT_FAILURE); + } } static void make_file_index(void) diff --git a/lastlog.c b/lastlog.c index cb36c54..61f806b 100644 --- a/lastlog.c +++ b/lastlog.c @@ -73,7 +73,10 @@ void mklastlog(const char *outdir) } closedir( dirp ); - fclose(fp_ou); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),temp,strerror(errno)); + exit(EXIT_FAILURE); + } snprintf(buf,sizeof(buf),"sort -n -t \"\t\" -k 1,1 -o \"%slastlog\" \"%s\"",outdir,temp); cstatus=system(buf); diff --git a/readlog.c b/readlog.c index 5cee0a4..acd7bed 100644 --- a/readlog.c +++ b/readlog.c @@ -505,7 +505,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) if (ufile1->file!=NULL) { if (x>=maxopenfiles) { if (fclose(ufile1->file)==EOF) { - debuga(_("Failed to close the log file of user %s - %s\n"),ufile1->user->id,strerror(errno)); + debuga(_("Write error in the log file of user %s: %s\n"),ufile1->user->id,strerror(errno)); exit(EXIT_FAILURE); } ufile1->file=NULL; @@ -594,7 +594,10 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) char val2[40]; char val4[255];//val4 must not be bigger than arq_log without fixing the strcpy below - fclose(fp_log); + if (fclose(fp_log)==EOF) { + debuga(_("Write error in %s: %s\n"),arq_log,strerror(errno)); + exit(EXIT_FAILURE); + } safe_strcpy(end_hour,tbuf2,sizeof(end_hour)); strftime(val2,sizeof(val2),"%d%m%Y",&period.start); strftime(val1,sizeof(val1),"%d%m%Y",&period.end); @@ -634,7 +637,10 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) for (ufile=first_user_file ; ufile ; ufile=ufile1) { ufile1=ufile->next; - if (ufile->file!=NULL) fclose(ufile->file); + if (ufile->file!=NULL && fclose(ufile->file)==EOF) { + debuga(_("Write error in the log file of user %s: %s\n"),ufile->user->id,strerror(errno)); + exit(EXIT_FAILURE); + } free(ufile); } diff --git a/redirector.c b/redirector.c index c7e0b67..7415d62 100644 --- a/redirector.c +++ b/redirector.c @@ -375,7 +375,10 @@ void redirector_log(void) } if (fp_guard) fclose(fp_guard); - if (fp_ou) fclose(fp_ou); + if (fp_ou && fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),guard_in,strerror(errno)); + exit(EXIT_FAILURE); + } if (files_done) { for (y=0; y\n",fp_ou); if (write_html_trailer(fp_ou)<0) debuga(_("Write error in file %s\n"),report); - if (fclose(fp_ou)==EOF) - debuga(_("Failed to close file %s - %s\n"),report,strerror(errno)); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),report,strerror(errno)); + exit(EXIT_FAILURE); + } if (!KeepTempLog && unlink(redirector_sorted)) { debuga(_("Cannot delete \"%s\": %s\n"),redirector_sorted,strerror(errno)); diff --git a/repday.c b/repday.c index a220a7c..9a41260 100644 --- a/repday.c +++ b/repday.c @@ -243,7 +243,9 @@ void report_day(const struct userinfostruct *uinfo) 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; } diff --git a/report.c b/report.c index e46bc75..c6c604b 100644 --- a/report.c +++ b/report.c @@ -32,7 +32,10 @@ struct globalstatstruct globstat; //! \c True to enable the smart filter. bool smartfilter=false; +//! The file to store the HTML page where the time of access is reported for one site and one user. static FILE *fp_tt=NULL; +//! The name of the file containing the access time of the site/user. +static char arqtt[4096]=""; static FILE *maketmp(const char *user, const char *dirname, int debug); static void gravatmp(FILE *fp_ou, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, long long int incache, long long int oucache); @@ -57,7 +60,6 @@ void gerarel(void) char accsmart[MAXLEN]; char crc2[MAXLEN/2 -1]; char siteind[MAX_TRUNCATED_URL]; - char arqtt[256]; char *oldurltt=NULL; char oldaccdiatt[11],oldacchoratt[9]; char tmp3[MAXLEN]; @@ -337,8 +339,10 @@ void gerarel(void) day_totalize(daystat,tmp,uinfo); } if (fp_tmp) { - if (fclose(fp_tmp)==EOF) - debuga(_("Failed to close temporary file for user %s - %s\n"),uinfo->filename,strerror(errno)); + if (fclose(fp_tmp)==EOF) { + debuga(_("Failed to close temporary file for user %s: %s\n"),uinfo->filename,strerror(errno)); + exit(EXIT_FAILURE); + } fp_tmp=NULL; } if (!KeepTempLog && unlink(tmp3)) { @@ -350,7 +354,10 @@ void gerarel(void) day_cleanup(daystat); totalger(fp_gen,wdirname); - fclose(fp_gen); + if (fclose(fp_gen)==EOF) { + debuga(_("Write error in %s: %s\n"),wdirname,strerror(errno)); + exit(EXIT_FAILURE); + } if(email[0] == '\0') { if (!indexonly) { @@ -455,7 +462,10 @@ static void gravatmp(FILE *fp_ou, const char *oldurl, long long int nacc, long l if(fp_tt) { fputs("\n\n",fp_tt); fputs("\n\n",fp_tt); - fclose(fp_tt); + if (fclose(fp_tt)==EOF) { + debuga(_("Write error in %s: %s\n"),arqtt,strerror(errno)); + exit(EXIT_FAILURE); + } fp_tt=NULL; } @@ -485,7 +495,10 @@ static void gravaporuser(const struct userinfostruct *uinfo, const char *dirname */ fprintf(fp_ou,"%s\t%s\t%s\t%s\t%"PRIu64"\t%"PRIu64"\n",ip,url,data,hora,(uint64_t)tam,(uint64_t)elap); - fclose(fp_ou); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),wdirname,strerror(errno)); + exit(EXIT_FAILURE); + } return; } @@ -766,7 +779,10 @@ static void grava_SmartFilter(const char *dirname, const char *user, const char fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\n",user,data,hora,ip,url,smart); fputs("\n\n",fp_tt); - fclose(fp_ou); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),wdirname,strerror(errno)); + exit(EXIT_FAILURE); + } return; } diff --git a/siteuser.c b/siteuser.c index 69b15c1..9f354ee 100644 --- a/siteuser.c +++ b/siteuser.c @@ -189,8 +189,10 @@ void siteuser(void) fputs("\n",fp_ou); if (write_html_trailer(fp_ou)<0) debuga(_("Write error in file %s\n"),report); - if (fclose(fp_ou)==EOF) - debuga(_("Failed to close file %s - %s\n"),report,strerror(errno)); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),report,strerror(errno)); + exit(EXIT_FAILURE); + } return; } diff --git a/smartfilter.c b/smartfilter.c index 12c8c69..4fb30fe 100644 --- a/smartfilter.c +++ b/smartfilter.c @@ -46,7 +46,6 @@ void smartfilter_report(void) char smartcat[256]; char ftime[128]; char smartuser[MAXLEN]; - int fuser=0; int cstatus; struct getwordstruct gwarea; const struct userinfostruct *uinfo; @@ -132,21 +131,23 @@ void smartfilter_report(void) if(strcmp(ouser,user) != 0) { strcpy(ouser,user); sprintf(smartuser,"%s/denied_%s.html",outdirname,uinfo->filename); - if(fuser) { - fuser=0; + if (fp_user) { fputs("\n",fp_user); if(ShowSargInfo) { zdate(ftime, sizeof(ftime), df); fprintf(fp_user,"

%s %s-%s %s %s
\n",_("Generated by"),URL,PGM,VERSION,_("on"),ftime); } fputs("\n\n",fp_user); - fclose(fp_user); + if (fclose(fp_user)==EOF) { + debuga(_("Write error in %s: %s\n"),smartuser,strerror(errno)); + exit(EXIT_FAILURE); + } + fp_user=NULL; } if ((fp_user = fopen(smartuser, "a")) == 0) { debuga(_("(smartfilter) Cannot open file %s: %s\n"),smartuser,strerror(errno)); exit(EXIT_FAILURE); } - fuser=1; fputs("\n",fp_ou); @@ -196,7 +197,10 @@ void smartfilter_report(void) fputs("\n\n",fp_user); - fclose(fp_ou); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),report,strerror(errno)); + exit(EXIT_FAILURE); + } if(fp_user) { fputs("\n",fp_user); if(ShowSargInfo) { @@ -204,7 +208,10 @@ void smartfilter_report(void) fprintf(fp_user,"

%s %s-%s %s %s
\n",_("Generated by"),URL,PGM,VERSION,_("on"),ftime); } fputs("\n\n",fp_user); - fclose(fp_user); + if (fclose(fp_user)==EOF) { + debuga(_("Write error in %s: %s\n"),smartuser,strerror(errno)); + exit(EXIT_FAILURE); + } } if (!KeepTempLog && unlink(smart_ou)) { diff --git a/splitlog.c b/splitlog.c index 5cd55ef..07685ba 100644 --- a/splitlog.c +++ b/splitlog.c @@ -109,7 +109,7 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons prev_month=t->tm_mon; prev_day=t->tm_mday; if (fp_ou && fclose(fp_ou)==EOF) { - debuga(_("Failed to close file %s - %s\n"),output_file,strerror(errno)); + debuga(_("Write error in %s: %s\n"),output_file,strerror(errno)); exit(EXIT_FAILURE); } strftime(output_file+output_prefix_len, sizeof(output_file)-output_prefix_len, "-%Y-%m-%d", t); @@ -144,7 +144,7 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons } if (autosplit && fp_ou) { if (fclose(fp_ou)==EOF) { - debuga(_("Failed to close file %s - %s\n"),output_file,strerror(errno)); + debuga(_("Write error in %s: %s\n"),output_file,strerror(errno)); exit(EXIT_FAILURE); } } diff --git a/topsites.c b/topsites.c index f57bdf3..7d5eb65 100644 --- a/topsites.c +++ b/topsites.c @@ -172,7 +172,10 @@ void topsites(void) free(ourl); } - fclose(fp_ou); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),general3,strerror(errno)); + exit(EXIT_FAILURE); + } #ifdef ENABLE_DOUBLE_CHECK_DATA if (ttnacc!=globstat.nacc || ttnbytes!=globstat.nbytes || ttntime!=globstat.elap) { @@ -317,8 +320,10 @@ void topsites(void) fputs("\n",fp_ou); if (write_html_trailer(fp_ou)<0) debuga(_("Write error in file %s\n"),report); - if (fclose(fp_ou)==EOF) - debuga(_("Failed to close file %s - %s\n"),report,strerror(errno)); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),report,strerror(errno)); + exit(EXIT_FAILURE); + } return; } diff --git a/topuser.c b/topuser.c index 2fa4c05..8129f74 100644 --- a/topuser.c +++ b/topuser.c @@ -47,8 +47,10 @@ static void set_total_users(int totuser) exit(EXIT_FAILURE); } fprintf(fp_ou,"%d\n",totuser); - if (fclose(fp_ou)==EOF) - debuga(_("Failed to close file %s - %s\n"),tusr,strerror(errno)); + if (fclose(fp_ou)==EOF) { + debuga(_("Write error in %s: %s\n"),tusr,strerror(errno)); + exit(EXIT_FAILURE); + } globstat.totuser=totuser; } @@ -152,7 +154,10 @@ void topuser(void) ttnincache+=tnincache; ttnoucache+=tnoucache; } - fclose(fp_top2); + if (fclose(fp_top2)==EOF) { + debuga(_("Write error in %s: %s\n"),top2,strerror(errno)); + exit(EXIT_FAILURE); + } #ifdef ENABLE_DOUBLE_CHECK_DATA if (ttnacc!=globstat.nacc || ttnbytes!=globstat.nbytes || ttnelap!=globstat.elap || @@ -247,7 +252,10 @@ void topuser(void) if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) { fputs("\n\n",fp_top3); - fclose (fp_top3); + if (fclose (fp_top3)==EOF) { + debuga(_("Write error in %s: %s\n"),top3,strerror(errno)); + exit(EXIT_FAILURE); + } if (debugz) debugaz(_("No top users report because it is not configured in report_type\n")); return; } @@ -480,8 +488,10 @@ void topuser(void) fputs("\n",fp_top3); if (write_html_trailer(fp_top3)<0) debuga(_("Write error in top user list %s\n"),top3); - if (fclose(fp_top3)==EOF) - debuga(_("Failed to close the top user list %s - %s\n"),top3,strerror(errno)); + if (fclose(fp_top3)==EOF) { + debuga(_("Write error in %s: %s\n"),top3,strerror(errno)); + exit(EXIT_FAILURE); + } return; } diff --git a/totday.c b/totday.c index 223a8e0..cadebeb 100644 --- a/totday.c +++ b/totday.c @@ -178,7 +178,7 @@ void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct * } if (fclose(fp_ou)==EOF) { - debuga(_("Failed to close file %s - %s\n"),arqout,strerror(errno)); + debuga(_("Write error in %s: %s\n"),arqout,strerror(errno)); exit(EXIT_FAILURE); } return; diff --git a/useragent.c b/useragent.c index 0fcd6df..1254da4 100644 --- a/useragent.c +++ b/useragent.c @@ -124,7 +124,7 @@ void useragent(void) fclose(fp_in); if (fclose(fp_ou)==EOF) { - debuga(_("Failed to close file %s - %s\n"),tmp3,strerror(errno)); + debuga(_("Write error in %s: %s\n"),tmp3,strerror(errno)); exit(EXIT_FAILURE); } @@ -275,7 +275,7 @@ void useragent(void) fclose(fp_in); if (fclose(fp_ou)==EOF) { - debuga(_("Failed to close file %s - %s\n"),tmp3,strerror(errno)); + debuga(_("Write error in %s: %s\n"),tmp3,strerror(errno)); exit(EXIT_FAILURE); } @@ -330,8 +330,10 @@ void useragent(void) fputs("\n",fp_ht); if (write_html_trailer(fp_ht)<0) debuga(_("Write error in file %s\n"),hfile); - if (fclose(fp_ht)==EOF) - debuga(_("Failed to close file %s - %s\n"),hfile,strerror(errno)); + if (fclose(fp_ht)==EOF) { + debuga(_("Write error in %s: %s\n"),hfile,strerror(errno)); + exit(EXIT_FAILURE); + } if (!KeepTempLog && unlink(tmp3)) { debuga(_("Cannot delete \"%s\": %s\n"),tmp3,strerror(errno)); diff --git a/util.c b/util.c index ba11101..6f13722 100644 --- a/util.c +++ b/util.c @@ -1055,7 +1055,10 @@ static void copy_images(void) break; } } - fclose(img_ou); + if (fclose(img_ou)==EOF) { + debuga(_("Error while copying image %s: %s\n"),dstfile,strerror(errno)); + exit(EXIT_FAILURE); + } } else fprintf(stderr,"SARG: (util): %s %s: %s\n", _("Cannot open file")?_("Cannot open file"):"Can't open/create file", dstfile, strerror(errno)); fclose(img_in); @@ -1202,8 +1205,7 @@ int vrfydir(const struct periodstruct *per1, const char *addr, const char *site, exit(EXIT_FAILURE); } if (fclose(fp_ou)==EOF) { - debuga(_("Failed to write the date in %s\n"),wdir); - perror("SARG:"); + debuga(_("Failed to write the date in %s: %s\n"),wdir,strerror(errno)); exit(EXIT_FAILURE); } @@ -1480,7 +1482,7 @@ void removetmp(const char *outdir) } totalger(fp_gen,filename); if (fclose(fp_gen)==EOF) { - debuga(_("Failed to close %s after writing the total line - %s\n"),filename,strerror(errno)); + debuga(_("Failed to close %s after writing the total line: %s\n"),filename,strerror(errno)); exit(EXIT_FAILURE); } }