]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Make sure NOFILE resource limit is big enough.
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index c18105fe7822aa57388d40d2228ea97e32c5d29c..3ac63e3a7ff2ae27d1d3c88a13631b92481dc5cf 100644 (file)
--- a/util.c
+++ b/util.c
@@ -28,6 +28,7 @@
 #include       <sys/utsname.h>
 #include       <sys/wait.h>
 #include       <sys/un.h>
+#include       <sys/resource.h>
 #include       <ctype.h>
 #include       <dirent.h>
 #include       <signal.h>
@@ -1959,3 +1960,17 @@ int compare_paths (char* path1, char* path2)
                return 0;
        return 1;
 }
+
+/* Make sure we can open as many devices as needed */
+void enable_fds(int devices)
+{
+       unsigned int fds = 20 + devices;
+       struct rlimit lim;
+       if (getrlimit(RLIMIT_NOFILE, &lim) != 0
+           || lim.rlim_cur >= fds)
+               return;
+       if (lim.rlim_max < fds)
+               lim.rlim_max = fds;
+       lim.rlim_cur = fds;
+       setrlimit(RLIMIT_NOFILE, &lim);
+}