Skip to content

Commit fdf4007

Browse files
committed
Rollup merge of rust-lang#53229 - varkor:rlimits_min, r=nikomatsakis
Make sure rlimit is only ever increased `libc::setrlimit` will fail if we try to set the rlimit to a value lower than it is currently, so make sure we're never trying to do this. Fixes rust-lang#52801.
2 parents 715581a + 82a704a commit fdf4007

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/librustc_driver/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<dyn Any
15131513
true
15141514
} else if rlim.rlim_max < STACK_SIZE as libc::rlim_t {
15151515
true
1516-
} else {
1516+
} else if rlim.rlim_cur < STACK_SIZE as libc::rlim_t {
15171517
std::rt::deinit_stack_guard();
15181518
rlim.rlim_cur = STACK_SIZE as libc::rlim_t;
15191519
if libc::setrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 {
@@ -1525,6 +1525,8 @@ pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<dyn Any
15251525
std::rt::update_stack_guard();
15261526
false
15271527
}
1528+
} else {
1529+
false
15281530
}
15291531
};
15301532

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)