postgres.git / summary / log / commit / refs

commit    1cdfea37c268d41b47e1cf968103cb9866feec4d
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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 378c078c7c7..a9565fda790 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(), @@ -2094,7 +2097,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); @@ -2118,7 +2121,7 @@ retry: returnCode = FileAccess(file); if (returnCode < 0) - return returnCode; + return errno; ra.ra_offset = offset; ra.ra_count = amount; [parent: 19a2002b5db9]