added a function set_maxfiles() to set our file rlimit to the max
authorAndrew Tridgell <tridge@samba.org>
Mon, 5 Oct 1998 01:57:03 +0000 (01:57 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 5 Oct 1998 01:57:03 +0000 (01:57 +0000)
possible and return the max.

source/include/proto.h
source/lib/util.c
source/smbd/files.c
source/smbwrapper/smbw.c

index f89b7a7ff51f8d6a69f7b269b913afccad24cbf7..0736e3f5bdc92f016db32906f8a9ff396101e52a 100644 (file)
@@ -347,6 +347,7 @@ char *sid_to_string(pstring sidstr_out, DOM_SID *sid);
 BOOL string_to_sid(DOM_SID *sidout, char *sidstr);
 int str_checksum(const char *s);
 void zero_free(void *p, size_t size);
+int set_maxfiles(void);
 
 /*The following definitions come from  libsmb/clientgen.c  */
 
index 38cde624d4f46c90ef921700d98c9e624388ce36..d079f86988212c779b6d7221babbc97648353101 100644 (file)
@@ -4845,3 +4845,26 @@ void zero_free(void *p, size_t size)
        free(p);
 }
 
+
+/*****************************************************************
+set our open file limit to the max and return the limit
+*****************************************************************/  
+int set_maxfiles(void)
+{
+#if (defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE))
+       struct rlimit rlp;
+       getrlimit(RLIMIT_NOFILE, &rlp);
+       /* Set the fd limit to be real_max_open_files + MAX_OPEN_FUDGEFACTOR to
+        * account for the extra fd we need 
+        * as well as the log files and standard
+        * handles etc.  */
+       rlp.rlim_cur = rlp.rlim_max;
+       setrlimit(RLIMIT_NOFILE, &rlp);
+       getrlimit(RLIMIT_NOFILE, &rlp);
+       return rlp.rlim_cur;
+#else
+       /* just guess ... */
+       return 1024;
+#endif
+}
+
index 4000439db0e1aec40ae4680f3559015fb2cbfe28..6afa0597535ba18416078361eab58d662be76863 100644 (file)
@@ -202,38 +202,19 @@ initialise file structures
 
 void file_init(void)
 {
-    real_max_open_files = lp_max_open_files();
-
-#if (defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE))
-       {
-               struct rlimit rlp;
-               getrlimit(RLIMIT_NOFILE, &rlp);
-               /* Set the fd limit to be real_max_open_files + MAX_OPEN_FUDGEFACTOR to
-                * account for the extra fd we need 
-                * as well as the log files and standard
-                * handles etc.  */
-               rlp.rlim_cur = (real_max_open_files+MAX_OPEN_FUDGEFACTOR>rlp.rlim_max)? 
-                       rlp.rlim_max:real_max_open_files+MAX_OPEN_FUDGEFACTOR;
-               setrlimit(RLIMIT_NOFILE, &rlp);
-               getrlimit(RLIMIT_NOFILE, &rlp);
-        if(rlp.rlim_cur != (real_max_open_files + MAX_OPEN_FUDGEFACTOR))
-          DEBUG(0,("file_init: Maximum number of open files requested per session \
-was %d, actual files available  per session = %d\n", 
-                real_max_open_files, (int)rlp.rlim_cur - MAX_OPEN_FUDGEFACTOR ));
-
-        DEBUG(2,("Maximum number of open files per session is %d\n", 
-              (int)rlp.rlim_cur - MAX_OPEN_FUDGEFACTOR));
-
-        real_max_open_files = (int)rlp.rlim_cur - MAX_OPEN_FUDGEFACTOR;
-       }
-#endif
+       int real_max_open_files, lim;
 
-       file_bmap = bitmap_allocate(real_max_open_files);
+       lim = set_maxfiles();
+       lim = MIN(lim, lp_max_open_files());
 
+       real_max_open_files = lim - MAX_OPEN_FUDGEFACTOR;
+       
+       file_bmap = bitmap_allocate(real_max_open_files);
+       
        if (!file_bmap) {
                exit_server("out of memory in file_init");
        }
-
+       
        /*
         * Ensure that pipe_handle_oppset is set correctly.
         */
index e76b42692eb91d58cbed390c70e150cce53e139a..633e63ef8d5b5a4dd19cf72f5efb92925186f39e 100644 (file)
@@ -87,6 +87,8 @@ void smbw_init(void)
                DEBUG(4,("Initial cwd from getwd is %s\n", smb_cwd));
        }
        smbw_busy--;
+
+       set_maxfiles();
 }
 
 /*****************************************************