]> 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 14:44:56 +0000 (16:44 +0200)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 15 Jun 2014 14:44:56 +0000 (16:44 +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 user asked not to delete temporary files.

Some debug messages give indication about what is happening with respect
to the old reports deletion.

lastlog.c
util.c

index 09a079e5d8e92a91cc9edee1fd6c062a899ec8a0..8334b2c52721b045abc296ad9ea067312e37f962 100644 (file)
--- 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 0aff2c61564affd2fc05719aeda559c8510d3794..7d64abc76f761be37b30397f1322577d76352e0c 100644 (file)
--- 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);