Skip to content

Commit 82a704a

Browse files
committed
Add a safety check for compiletest rlimit
1 parent 6563803 commit 82a704a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/tools/compiletest/src/raise_fd_limit.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,16 @@ pub unsafe fn raise_fd_limit() {
5757
panic!("raise_fd_limit: error calling getrlimit: {}", err);
5858
}
5959

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

64-
// Set our newly-increased resource limit
65-
if libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) != 0 {
66-
let err = io::Error::last_os_error();
67-
panic!("raise_fd_limit: error calling setrlimit: {}", err);
65+
// Set our newly-increased resource limit.
66+
if libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) != 0 {
67+
let err = io::Error::last_os_error();
68+
panic!("raise_fd_limit: error calling setrlimit: {}", err);
69+
}
6870
}
6971
}
7072

0 commit comments

Comments
 (0)