]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Report a proper message if a log file cannot be read
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Sat, 30 Mar 2013 12:19:15 +0000 (13:19 +0100)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Sat, 30 Mar 2013 12:19:15 +0000 (13:19 +0100)
Previous versions used to report that the file doesn't exist if the user
doesn't have read access.

Thanks to Henri Lin for reporting this bug.

decomp.c
documentation/decomp.txt [deleted file]
readlog.c

index e9c3b308030c018afb2849be2d206551bf6f67ea..bd5a870b3558c5bb66e1e147c10d08b6619aff9d 100644 (file)
--- a/decomp.c
+++ b/decomp.c
 #include "include/conf.h"
 #include "include/defs.h"
 
+/*!
+Open the log file. If it is compressed, uncompress it through a pipe.
+
+Log files compressed with gzip, bzip2 or compress are uncompressed with zcat or bzcat.
+
+If the log file does not exist, the process terminates with an error message.
+
+\param arq The log file to process.
+\param pipe A variable set to \c true if the log file is opened through a pipe or set to \c false if the file is open directly.
+
+\date 2009-09-24 - F Marchal\n This function used to uncompress .Z files in
+place using uncompress but that required a write access to the log directory,
+could conflict with logrotate and could leave the log file uncompressed if sarg
+crashed. According to the documentation, zcat is capable of uncompressing .Z
+files so it is now used.
+
+\date 2010-05-10 - F Marchal\n
+The function doesn't use a temporary file any more and read the compressed file through a pipe.
+*/
 FILE *decomp(const char *arq, bool *pipe)
 {
+       FILE *fi;
        char cmd[1024];
        int arqlen;
 
-       if(access(arq, R_OK) != 0) {
-               debuga(_("File not found: %s\n"),arq);
-               exit(EXIT_FAILURE);
-       }
-
        arqlen=strlen(arq);
        if(arqlen>3 && strcmp(arq+arqlen-3,".gz") == 0) {
                debuga(_("Decompressing log file \"%s\" with zcat\n"),arq);
@@ -45,29 +60,29 @@ FILE *decomp(const char *arq, bool *pipe)
                        exit(EXIT_FAILURE);
                }
                *pipe=true;
-               return(popen(cmd,"r"));
+               fi=popen(cmd,"r");
        }
-
-       if(arqlen>4 && strcmp(arq+arqlen-4,".bz2") == 0) {
+       else if(arqlen>4 && strcmp(arq+arqlen-4,".bz2") == 0) {
                debuga(_("Decompressing log file \"%s\" with bzcat\n"),arq);
                if (snprintf(cmd,sizeof(cmd),"bzcat \"%s\"",arq)>=sizeof(cmd)) {
                        debuga(_("decompression command too long for log file %s\n"),arq);
                        exit(EXIT_FAILURE);
                }
                *pipe=true;
-               return(popen(cmd,"r"));
+               fi=popen(cmd,"r");
        }
-
-       if(arqlen>2 && strcmp(arq+arqlen-2,".Z") == 0) {
+       else if(arqlen>2 && strcmp(arq+arqlen-2,".Z") == 0) {
                debuga(_("Decompressing log file \"%s\" with zcat\n"),arq);
                if (snprintf(cmd,sizeof(cmd),"zcat \"%s\"",arq)>=sizeof(cmd)) {
                        debuga(_("decompression command too long for log file %s\n"),arq);
                        exit(EXIT_FAILURE);
                }
                *pipe=true;
-               return(popen(cmd,"r"));
+               fi=popen(cmd,"r");
        }
-
-       *pipe=false;
-       return(MY_FOPEN(arq,"r"));
+       else {
+               *pipe=false;
+               fi=MY_FOPEN(arq,"r");
+       }
+       return(fi);
 }
diff --git a/documentation/decomp.txt b/documentation/decomp.txt
deleted file mode 100644 (file)
index 02c5579..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/*!\file decomp.c
-\brief Handle compressed log files.
-*/
-
-/*! \fn FILE *decomp(const char *arq, bool *pipe)
-Open the log file. If it is compressed, uncompress it through a pipe.
-
-Log files compressed with gzip, bzip2 or compress are uncompressed with zcat or bzcat.
-
-If the log file does not exist, the process terminates with an error message.
-
-\param arq The log file to process.
-\param pipe A variable set to \c true if the log file is opened through a pipe or set to \c false if the file is open directly.
-
-\date 2009-09-24 - F Marchal\n
-This function used to uncompress .Z files in place using uncompress but that required a write access to the log directory, could conflict with logrotate and could leave the log file uncompressed if sarg crashed. According to the documentation, zcat is capable of uncompressing .Z files so it is now used.
-
-\date 2010-05-10 - F Marchal\n
-The function doesn't use a temporary file any more and read the compressed file through a pipe.
-*/
index f47fd73dae468c4e30183cadf9bcd4681da6d4bd..dc6c510818c07f9801d68f7292333117e360f26d 100644 (file)
--- a/readlog.c
+++ b/readlog.c
@@ -195,7 +195,7 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
                }
                fp_in=decomp(arq,&from_pipe);
                if(fp_in==NULL) {
-                       debuga(_("(log) Cannot open log file: %s - %s\n"),arq,strerror(errno));
+                       debuga(_("Cannot open input log file \"%s\": %s\n"),arq,strerror(errno));
                        exit(EXIT_FAILURE);
                }
                if(debug) debuga(_("Reading access log file: %s\n"),arq);