@@ -1259,9 +1259,13 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
1259
1259
/*
1260
1260
* If not an ERROR, then release the lock before returning. In case
1261
1261
* of an ERROR, the error recovery path automatically releases the
1262
- * lock, but no harm in explicitly releasing even in that case.
1262
+ * lock, but no harm in explicitly releasing even in that case. Note
1263
+ * that LWLockRelease() could affect errno.
1263
1264
*/
1265
+ int save_errno = errno ;
1266
+
1264
1267
LWLockRelease (& slot -> io_in_progress_lock );
1268
+ errno = save_errno ;
1265
1269
ereport (elevel ,
1266
1270
(errcode_for_file_access (),
1267
1271
errmsg ("could not create file \"%s\": %m" ,
@@ -1325,7 +1329,10 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
1325
1329
1326
1330
if (CloseTransientFile (fd ) != 0 )
1327
1331
{
1332
+ int save_errno = errno ;
1333
+
1328
1334
LWLockRelease (& slot -> io_in_progress_lock );
1335
+ errno = save_errno ;
1329
1336
ereport (elevel ,
1330
1337
(errcode_for_file_access (),
1331
1338
errmsg ("could not close file \"%s\": %m" ,
@@ -1336,7 +1343,10 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
1336
1343
/* rename to permanent file, fsync file and directory */
1337
1344
if (rename (tmppath , path ) != 0 )
1338
1345
{
1346
+ int save_errno = errno ;
1347
+
1339
1348
LWLockRelease (& slot -> io_in_progress_lock );
1349
+ errno = save_errno ;
1340
1350
ereport (elevel ,
1341
1351
(errcode_for_file_access (),
1342
1352
errmsg ("could not rename file \"%s\" to \"%s\": %m" ,
0 commit comments