@@ -301,14 +301,14 @@ dsm_cleanup_for_mmap(void)
301301 struct 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 )
305305 ereport (ERROR ,
306306 (errcode_for_file_access (),
307307 errmsg ("could not open directory \"%s\": %m" ,
308308 PG_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 {
313313 if (strncmp (dent -> d_name , PG_DYNSHMEM_MMAP_FILE_PREFIX ,
314314 strlen (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)
357357 dsm_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 );
361361 if (statefd < 0 )
362362 {
363363 if (errno == ENOENT )
@@ -369,10 +369,13 @@ dsm_read_state_file(dsm_handle *h)
369369 }
370370 nbytes = read (statefd , statebuf , PG_DYNSHMEM_STATE_BUFSIZ - 1 );
371371 if (nbytes < 0 )
372+ {
373+ close (statefd );
372374 ereport (ERROR ,
373375 (errcode_for_file_access (),
374376 errmsg ("could not read file \"%s\": %m" ,
375377 PG_DYNSHMEM_STATE_FILE )));
378+ }
376379 /* make sure buffer is NUL terminated */
377380 statebuf [nbytes ] = '\0' ;
378381 close (statefd );
0 commit comments