postgres.git / summary / log / commit / refs
commit ce2797dca4f81bad7e4b838761bf717ceaaa584c
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Sat Oct 31 09:24:22 2026 +0000
First released in: 14.25, 15.20, 16.16, 17.12, 18.7, 19.0
Fix error handling in pg_flush_data() and FilePrefetch()
posix_fadvise() returns an error code directly instead of setting
errno. However, pg_flush_data() uses %m and errcode_for_file_access()
to report errors without setting errno, potentially reporting an
unrelated error. Fix this by assigning the returned error code to
errno before reporting the error.
FilePrefetch() is documented to return an errno error code on failure,
but it returns -1 when FileAccess() fails. Fix this by returning errno
instead.
The first bug one only affects a warning, and the second doesn't have
any effect because the only existing caller ignores the return value.
So these are pretty harmless bugs, but let's be tidy.
Author: Chao Li <lic@highgo.com>
Discussion: https://www.postgresql.org/message-id/F1916C7A-F152-4AF3-87A9-40492D8B3670@gmail.com
Backpatch-through: 14
src/backend/storage/file/fd.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 6aa6bae5e37..64900ccb76d 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -685,6 +685,9 @@ retry:
if (rc != 0)
{
+ /* update errno for %m et al */
+ errno = rc;
+
/* don't error out, this is just a performance optimization */
ereport(WARNING,
(errcode_for_file_access(),
@@ -2088,7 +2091,7 @@ FilePrefetch(File file, off_t offset, off_t amount, uint32 wait_event_info)
returnCode = FileAccess(file);
if (returnCode < 0)
- return returnCode;
+ return errno;
retry:
pgstat_report_wait_start(wait_event_info);
[parent: 9c44922d125c]