@@ -301,14 +301,14 @@ dsm_cleanup_for_mmap(void)
301301struct dirent * dent ;
302302
303303/* Open the directory; can't use AllocateDir in postmaster. */
304- if ((dir = opendir (PG_DYNSHMEM_DIR ))== NULL )
304+ if ((dir = AllocateDir (PG_DYNSHMEM_DIR ))== NULL )
305305ereport (ERROR ,
306306(errcode_for_file_access (),
307307errmsg ("could not open directory \"%s\": %m" ,
308308PG_DYNSHMEM_DIR )));
309309
310310/* Scan for something with a name of the correct format. */
311- while ((dent = readdir (dir ))!= NULL )
311+ while ((dent = ReadDir (dir , PG_DYNSHMEM_DIR ))!= NULL )
312312{
313313if (strncmp (dent -> d_name ,PG_DYNSHMEM_MMAP_FILE_PREFIX ,
314314strlen (PG_DYNSHMEM_MMAP_FILE_PREFIX ))== 0 )
@@ -335,7 +335,7 @@ dsm_cleanup_for_mmap(void)
335335}
336336
337337/* Cleanup complete. */
338- closedir (dir );
338+ FreeDir (dir );
339339}
340340
341341/*
@@ -357,7 +357,7 @@ dsm_read_state_file(dsm_handle *h)
357357dsm_handle handle ;
358358
359359/* Read the state file to get the ID of the old control segment. */
360- statefd = open (PG_DYNSHMEM_STATE_FILE ,O_RDONLY |PG_BINARY ,0 );
360+ statefd = BasicOpenFile (PG_DYNSHMEM_STATE_FILE ,O_RDONLY |PG_BINARY ,0 );
361361if (statefd < 0 )
362362{
363363if (errno == ENOENT )
@@ -369,10 +369,13 @@ dsm_read_state_file(dsm_handle *h)
369369}
370370nbytes = read (statefd ,statebuf ,PG_DYNSHMEM_STATE_BUFSIZ - 1 );
371371if (nbytes < 0 )
372+ {
373+ close (statefd );
372374ereport (ERROR ,
373375(errcode_for_file_access (),
374376errmsg ("could not read file \"%s\": %m" ,
375377PG_DYNSHMEM_STATE_FILE )));
378+ }
376379/* make sure buffer is NUL terminated */
377380statebuf [nbytes ]= '\0' ;
378381close (statefd );