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.
/*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
/*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
- 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);
if((fp_ou=fopen(temp,"w"))==NULL) {
debuga(_("(lastlog) Cannot open temporary file %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);
+ 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));
cstatus=system(buf);
if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
+ if (!KeepTempLog && unlink(temp)) {
debuga(_("Cannot delete \"%s\": %s\n"),temp,strerror(errno));
exit(EXIT_FAILURE);
}
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);
+ 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);
if((fp_in=fopen(temp,"r"))==NULL) {
debuga(_("(lastlog) Cannot open temporary file %s: %s\n"),temp,strerror(errno));
exit(EXIT_FAILURE);
- 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));
".user_unsort",
".user_log",
".utmp",
".user_unsort",
".user_log",
".utmp",
+ ".ip",
+ "lastlog1",
+ "lastlog"