]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Check for the return code when deleting a file
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Dec 2010 18:29:38 +0000 (18:29 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Dec 2010 18:29:38 +0000 (18:29 +0000)
Most of the calls to unlink are checked to report an error if the file
cannot be deleted.

The calls that are not checked are call where the file may not exists
and it might not be desirable to abort the process for such an error.

21 files changed:
authfail.c
dansguardian_log.c
dansguardian_report.c
denied.c
download.c
email.c
grepday.c
html.c
index.c
lastlog.c
log.c
realtime.c
report.c
siteuser.c
smartfilter.c
sort.c
squidguard_log.c
squidguard_report.c
topsites.c
topuser.c
useragent.c

index 434bb47f4bbcfc80f19ff298ffbe0a72009d39b7..6e411692c0c32d625f8aeee2b59e9c34cea2a8b6 100644 (file)
@@ -82,7 +82,10 @@ void authfail_report(void)
                debuga(_("sort command: %s\n"),csort);
                exit(EXIT_FAILURE);
        }
-       unlink(tmp4);
+       if (unlink(tmp4)) {
+               debuga(_("Cannot delete %s - %s\n"),tmp4,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
                debuga(_("(authfail) Cannot open file %s\n"),report);
@@ -190,7 +193,10 @@ void authfail_report(void)
        if (fclose(fp_ou)==EOF)
                debuga(_("Failed to close file %s - %s\n"),report,strerror(errno));
 
-       unlink(authfail_in);
+       if (unlink(authfail_in)) {
+               debuga(_("Cannot delete %s - %s\n"),authfail_in,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        return;
 }
index a90367efb6c8a7a6d5ed2c277af1665f5a78fef0..9f5ba8c1e2416ef87b897862e468a8119cce0dc4 100644 (file)
@@ -139,5 +139,8 @@ void dansguardian_log(void)
                debuga(_("sort command: %s\n"),tmp6);
                exit(EXIT_FAILURE);
        }
-       unlink(guard_in);
+       if (unlink(guard_in)) {
+               debuga(_("Cannot delete %s - %s\n"),guard_in,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 }
index 0ff685fd5e808c8a6858d46ec813e0a904a1faea..2d8aa37bea74d28e06f1857b1bcbabb01923e1d5 100644 (file)
@@ -157,7 +157,10 @@ void dansguardian_report(void)
        if (fclose(fp_ou)==EOF)
                debuga(_("Failed to close file %s - %s\n"),report,strerror(errno));
 
-       unlink(dansguardian_in);
+       if (unlink(dansguardian_in)) {
+               debuga(_("Cannot delete %s - %s\n"),dansguardian_in,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        return;
 }
index bf6bf561d18a3839094ca0010eadb75fc862c66b..30e41a1ec6e57accdd36b7f0886e2ffefe1938e7 100644 (file)
--- a/denied.c
+++ b/denied.c
@@ -63,7 +63,7 @@ void gen_denied_report(void)
        ouser2[0]='\0';
 
        sprintf(denied_in,"%s/denied.log",tmp);
-       if(!denied_count) {
+       if (!denied_count) {
                unlink(denied_in);
                return;
        }
index a490952768af8248a167ca05f14bccab854f01b5..be4665bd28bac1aa4e72d4b00f4d1d1c2f63fe58 100644 (file)
@@ -166,7 +166,10 @@ void download_report(void)
        if (fclose(fp_ou)==EOF)
                debuga(_("Failed to close file %s - %s\n"),report,strerror(errno));
 
-       unlink(report_in);
+       if (unlink(report_in)) {
+               debuga(_("Cannot delete %s - %s\n"),report_in,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        return;
 }
diff --git a/email.c b/email.c
index 704d4e163f58a52e7bc84e0971c6eacfb8d93373..a0dbe61aaac0079b2adf1bd97523363120c0dbb5 100644 (file)
--- a/email.c
+++ b/email.c
@@ -127,7 +127,10 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema
                exit(EXIT_FAILURE);
        }
 
-       unlink(top2);
+       if (unlink(top2)) {
+               debuga(_("Cannot delete %s - %s\n"),top2,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        if((fp_top1=fopen(top1,"r"))==NULL) {
                debuga(_("(email) Cannot open file %s\n"),top1);
@@ -235,7 +238,10 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema
 #endif
 
        fclose(fp_top1);
-       unlink(top1);
+       if (unlink(top1)) {
+               debuga(_("Cannot delete %s - %s\n"),top1,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        t = time(NULL);
        local = localtime(&t);
index 3be390bf11f582fc3d9fd2f9a1ee20f846d880b6..ed3de6f67eaea0cfac168a6e8f4139e8fcf945e2 100644 (file)
--- a/grepday.c
+++ b/grepday.c
@@ -713,7 +713,10 @@ void greport_day(const struct userinfostruct *uinfo)
                }
        }
        fclose(fp_in);
-       unlink(wdirname);
+       if (unlink(wdirname)) {
+               debuga(_("Cannot delete %s - %s\n"),wdirname,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        if (snprintf(wdirname,sizeof(wdirname),"%s/%s/graph.html",outdirname,uinfo->filename)>=sizeof(wdirname)) {
                debuga(_("user name too long for %s/%s/%s\n"),outdirname,uinfo->filename,"graph.html");
diff --git a/html.c b/html.c
index 75702648c521f516c2aa0cea0362d32359f55892..5918c4b594f10bc38214b79bcf5b5f496aa0176b 100644 (file)
--- a/html.c
+++ b/html.c
@@ -480,8 +480,14 @@ void htmlrel(void)
                                fclose(fp_ip);
                                longline_destroy(&line1);
 
-                               unlink(tmp2);
-                               unlink(tmp3);
+                               if (unlink(tmp2)) {
+                                       debuga(_("Cannot delete %s - %s\n"),tmp2,strerror(errno));
+                                       exit(EXIT_FAILURE);
+                               }
+                               if (unlink(tmp3)) {
+                                       debuga(_("Cannot delete %s - %s\n"),tmp3,strerror(errno));
+                                       exit(EXIT_FAILURE);
+                               }
 
                                if (olduserip[0]!='\0') {
                                        fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td>",olduserip);
@@ -509,9 +515,16 @@ void htmlrel(void)
                fclose(fp_in);
                longline_destroy(&line);
 
-               if(iprel)
-                       unlink(arqip);
-               unlink(arqin);
+               if (iprel) {
+                       if (unlink(arqip)) {
+                               debuga(_("Cannot delete %s - %s\n"),arqip,strerror(errno));
+                               exit(EXIT_FAILURE);
+                       }
+               }
+               if (unlink(arqin)) {
+                       debuga(_("Cannot delete %s - %s\n"),arqin,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
 
                if ((UserReportFields & (USERREPORTFIELDS_TOTAL | USERREPORTFIELDS_AVERAGE)) != 0)
                        fputs("<tfoot>",fp_ou);
diff --git a/index.c b/index.c
index 9350422a81141945de3ceda53262788cadaedea0..3420369a92bdaa695bebaa8825871b99213ea875 100644 (file)
--- a/index.c
+++ b/index.c
@@ -42,7 +42,12 @@ void make_index(void)
 
        if(Index == INDEX_NO) {
                sprintf(wdir,"%sindex.html",outdir);
-               if(access(wdir, R_OK) == 0) unlink(wdir);
+               if(access(wdir, R_OK) == 0) {
+                       if (unlink(wdir)) {
+                               debuga(_("Cannot delete %s - %s\n"),wdir,strerror(errno));
+                               exit(EXIT_FAILURE);
+                       }
+               }
                return;
        }
 
index 8b71d0504e72349dae4e0ff2bf2f4269fef26b76..83ff3fc41a150412c046566ced8658c92ad56cea 100644 (file)
--- a/lastlog.c
+++ b/lastlog.c
@@ -83,12 +83,19 @@ void mklastlog(const char *outdir)
                exit(EXIT_FAILURE);
        }
 
-       unlink(temp);
+       if (unlink(temp)) {
+               debuga(_("Cannot delete %s - %s\n"),temp,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        if(ftot<=LastLog) {
                snprintf(temp,sizeof(temp),"%slastlog",outdir);
-               if(access(temp, R_OK) == 0)
-                       unlink(temp);
+               if(access(temp, R_OK) == 0) {
+                       if (unlink(temp)) {
+                               debuga(_("Cannot delete %s - %s\n"),temp,strerror(errno));
+                               exit(EXIT_FAILURE);
+                       }
+               }
                return;
        }
 
diff --git a/log.c b/log.c
index 2f115f24ef09223d21d3542f6b0018550b1d305d..c93f7950b3684c8e1027b9c48490c76180c2befc 100644 (file)
--- a/log.c
+++ b/log.c
@@ -1654,7 +1654,10 @@ int main(int argc,char *argv[])
                        debuga(_("sort command: %s\n"),csort);
                        exit(EXIT_FAILURE);
                }
-               unlink(denied_unsort);
+               if (unlink(denied_unsort)) {
+                       debuga(_("Cannot delete %s - %s\n"),denied_unsort,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
        }
 
        sort_users_log(tmp, debug);
@@ -1664,8 +1667,9 @@ int main(int argc,char *argv[])
        else
                gerarel();
 
-       if((ReportType & REPORT_TYPE_DENIED) != 0)
+       if((ReportType & REPORT_TYPE_DENIED) != 0) {
                unlink(denied_sort);
+       }
 
        if(strcmp(tmp,"/tmp") != 0) {
                unlinkdir(tmp,0);
index 6dc382cc723c8c5fdd581e7c55d1f5249ee5b908..a38375ec6e9b2ccb7e5f9d3e003110d1cf160604 100755 (executable)
@@ -86,7 +86,10 @@ static void getlog(void)
                debuga(_("sort command: %s\n"),cmd);
                exit(EXIT_FAILURE);
        }
-       unlink(template1);
+       if (unlink(template1)) {
+               debuga(_("Cannot delete %s - %s\n"),template1,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
        datashow(template2);
 }
 
@@ -268,7 +271,10 @@ static void datashow(const char *tmp)
 
        puts("</table>\n</div>\n</body>\n</html>\n");
        fclose(fin);
-       unlink(tmp);
+       if (unlink(tmp)) {
+               debuga(_("Cannot delete %s - %s\n"),tmp,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
        fflush(NULL);
 }
 
index 8b90ed3b3fef5b7035d3f5928c430523eb51b026..01b1dbc7798c4360a59f6c8f07ee4cfb00af9fd4 100644 (file)
--- a/report.c
+++ b/report.c
@@ -323,7 +323,10 @@ void gerarel(void)
                fclose(fp_in);
                longline_destroy(&line);
                if (oldurltt) free(oldurltt);
-               unlink(tmp3);
+               if (unlink(tmp3)) {
+                       debuga(_("Cannot delete %s - %s\n"),tmp3,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
        }
        userinfo_stopscan(uscan);
 
index a22f14ff33d2615b29d5ce69b914f232468e8c20..1becea9cdbef5763d1d1b80a11ba207ce7795bba 100644 (file)
@@ -213,7 +213,10 @@ void siteuser(void)
        }
        if (ourl) free(ourl);
 
-       unlink(general2);
+       if (unlink(general2)) {
+               debuga(_("Cannot delete %s - %s\n"),general2,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        fputs("</table></div>\n",fp_ou);
        if (write_html_trailer(fp_ou)<0)
index a34b79731485477f4ad09f8d074f10656ccbb3cc..71c83215f566e8c7370196bbb3b26e5be3317e98 100644 (file)
@@ -77,7 +77,10 @@ void smartfilter_report(void)
                debuga(_("sort command: %s\n"),csort);
                exit(EXIT_FAILURE);
        }
-       unlink(smart_in);
+       if (unlink(smart_in)) {
+               debuga(_("Cannot delete %s - %s\n"),smart_in,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        if((fp_ou=fopen(report,"w"))==NULL) {
                debuga(_("(smartfilter) Cannot open log file %s\n"),report);
diff --git a/sort.c b/sort.c
index 0b229a525433bfa981bb9eab27ae8f9eea334b84..e41f9a2bc13d9849317f7172e7ae53a847ce6182 100644 (file)
--- a/sort.c
+++ b/sort.c
@@ -87,7 +87,10 @@ void tmpsort(void)
                        debuga(_("sort command: %s\n"),csort);
                        exit(EXIT_FAILURE);
                }
-               unlink(arqin);
+               if (unlink(arqin)) {
+                       debuga(_("Cannot delete %s - %s\n"),arqin,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
        }
 
        userinfo_stopscan(uscan);
@@ -150,7 +153,10 @@ void sort_users_log(const char *tmp, int debug)
                        debuga(_("user name too long for %s/%s.unsort\n"),tmp,user);
                        exit(EXIT_FAILURE);
                }
-               unlink(wdname);
+               if (unlink(wdname)) {
+                       debuga(_("Cannot delete %s - %s\n"),wdname,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
        }
        (void)closedir( dirp );
 
index 4c0d7a53757a0555bc6c2ce1d61ce5969141b728..c13ad8a823fba0ef4e7e500b30b2aff26d2cef06 100644 (file)
@@ -383,6 +383,9 @@ void squidguard_log(void)
                exit(EXIT_FAILURE);
        }
 
-       unlink(guard_in);
+       if (unlink(guard_in)) {
+               debuga(_("Cannot delete %s - %s\n"),guard_in,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
        return;
 }
index 8f3dc7eb6a5188a915776b14471d0d60097b1ae1..8e2b8619fe19301cb952eb2da955a53d53396eee 100644 (file)
@@ -176,7 +176,10 @@ void squidguard_report(void)
        if (fclose(fp_ou)==EOF)
                debuga(_("Failed to close file %s - %s\n"),report,strerror(errno));
 
-       unlink(squidguard_in);
+       if (unlink(squidguard_in)) {
+               debuga(_("Cannot delete %s - %s\n"),squidguard_in,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        return;
 }
index 744cbd7630112d4a12ffe7269672eae1926165ba..950efdbcc8b0147f678bf02cab5099fb0aced268 100644 (file)
@@ -138,7 +138,10 @@ void topsites(void)
                tntime+=item.nelap;
        }
        fclose(fp_in);
-       unlink(general2);
+       if (unlink(general2)) {
+               debuga(_("Cannot delete %s - %s\n"),general2,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
        longline_destroy(&line);
 
        if (ourl) {
@@ -180,8 +183,10 @@ void topsites(void)
                exit(EXIT_FAILURE);
        }
 
-       unlink(general2);
-       unlink(general3);
+       if (unlink(general3)) {
+               debuga(_("Cannot delete %s - %s\n"),general3,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        if((fp_ou=fopen(report,"w"))==NULL) {
                debuga(_("(topsites) Cannot open log file %s\n"),report);
index b2a3e4329bbd6801a83220d9f796f49a9a2c43d4..01a32d70a811bf5a984cc4309988bf81d4be5e10 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -168,7 +168,10 @@ void topuser(void)
                exit(EXIT_FAILURE);
        }
 
-       unlink(top2);
+       if (unlink(top2)) {
+               debuga(_("Cannot delete %s - %s\n"),top2,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        snprintf(top3,sizeof(top3),"%s/index.html",outdirname);
        if((fp_top3=fopen(top3,"w"))==NULL) {
@@ -303,7 +306,10 @@ void topuser(void)
                        fprintf(fp_top3,"<a href=\"%s/d%s.html\"><img src=\"%s/datetime.png\" title=\"%s\" alt=\"T\"></a></td>",uinfo->filename,uinfo->filename,ImageFile,_("date/time report"));
                } else {
                        sprintf(val1,"%s/d%s.html",outdirname,uinfo->filename);
-                       unlink(val1);
+                       if (unlink(val1)) {
+                               debuga(_("Cannot delete %s - %s\n"),val1,strerror(errno));
+                               exit(EXIT_FAILURE);
+                       }
                }
                if((TopUserFields & TOPUSERFIELDS_USERID) != 0) {
                        if((ReportType & REPORT_TYPE_USERS_SITES) == 0)
@@ -355,7 +361,10 @@ void topuser(void)
                topcount++;
        }
        fclose(fp_top1);
-       unlink(top1);
+       if (unlink(top1)) {
+               debuga(_("Cannot delete %s - %s\n"),top1,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
        longline_destroy(&line);
 
        if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) {
index 144d2367e4a9f54fc594b9465c210e36768e003d..76c6123e02f6a83352822d700d2bba31ffaf7f7e 100644 (file)
@@ -145,7 +145,10 @@ void useragent(void)
                exit(EXIT_FAILURE);
        }
 
-       unlink(tmp3);
+       if (unlink(tmp3)) {
+               debuga(_("Cannot delete %s - %s\n"),tmp3,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        snprintf(hfile,sizeof(hfile),"%s/useragent.html", outdirname);
        if((fp_ht=fopen(hfile,"w"))==NULL) {
@@ -222,7 +225,10 @@ void useragent(void)
                exit(EXIT_FAILURE);
        }
 
-       unlink(tmp2);
+       if (unlink(tmp2)) {
+               debuga(_("Cannot delete %s - %s\n"),tmp2,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        if((fp_ou=fopen(tmp2,"w"))==NULL) {
                debuga(_("(useragent) Cannot open file %s\n"),tmp2);
@@ -267,7 +273,10 @@ void useragent(void)
                exit(EXIT_FAILURE);
        }
 
-       unlink(tmp3);
+       if (unlink(tmp3)) {
+               debuga(_("Cannot delete %s - %s\n"),tmp3,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        sprintf(csort,"sort -n -r -k 1,1 -o \"%s\" \"%s\"",tmp3,tmp2);
        cstatus=system(csort);
@@ -282,7 +291,10 @@ void useragent(void)
                exit(EXIT_FAILURE);
        }
 
-       unlink(tmp2);
+       if (unlink(tmp2)) {
+               debuga(_("Cannot delete %s - %s\n"),tmp2,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        fputs("<br><br>\n",fp_ht);
 
@@ -312,7 +324,10 @@ void useragent(void)
        if (fclose(fp_ht)==EOF)
                debuga(_("Failed to close file %s - %s\n"),hfile,strerror(errno));
 
-       unlink(tmp3);
+       if (unlink(tmp3)) {
+               debuga(_("Cannot delete %s - %s\n"),tmp3,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        return;
 }