IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11152


Ignore:
Timestamp:
Jan 18, 2007, 6:29:11 PM (19 years ago)
Author:
magnier
Message:

using the actual page size to drive the size request in an attempt to fix a bus error for empty files; did not work, so added a skip for empty files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psMetadataConfig.c

    r10999 r11152  
    1010*  @author Eric Van Alst, MHPCC
    1111*
    12 *  @version $Revision: 1.126 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2007-01-09 22:38:53 $
     12*  @version $Revision: 1.127 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2007-01-19 04:29:11 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3232#include "psMetadataConfig.h"
    3333#include "psAssert.h"
    34 
     34#include "psTrace.h"
    3535
    3636/******************************************************************************/
     
    12951295        return NULL;
    12961296    }
     1297    // XXX EAM : for some reason, the mmap below results in a buffer which causes
     1298    // bus errors if the file is empty.  This seems like a strange result...
     1299    if (buf.st_size == 0) {
     1300        psError(PS_ERR_IO, true, _("Empty file '%s'.\n"), filename);
     1301        close(fd);
     1302        return NULL;
     1303    }
     1304
     1305    // determine the system page size
     1306    int pageSize = getpagesize();
     1307
     1308    // request one extra page.  even if st_size is an exact multiple of pageSize, this
     1309    // will guarantee we get a block of 0-valued bytes at the end of the file data.
     1310    int nPages = buf.st_size / pageSize + 1;
     1311
     1312    int nBytes = nPages * pageSize;
    12971313
    12981314    // psMetadataConfigParse() is going to read the entire file into memory so
    12991315    // we're trying to be nice by allowing the VM to flush the file out of
    1300     // memory if need be.  XXX we're adding 1 to buf.st_size here in case
    1301     // st_size / system page size has a remaineder of zero (in that case this
    1302     // magic trick may not work because there won't be any trailing \0s at the
    1303     // end of the page).
    1304     void *file = mmap(0, (size_t)buf.st_size + 1, PROT_READ, MAP_PRIVATE, fd, 0);
     1316    // memory if need be.
     1317
     1318    void *file = mmap(0, nBytes, PROT_READ, MAP_PRIVATE, fd, 0);
    13051319    if (file == MAP_FAILED) {
    13061320        psError(PS_ERR_IO, true, _("failed to mmap() file %s"), filename);
    13071321        if (close(fd) != 0) {
    13081322            psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
    1309             return NULL;
    13101323        }
    13111324        return NULL;
    13121325    }
     1326
     1327    bool success = true;
    13131328
    13141329    md = psMetadataConfigParse(md, nFail, (char *)file, overwrite);
    13151330    if (!md) {
    13161331        psError(PS_ERR_IO, true, _("failed to parse file '%s'"), filename);
    1317         return NULL;
    1318     }
    1319 
    1320     if (munmap(file, (size_t)buf.st_size) != 0) {
     1332        success = false;
     1333    }
     1334
     1335    if (munmap(file, nBytes) != 0) {
    13211336        psError(PS_ERR_IO, true, _("failed to munmap file '%s'"), filename);
    1322         if (close(fd) != 0) {
    1323             // the new error flag is set to false so as not to hide the
    1324             // munmap() error
    1325             psError(PS_ERR_IO, false, _("Failed to close file '%s'."), filename);
    1326             psFree(md);
    1327             return NULL;
    1328         }
     1337        success = false;
    13291338    }
    13301339
    13311340    if (close(fd) != 0) {
    13321341        psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
    1333         psFree(md);
     1342        success = false;
     1343    }
     1344
     1345    if (!success) {
     1346        psFree (md);
    13341347        return NULL;
    13351348    }
    1336 
    13371349    return md;
    13381350}
     
    14031415                psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Error parsing line: %s", line);
    14041416            }
     1417            psTrace("psLib.types", 4, "Error parsing line: %s", line);
    14051418        }
    14061419    }
Note: See TracChangeset for help on using the changeset viewer.