]> git.lizzy.rs Git - rust.git/commitdiff
Add a safety check for compiletest rlimit
authorvarkor <github@varkor.com>
Thu, 9 Aug 2018 18:40:49 +0000 (19:40 +0100)
committervarkor <github@varkor.com>
Thu, 9 Aug 2018 18:40:49 +0000 (19:40 +0100)
src/tools/compiletest/src/raise_fd_limit.rs

index 220082799a8b081430a128853a63d10482ebb520..d1071231530d68f6929e0fb2b3814593f1f7c834 100644 (file)
@@ -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);
+        }
     }
 }