Changeset 11152
- Timestamp:
- Jan 18, 2007, 6:29:11 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/types/psMetadataConfig.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psMetadataConfig.c
r10999 r11152 10 10 * @author Eric Van Alst, MHPCC 11 11 * 12 * @version $Revision: 1.12 6$ $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 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 32 32 #include "psMetadataConfig.h" 33 33 #include "psAssert.h" 34 34 #include "psTrace.h" 35 35 36 36 /******************************************************************************/ … … 1295 1295 return NULL; 1296 1296 } 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; 1297 1313 1298 1314 // psMetadataConfigParse() is going to read the entire file into memory so 1299 1315 // 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); 1305 1319 if (file == MAP_FAILED) { 1306 1320 psError(PS_ERR_IO, true, _("failed to mmap() file %s"), filename); 1307 1321 if (close(fd) != 0) { 1308 1322 psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename); 1309 return NULL;1310 1323 } 1311 1324 return NULL; 1312 1325 } 1326 1327 bool success = true; 1313 1328 1314 1329 md = psMetadataConfigParse(md, nFail, (char *)file, overwrite); 1315 1330 if (!md) { 1316 1331 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) { 1321 1336 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; 1329 1338 } 1330 1339 1331 1340 if (close(fd) != 0) { 1332 1341 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); 1334 1347 return NULL; 1335 1348 } 1336 1337 1349 return md; 1338 1350 } … … 1403 1415 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Error parsing line: %s", line); 1404 1416 } 1417 psTrace("psLib.types", 4, "Error parsing line: %s", line); 1405 1418 } 1406 1419 }
Note:
See TracChangeset
for help on using the changeset viewer.
