Skip to content

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

Closed

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    3.16new features, bugs and security fixes
    on Jul 22, 2026
  2. added 2 commits that reference this issue on Jul 22, 2026
  3. added 2 commits that reference this issue on Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions