]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Be more thorough when ensuring a file is correctly written
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 12 Sep 2012 17:40:48 +0000 (19:40 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 12 Sep 2012 17:40:48 +0000 (19:40 +0200)
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.

26 files changed:
auth.c
authfail.c
convlog.c
dansguardian_log.c
dansguardian_report.c
datafile.c
denied.c
download.c
email.c
grepday.c
html.c
include/conf.h
index.c
lastlog.c
readlog.c
redirector.c
repday.c
report.c
siteuser.c
smartfilter.c
splitlog.c
topsites.c
topuser.c
totday.c
useragent.c
util.c

diff --git a/auth.c b/auth.c
index 9d2d03fd914a7b128dd63f0da62d5aa86e0fd699..718dff08cfab7c0adbad40dd56d597acf19e5c4c 100644 (file)
--- 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;
index e10593fdbe9f982bc14e7ebf5818cae38d111685..d27e9473c1804db30eca774240e42d6de1d369a2 100644 (file)
@@ -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("</table></div>\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]) {
index df75639b4a56495eb212a8db0fe26b5e9e6f6356..4b5600f4436bafde7fa0d2d190b326f6b655f72c 100644 (file)
--- 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);
        }
 }
index 874fa06dc12c4d7ab908a9fbfbc51368ef3322e8..7af74e33f9374b713ac196ec629dfbe22b712e51 100644 (file)
@@ -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);
index 938820a925e72ad59cbe964f325f40ef886c9dab..d4e07ba39a962cd47d9b96549465ff50184e558b 100644 (file)
@@ -167,8 +167,10 @@ void dansguardian_report(void)
        fputs("</table></div>\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));
index b6e399822434776dd81c524e8b105a3ab443b546..72ea06ca88831340a15afb3d01028c1eb5fc53e3 100644 (file)
@@ -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);
index 1eda2e9efa9dfd6cbd6ab97681f6d535d0a33f17..303af0f67c423cdbdef066e65a5f7e68ddf6b2f6 100644 (file)
--- 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("</table></div>\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]) {
index 6028ecf5aac254a917d013e84dc7ae81ec5b2b3a..0a20cca630d08af328309985966b401234cefe16 100644 (file)
@@ -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("</table></div>\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 84a6d6c5e2475056b516f1fdb7f37ede2078b050..e119cd76561aa73b2b3c1768ffa6b66afb02c5a5 100644 (file)
--- 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) {
index 48ea14297b6edb9c6e366591e777a189e0c9b062..04580044a026978e980952ce3a165d84bea56b1c 100644 (file)
--- 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 55451173a3ae6717cb2ac27f016265d98f4bb570..effd993ca7218dca21850ebf27ab9eb5947ea724 100644 (file)
--- 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("</table></div>\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);
        }
index 8556c64bbf79022e1bf27d8ac8de45da925546be..baf13558992c43c96aa646330b7f5dd565fe027c 100755 (executable)
@@ -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 6b306e295f92d173bfc2597afd61a1ebbd3d15dd..d6b0b8e155cb54b4cef7a7f96e08d5c4d4793f55 100644 (file)
--- a/index.c
+++ b/index.c
@@ -278,21 +278,27 @@ static void make_date_index(void)
                        fputs("</table></div>\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("</table></div>\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("</table></div>\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)
index cb36c5410adcd98301c43dbef1ba224e815134ee..61f806b7e39dcf6a0f92091b569219b81d616353 100644 (file)
--- 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);
index 5cee0a462c4c1a0ffc37ba4a6b49cd8044a8e2c7..acd7bed9f5b39f21d4b81ec84b2b81a3e2eefeb1 100644 (file)
--- 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);
        }
 
index c7e0b678a74f7ab6e5a31c10312b83e8e389fbb6..7415d624fe785b88e6b505fa9714a99fa73f5bff 100644 (file)
@@ -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<nfiles_done; y++)
@@ -575,8 +578,10 @@ void redirector_report(void)
        fputs("</div>\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));
index a220a7c79c4532f536767a9ea9543ec01faff78c..9a412609b0c2a3f6ce7c2519dd4a848158ec7ace 100644 (file)
--- 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;
 }
index e46bc750ab7c1d68013595b648d0f02fba1b5043..c6c604bf884fd851699b837a6ec71e22a9835526 100644 (file)
--- 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("</table>\n</div>\n",fp_tt);
                fputs("</body>\n</html>\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("</body>\n</html>\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;
 }
index 69b15c1a2c058f3ad2be41037328be17001eb57b..9f354ee45476243409408ecf543c912bea0274f9 100644 (file)
@@ -189,8 +189,10 @@ void siteuser(void)
        fputs("</table></div>\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;
 }
index 12c8c69f5ca8d78064414f4f3b807696a5a1ea06..4fb30feea602e6e0cae8a65a3fe2c698c25ca512 100644 (file)
@@ -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("</table>\n",fp_user);
                                if(ShowSargInfo) {
                                        zdate(ftime, sizeof(ftime), df);
                                        fprintf(fp_user,"<br><br><div align=\"center\"><font size=\"-2\">%s <a href=\"%s\">%s-%s</a> %s %s</font></div>\n",_("Generated by"),URL,PGM,VERSION,_("on"),ftime);
                                }
                                fputs("</body>\n</html>\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("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou);
                        fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou);
@@ -196,7 +197,10 @@ void smartfilter_report(void)
 
        fputs("</body>\n</html>\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("</table>\n",fp_user);
                if(ShowSargInfo) {
@@ -204,7 +208,10 @@ void smartfilter_report(void)
                        fprintf(fp_user,"<br><br><div align=\"center\"><font size=\"-2\">%s <a href=\"%s\">%s-%s</a> %s %s</font></div>\n",_("Generated by"),URL,PGM,VERSION,_("on"),ftime);
                }
                fputs("</body>\n</html>\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)) {
index 5cd55ef5ab1abed0e3b9b4dafa6cf085fca9957c..07685bafa47515071287f4b1dc0507018821ca22 100644 (file)
@@ -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);
                }
        }
index f57bdf35166c234b737d0c41c20ee23f578c8d63..7d5eb6579bdff64ae949f40124f742e4857ca135 100644 (file)
@@ -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("</table></div>\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;
 }
index 2fa4c0578c70f58c206bb53de7c440c4d1b3ede6..8129f745cbf860d8b65bf527328309ac2392229e 100644 (file)
--- 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("</body>\n</html>\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("</table></div>\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;
 }
index 223a8e0afccae2c1bc655b639dda94c23e8180a3..cadebeb8a7f732b6662732f7b9ec4ee0cbfd5b79 100644 (file)
--- 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;
index 0fcd6dff7a451dc1a90c57eb1b03725b2104182a..1254da4c2ad0d7655cf291c8f1adeef8b4247054 100644 (file)
@@ -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("</table></div>\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 ba111013a0119645d98bbd19d80b920075918c40..6f13722e3c501ccd8751026652097d6f36dbc0f5 100644 (file)
--- 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);
        }
 }