Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure rlimit is only ever increased #53229

Merged
merged 2 commits into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<dyn Any
true
} else if rlim.rlim_max < STACK_SIZE as libc::rlim_t {
true
} else {
} else if rlim.rlim_cur < STACK_SIZE as libc::rlim_t {
std::rt::deinit_stack_guard();
rlim.rlim_cur = STACK_SIZE as libc::rlim_t;
if libc::setrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 {
Expand All @@ -1524,6 +1524,8 @@ pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<dyn Any
std::rt::update_stack_guard();
false
}
} else {
false
}
};

Expand Down
16 changes: 9 additions & 7 deletions src/tools/compiletest/src/raise_fd_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ pub unsafe fn raise_fd_limit() {
panic!("raise_fd_limit: error calling getrlimit: {}", err);
}

// Bump the soft limit to the smaller of kern.maxfilesperproc and the hard
// limit
rlim.rlim_cur = cmp::min(maxfiles as libc::rlim_t, rlim.rlim_max);
// Make sure we're only ever going to increase the rlimit.
if rlim.rlim_cur < maxfiles as libc::rlim_t {
// Bump the soft limit to the smaller of kern.maxfilesperproc and the hard limit.
rlim.rlim_cur = cmp::min(maxfiles as libc::rlim_t, rlim.rlim_max);

// Set our newly-increased resource limit
if libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) != 0 {
let err = io::Error::last_os_error();
panic!("raise_fd_limit: error calling setrlimit: {}", err);
// Set our newly-increased resource limit.
if libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) != 0 {
let err = io::Error::last_os_error();
panic!("raise_fd_limit: error calling setrlimit: {}", err);
}
}
}

Expand Down