diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2020-04-05 10:02:00 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2020-04-05 10:03:04 +0200 |
commit | d278d4e1adc14998948656d16e759f70c0fafb66 (patch) | |
tree | b3221a887bbf660174687b9a470f2485fecf9822 /src | |
parent | 05f4a88184a4587d883594d4b90d41f9bb63a39b (diff) | |
download | postgresql-d278d4e1adc14998948656d16e759f70c0fafb66.tar.gz postgresql-d278d4e1adc14998948656d16e759f70c0fafb66.zip |
Save errno across LWLockRelease() calls
Fixup for "Drop slot's LWLock before returning from SaveSlotToPath()"
Reported-by: Michael Paquier <michael@paquier.xyz>
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/replication/slot.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 409db4b2eff..bb5555ed736 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -1259,9 +1259,13 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) /* * If not an ERROR, then release the lock before returning. In case * of an ERROR, the error recovery path automatically releases the - * lock, but no harm in explicitly releasing even in that case. + * lock, but no harm in explicitly releasing even in that case. Note + * that LWLockRelease() could affect errno. */ + int save_errno = errno; + LWLockRelease(&slot->io_in_progress_lock); + errno = save_errno; ereport(elevel, (errcode_for_file_access(), errmsg("could not create file \"%s\": %m", @@ -1325,7 +1329,10 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) if (CloseTransientFile(fd)) { + int save_errno = errno; + LWLockRelease(&slot->io_in_progress_lock); + errno = save_errno; ereport(elevel, (errcode_for_file_access(), errmsg("could not close file \"%s\": %m", @@ -1336,7 +1343,10 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) /* rename to permanent file, fsync file and directory */ if (rename(tmppath, path) != 0) { + int save_errno = errno; + LWLockRelease(&slot->io_in_progress_lock); + errno = save_errno; ereport(elevel, (errcode_for_file_access(), errmsg("could not rename file \"%s\" to \"%s\": %m", |