]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - realtime.c
Add support to decompress xz files
[thirdparty/sarg.git] / realtime.c
index 37e0dd2139c8084dd2d644f31937cdc1e1048c4a..cf90e479d9c25842cd3ef53efc11eb9dccfede7e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
- *                                                            1998, 2013
+ *                                                            1998, 2015
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
@@ -67,7 +67,7 @@ static bool GetLatestModified(char *file_name,int file_name_size)
        while ((file=FileListIter_Next(FIter))!=NULL)
        {
                if (stat(file,&st)==-1) {
-                       debuga(_("Cannot stat \"%s\": %s\n"),file,strerror(errno));
+                       debuga(__FILE__,__LINE__,_("Cannot stat \"%s\": %s\n"),file,strerror(errno));
                }
                if (!found)
                {
@@ -172,7 +172,7 @@ static void datashow(struct RealtimeReadLogStruct *List,int Index,int Size)
 
 void realtime(void)
 {
-       FILE *fp;
+       FileObject *fp;
        char file_name[2048];
        char *buf;
        longline line;
@@ -187,11 +187,6 @@ void realtime(void)
        init_usertab(UserTabFile);
        LogLine_Init(&log_line);
 
-       if ((line=longline_create())==NULL) {
-               debuga(_("Not enough memory to read the log file\n"));
-               exit(EXIT_FAILURE);
-       }
-
        /*
         * Store one more entry to prepare the memory structure in place and reject it if
         * it is about the same user and url as the last stored one.
@@ -199,7 +194,7 @@ void realtime(void)
        StoredLogEntries=calloc(realtime_access_log_lines+1,sizeof(struct RealtimeReadLogStruct));
        if (!StoredLogEntries)
        {
-               debuga(_("Not enough memory to store %d records"),realtime_access_log_lines);
+               debuga(__FILE__,__LINE__,_("Not enough memory to store %d records"),realtime_access_log_lines);
                exit(EXIT_FAILURE);
        }
        /*
@@ -210,14 +205,20 @@ void realtime(void)
 
        if (!GetLatestModified(file_name,sizeof(file_name)))
        {
-               debuga(_("No log file to read the last %d lines from\n"),realtime_access_log_lines);
+               debuga(__FILE__,__LINE__,_("No log file to read the last %d lines from\n"),realtime_access_log_lines);
                exit(EXIT_FAILURE);
        }
-       fp = fopen(file_name, "r");
+       fp = FileObject_Open(file_name);
        if (!fp) {
-               debuga(_("Failed to open the last modified log file \"%s\": %s\n"),file_name,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),file_name,FileObject_GetLastOpenError());
                exit(EXIT_FAILURE);
        }
+
+       if ((line=longline_create())==NULL) {
+               debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),file_name);
+               exit(EXIT_FAILURE);
+       }
+
        while((buf=longline_read(fp,line)) != NULL )
        {
                log_entry_status=LogLine_Parse(&log_line,&log_entry,buf);
@@ -242,7 +243,10 @@ void realtime(void)
                if (NextIndex>StoreSize) StoreSize=NextIndex;
                if (NextIndex>realtime_access_log_lines) NextIndex=0;
        }
-       fclose(fp);
+       if (FileObject_Close(fp)) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),file_name,FileObject_GetLastCloseError());
+               exit(EXIT_FAILURE);
+       }
        longline_destroy(&line);
 
        datashow(StoredLogEntries,StoreIndex,StoreSize);