]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Help in diagnosing the number of old reports to keep
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 15 Jun 2014 08:35:57 +0000 (10:35 +0200)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 15 Jun 2014 08:35:57 +0000 (10:35 +0200)
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.

lastlog.c

index 1404b01088fd60c6bab223b26c8e5a356caf6908..5d453e62ea6e5495d7ed9d38cd3687349ae795bb 100644 (file)
--- 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;