postgres.git / summary / log / commit / refs

commit    72b2b9c52e3a86ae414fc07acf6db3de0776fc13
Author:   Peter Eisentraut <peter@eisentraut.org>
Date:     Sun Apr 05 08:02:00 2020 +0000
First released in: 13.0, 9.5.22, 9.6.18, 10.13, 11.8, 12.3

    Save errno across LWLockRelease() calls
    
    Fixup for "Drop slot's LWLock before returning from SaveSlotToPath()"
    
    Reported-by: Michael Paquier <michael@paquier.xyz>


src/backend/replication/slot.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 14fc04df09c..85c1cc969c1 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -1013,9 +1013,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", @@ -1076,7 +1080,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", [parent: 8150f7813a08]