postgres.git / summary / log / commit / refs

commit    a1d165d63cc8f3574882e75f8a0924544dcbe7ed
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 3c04c9dabda..9717e62acdb 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -621,6 +621,9 @@ pg_flush_data(int fd, off_t offset, off_t nbytes) 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(), @@ -2068,7 +2071,7 @@ FilePrefetch(File file, off_t offset, int amount, uint32 wait_event_info) returnCode = FileAccess(file); if (returnCode < 0) - return returnCode; + return errno; pgstat_report_wait_start(wait_event_info); returnCode = posix_fadvise(VfdCache[file].fd, offset, amount, [parent: a3657b7d47ce]