Skip to content

Commit d9250da

Browse files
committed
Fixups for dsm.c's file descriptor handling.
Per complaint from Tom Lane.
1 parent 33d3f55 commit d9250da

File tree

1 file changed

+7
-4
lines changed
  • src/backend/storage/ipc

1 file changed

+7
-4
lines changed

src/backend/storage/ipc/dsm.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy