Skip to content

Commit

Permalink
Add a safety check for compiletest rlimit
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Aug 9, 2018
1 parent 6563803 commit 82a704a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/tools/compiletest/src/raise_fd_limit.rs
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

0 comments on commit 82a704a

Please sign in to comment.