Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8528e3d

Browse files
committed
Fix failure to check for open() or fsync() failures.
While it seems OK to not be concerned about fsync() failure for a pre-existing signal file, it's not OK to not even check for open() failure. This at least causes complaints from static analyzers, and I think on some platforms passing -1 to fsync() or close() might trigger assertion-type failures. Also add (void) casts to make clear that we're ignoring fsync's result intentionally. Oversights in commit 2dedf4d, noted by Coverity.
1 parent e9fcfed commit 8528e3d

File tree

1 file changed

+12
-5
lines changed
  • src/backend/access/transam

1 file changed

+12
-5
lines changed

src/backend/access/transam/xlog.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5327,7 +5327,8 @@ readRecoverySignalFile(void)
53275327

53285328
/*
53295329
* Check for recovery signal files and if found, fsync them since they
5330-
* represent server state information.
5330+
* represent server state information. We don't sweat too much about the
5331+
* possibility of fsync failure, however.
53315332
*
53325333
* If present, standby signal file takes precedence. If neither is present
53335334
* then we won't enter archive recovery.
@@ -5338,8 +5339,11 @@ readRecoverySignalFile(void)
53385339

53395340
fd = BasicOpenFilePerm(STANDBY_SIGNAL_FILE, O_RDWR | PG_BINARY | get_sync_bit(sync_method),
53405341
S_IRUSR | S_IWUSR);
5341-
pg_fsync(fd);
5342-
close(fd);
5342+
if (fd >= 0)
5343+
{
5344+
(void) pg_fsync(fd);
5345+
close(fd);
5346+
}
53435347
standby_signal_file_found = true;
53445348
}
53455349
else if (stat(RECOVERY_SIGNAL_FILE, &stat_buf) == 0)
@@ -5348,8 +5352,11 @@ readRecoverySignalFile(void)
53485352

53495353
fd = BasicOpenFilePerm(RECOVERY_SIGNAL_FILE, O_RDWR | PG_BINARY | get_sync_bit(sync_method),
53505354
S_IRUSR | S_IWUSR);
5351-
pg_fsync(fd);
5352-
close(fd);
5355+
if (fd >= 0)
5356+
{
5357+
(void) pg_fsync(fd);
5358+
close(fd);
5359+
}
53535360
recovery_signal_file_found = true;
53545361
}
53555362

0 commit comments

Comments
 (0)