From: Frederic Marchal Date: Sun, 15 Jun 2014 08:35:57 +0000 (+0200) Subject: Help in diagnosing the number of old reports to keep X-Git-Tag: v2.3.9~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f293c727745d6ee6bc6d298fd3589d360e7e1b08;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 users 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 1404b01..5d453e6 100644 --- a/lastlog.c +++ b/lastlog.c @@ -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\n"),temp); exit(EXIT_FAILURE); @@ -75,7 +78,19 @@ void mklastlog(const char *outdir) closedir( dirp ); fclose(fp_ou); - 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 exist\n", + "No old reports to delete as only %d reports currently exists\n",ftot),ftot); + } + if (!KeepTempLog && unlink(temp)) { + debuga(_("Cannot delete \"%s\": %s\n"),temp,strerror(errno)); + exit(EXIT_FAILURE); + } + return; + } + + snprintf(buf,sizeof(buf),"sort -n -t \"\t\" -k 1,1 -o \"%s/lastlog\" \"%s\"",tmp,temp); cstatus=system(buf); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus)); @@ -83,25 +98,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\n"),temp); exit(EXIT_FAILURE); @@ -126,9 +134,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;