logswan

Fast Web log analyzer using probabilistic data structures
Log | Files | Refs | README | LICENSE

commit c06f0f3b56a111141d2d0c0cafd81d3776733b16
parent 0368c4e1be6d0ff555b17cddda934531fab0d0bb
Author: Frederic Cambus <fred@statdns.com>
Date:   Wed,  7 Dec 2016 21:01:43 +0100

Use fstat on open file descriptor instead of using stat before opening the log file

Diffstat:
Msrc/logswan.c | 15+++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/logswan.c b/src/logswan.c @@ -73,8 +73,8 @@ int main (int argc, char *argv[]) { uint32_t hour; uint32_t countryId = 0; - struct stat logFileSize; FILE *logFile; + struct stat logFileStat; const char *errstr; @@ -125,11 +125,6 @@ int main (int argc, char *argv[]) { geoipv6 = GeoIP_open(GEOIPDIR "GeoIPv6.dat", GEOIP_MEMORY_CACHE); } - /* Get log file size */ - stat(intputFile, &logFileSize); - results.fileName = intputFile; - results.fileSize = (uint64_t)logFileSize.st_size; - /* Open log file */ if (!strcmp(intputFile, "-")) { /* Read from standard input */ @@ -142,6 +137,14 @@ int main (int argc, char *argv[]) { } } + /* Get log file size */ + if (fstat(fileno(logFile), &logFileStat)) { + perror("Can't stat log file"); + return EXIT_FAILURE; + } + + results.fileName = intputFile; + results.fileSize = (uint64_t)logFileStat.st_size; results.invalidLines = 0; while (fgets(lineBuffer, LINE_MAX_LENGTH, logFile)) {