-
Notifications
You must be signed in to change notification settings - Fork 389
/
Copy pathmacos.rs
37 lines (34 loc) · 1.14 KB
/
macos.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::io;
/// Bump filehandle limit
pub fn bump_filehandle_limit() {
let mut limits = libc::rlimit {
rlim_cur: 0,
rlim_max: 0,
};
// SAFETY: `&mut limits` is a valid pointer parameter for the getrlimit syscall
let status = unsafe { libc::getrlimit(libc::RLIMIT_NOFILE, &mut limits) };
if status != 0 {
log::error!(
"Failed to get file handle limits: {}-{}",
io::Error::from_raw_os_error(status),
status
);
return;
}
const INCREASED_FILEHANDLE_LIMIT: u64 = 1024;
// if file handle limit is already big enough, there's no reason to decrease it.
if limits.rlim_cur >= INCREASED_FILEHANDLE_LIMIT {
return;
}
limits.rlim_cur = INCREASED_FILEHANDLE_LIMIT;
// SAFETY: `&limits` is a valid pointer parameter for the getrlimit syscall
let status = unsafe { libc::setrlimit(libc::RLIMIT_NOFILE, &limits) };
if status != 0 {
log::error!(
"Failed to set file handle limit to {}: {}-{}",
INCREASED_FILEHANDLE_LIMIT,
io::Error::from_raw_os_error(status),
status
);
}
}