postgres.git / summary / log / commit / refs

commit    d50c656a8e344f6582a8bfcb84254b9e8a621e9e
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 4cf4717f764..abfb4c5ff2b 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -686,6 +686,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(), @@ -2078,7 +2081,7 @@ FilePrefetch(File file, pgoff_t offset, pgoff_t amount, uint32 wait_event_info) returnCode = FileAccess(file); if (returnCode < 0) - return returnCode; + return errno; retry: pgstat_report_wait_start(wait_event_info); @@ -2102,7 +2105,7 @@ retry: returnCode = FileAccess(file); if (returnCode < 0) - return returnCode; + return errno; ra.ra_offset = offset; ra.ra_count = amount; [parent: 4942dc745cf1]