Commit 7703f4c60a
src/stage1/os.cpp
@@ -977,29 +977,6 @@ int os_init(void) {
#elif defined(__MACH__)
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &macos_monotonic_clock);
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &macos_calendar_clock);
-#endif
-#if defined(ZIG_OS_POSIX)
- // Raise the open file descriptor limit.
- // Code lifted from node.js
- struct rlimit lim;
- if (getrlimit(RLIMIT_NOFILE, &lim) == 0 && lim.rlim_cur != lim.rlim_max) {
- // Do a binary search for the limit.
- rlim_t min = lim.rlim_cur;
- rlim_t max = 1 << 20;
- // But if there's a defined upper bound, don't search, just set it.
- if (lim.rlim_max != RLIM_INFINITY) {
- min = lim.rlim_max;
- max = lim.rlim_max;
- }
- do {
- lim.rlim_cur = min + (max - min) / 2;
- if (setrlimit(RLIMIT_NOFILE, &lim)) {
- max = lim.rlim_cur;
- } else {
- min = lim.rlim_cur;
- }
- } while (min + 1 < max);
- }
#endif
return 0;
}
src/main.zig
@@ -2982,35 +2982,29 @@ fn parseCodeModel(arg: []const u8) std.builtin.CodeModel {
/// garbage collector to run concurrently to zig processes, and to allow multiple
/// zig processes to run concurrently with each other, without clobbering each other.
fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
- switch (std.Target.current.os.tag) {
- .windows, .wasi, .uefi, .other, .freestanding => return,
- // std lib is missing getrlimit/setrlimit.
- // https://github.com/ziglang/zig/issues/6361
- //else => {},
- else => return,
- }
+ if (!@hasDecl(std.os, "rlimit")) return;
const posix = std.os;
- var lim = posix.getrlimit(posix.RLIMIT_NOFILE, &lim) catch return; // Oh well; we tried.
+
+ var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried.
if (lim.cur == lim.max) return;
+
+ // Do a binary search for the limit.
+ var min: posix.rlim_t = lim.cur;
+ var max: posix.rlim_t = 1 << 20;
+ // But if there's a defined upper bound, don't search, just set it.
+ if (lim.max != posix.RLIM_INFINITY) {
+ min = lim.max;
+ max = lim.max;
+ }
+
while (true) {
- // Do a binary search for the limit.
- var min: posix.rlim_t = lim.cur;
- var max: posix.rlim_t = 1 << 20;
- // But if there's a defined upper bound, don't search, just set it.
- if (lim.max != posix.RLIM_INFINITY) {
- min = lim.max;
- max = lim.max;
- }
- while (true) {
- lim.cur = min + (max - min) / 2;
- if (posix.setrlimit(posix.RLIMIT_NOFILE, lim)) |_| {
- min = lim.cur;
- } else |_| {
- max = lim.cur;
- }
- if (min + 1 < max) continue;
- return;
+ lim.cur = min + (max - min) / 2;
+ if (posix.setrlimit(.NOFILE, lim)) |_| {
+ min = lim.cur;
+ } else |_| {
+ max = lim.cur;
}
+ if (min + 1 >= max) break;
}
}