PUD: update cached mtime right after position file was successfully opened
authorFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 9 May 2012 12:27:33 +0000 (14:27 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 9 May 2012 13:55:23 +0000 (15:55 +0200)
This updates the cached mtime earlier so that the file will
not be read again until it has been changed (to prevent
repeatedly reading a file with errors)

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/src/posFile.c

index c11f11a..d3596af 100644 (file)
@@ -100,6 +100,11 @@ bool readPositionFile(char * fileName, nmeaINFO * nmeaInfo) {
                goto out;
        }
 
+       fd = fopen(fileName, "r");
+       if (!fd) {
+               goto out;
+       }
+
        nmea_zero_INFO(&result);
        result.sig = POSFILE_DEFAULT_SIG;
        result.fix = POSFILE_DEFAULT_FIX;
@@ -112,10 +117,7 @@ bool readPositionFile(char * fileName, nmeaINFO * nmeaInfo) {
        result.speed = POSFILE_DEFAULT_SPEED;
        result.direction = POSFILE_DEFAULT_DIRECTION;
 
-       fd = fopen(fileName, "r");
-       if (!fd) {
-               goto out;
-       }
+       memcpy(&cachedStat.st_mtim, &statBuf.st_mtim, sizeof(cachedStat.st_mtim));
 
        while (fgets(line, LINE_LENGTH, fd)) {
                regmatch_t pmatch[regexNameValuematchCount];
@@ -232,7 +234,6 @@ bool readPositionFile(char * fileName, nmeaINFO * nmeaInfo) {
                result.smask = POSFILE_DEFAULT_SMASK;
        }
 
-       memcpy(&cachedStat.st_mtim, &statBuf.st_mtim, sizeof(cachedStat.st_mtim));
        memcpy(nmeaInfo, &result, sizeof(result));
        retval = true;