Bug 293494 - RLIMIT_NOFILE semantics seem to be incorrect
Summary: RLIMIT_NOFILE semantics seem to be incorrect
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 16.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-02-28 05:57 UTC by Audrey Dutcher
Modified: 2026-02-28 05:57 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Audrey Dutcher 2026-02-28 05:57:45 UTC
limits(1) describes the behavior of -n as adjusting the maximum number of open file descriptors. I think this is the correct behavior. However, the kernel seems to implement this as setting a limit on the maximum file descriptor that is opened. This leads to a number of discrepancies:

- The limit can be set while there are too many open descriptors and more files can continue to be opened as long as there are free slots below the given maximum
- Even if there are fewer than the given number of descriptors open, dup operations can fail if the "minimum fd" parameter to fcntl(F_DUPFD) is given.

I encountered this while running testcases for git. I had dozens of file descriptors open from my desktop environment (probably shouldn't but whatever), the test (t5324-split-commit-graph.sh) sets ulimit -n32 and does some operations to make sure it works correctly under this kind of duress. It fails in confusion over some combination of the above two points.