From: Frederic Marchal Date: Sun, 15 Jun 2014 14:44:56 +0000 (+0200) Subject: Help in diagnosing the number of old reports to keep X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0428e5fd501028bb9f48550a738f428d88dc95ba;p=thirdparty%2Fsarg.git Help in diagnosing the number of old reports to keep The lastlog and lastlog1 files are stored in the temporary directory instead of the output directory and they are not deleted when sarg exits if the user asked not to delete temporary files. Some debug messages give indication about what is happening with respect to the old reports deletion. --- diff --git a/lastlog.c b/lastlog.c index 09a079e..8334b2c 100644 --- a/lastlog.c +++ b/lastlog.c @@ -1,6 +1,6 @@ /* * SARG Squid Analysis Report Generator http://sarg.sourceforge.net - * 1998, 2013 + * 1998, 2014 * * SARG donations: * please look at http://sarg.sourceforge.net/donations.php @@ -46,7 +46,10 @@ void mklastlog(const char *outdir) if(LastLog <= 0) return; - snprintf(temp,sizeof(temp),"%slastlog1",outdir); + if (snprintf(temp,sizeof(temp),"%s/lastlog1",tmp)>=sizeof(temp)) { + debuga(_("File name too long: %s/lastlog1\n"),tmp); + exit(EXIT_FAILURE); + } if((fp_ou=fopen(temp,"w"))==NULL) { debuga(_("(lastlog) Cannot open temporary file %s: %s\n"),temp,strerror(errno)); exit(EXIT_FAILURE); @@ -78,7 +81,22 @@ void mklastlog(const char *outdir) exit(EXIT_FAILURE); } - snprintf(buf,sizeof(buf),"sort -n -t \"\t\" -k 1,1 -o \"%slastlog\" \"%s\"",outdir,temp); + if(ftot<=LastLog) { + if (debug) { + debuga(ngettext("No old reports to delete as only %d report currently exists\n", + "No old reports to delete as only %d reports currently exist\n",ftot),ftot); + } + if (!KeepTempLog && unlink(temp)) { + debuga(_("Cannot delete \"%s\": %s\n"),temp,strerror(errno)); + exit(EXIT_FAILURE); + } + return; + } + + if (snprintf(buf,sizeof(buf),"sort -n -t \"\t\" -k 1,1 -o \"%s/lastlog\" \"%s\"",tmp,temp)>=sizeof(buf)) { + debuga(_("Cannot sort last reports list as the resulting command is too long\n")); + exit(EXIT_FAILURE); + } cstatus=system(buf); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus)); @@ -86,25 +104,18 @@ void mklastlog(const char *outdir) exit(EXIT_FAILURE); } - if (unlink(temp)) { + if (!KeepTempLog && 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) { - if (unlink(temp)) { - debuga(_("Cannot delete \"%s\": %s\n"),temp,strerror(errno)); - exit(EXIT_FAILURE); - } - } - return; - } - + if (debug) + debuga(ngettext("%d report directory found\n","%d report directories found\n",ftot),ftot); ftot-=LastLog; + if (debug) + debuga(ngettext("%d old report to delete\n","%d old reports to delete\n",ftot),ftot); - snprintf(temp,sizeof(temp),"%slastlog",outdir); + snprintf(temp,sizeof(temp),"%s/lastlog",tmp); if((fp_in=fopen(temp,"r"))==NULL) { debuga(_("(lastlog) Cannot open temporary file %s: %s\n"),temp,strerror(errno)); exit(EXIT_FAILURE); @@ -129,9 +140,10 @@ void mklastlog(const char *outdir) } fclose(fp_in); - snprintf(temp,sizeof(temp),"%slastlog",outdir); - if (unlink(temp) == -1) { - debuga(_("Cannot delete \"%s\": %s\n"),temp,strerror(errno)); + if (!KeepTempLog) { + snprintf(temp,sizeof(temp),"%s/lastlog",tmp); + if (unlink(temp) == -1) + debuga(_("Cannot delete \"%s\": %s\n"),temp,strerror(errno)); } return; diff --git a/util.c b/util.c index 0aff2c6..7d64abc 100644 --- a/util.c +++ b/util.c @@ -2064,7 +2064,9 @@ void emptytmpdir(const char *dir) ".user_unsort", ".user_log", ".utmp", - ".ip" + ".ip", + "lastlog1", + "lastlog" }; dirp=opendir(dir);