Skip to content

os.posix_fadvise() and os.posix_fallocate() misreport errors on DragonFly BSD #154435

Description

@serhiy-storchaka

Bug report

os.posix_fadvise() and os.posix_fallocate() raise OSError with a meaningless error code on DragonFly BSD:

>>> os.posix_fadvise(-42, 0, 0, os.POSIX_FADV_WILLNEED)
OSError: [Errno -1] Unknown error: -1
>>> os.posix_fallocate(-42, 0, 10)
OSError: [Errno -1] Unknown error: -1

It should be EBADF.

POSIX specifies that these functions return the error number and do not set errno, and this is what the manual page on DragonFly BSD says too:

If successful, posix_fallocate() returns zero. It returns an error on failure, without setting errno.

But the implementation returns -1 and sets errno:

posix_fadvise(-42)   ret=-1 errno=9 (Bad file descriptor)
posix_fallocate(-42) ret=-1 errno=9 (Bad file descriptor)

We use the return value since gh-73528, where the opposite problem was reported: on musl the error was taken from errno, which was not set. Using -1 as an error number produces the above, and it also breaks retrying on EINTR, because the returned value is compared with EINTR.

Both conventions can be supported by using errno when the function returns -1.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesOS-unsupportedextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions