Index: appfsd.c ================================================================== --- appfsd.c +++ appfsd.c @@ -19,12 +19,14 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #define FUSE_USE_VERSION 26 +#include #include #include +#include #include #include #include #include #include @@ -2169,13 +2171,15 @@ */ int main(int argc, char **argv) { Tcl_Interp *test_interp; char *test_interp_error; struct fuse_args args = FUSE_ARGS_INIT(0, NULL); - int pthread_ret, aop_ret; + struct rlimit number_open_files; + int pthread_ret, aop_ret, rlimit_ret; void *signal_ret; char *argv0; + rlim_t number_open_files_max; /* * Skip passed program name */ if (argc == 0 || argv == NULL) { @@ -2303,13 +2307,46 @@ Tcl_DeleteInterp(test_interp); if (appfs_threaded_tcl) { Tcl_FinalizeNotifier(NULL); } + + /* + * Increase resource limits for number of open files + * to the maximum values, since we may be asked to + * hold open many files on behalf of many other processes + */ + number_open_files.rlim_cur = number_open_files.rlim_max = RLIM_INFINITY; + + rlimit_ret = setrlimit(RLIMIT_NOFILE, &number_open_files); + + if (rlimit_ret != 0) { + rlimit_ret = getrlimit(RLIMIT_NOFILE, &number_open_files); + if (rlimit_ret == 0) { + number_open_files_max = number_open_files.rlim_max; + + if (number_open_files_max < (1024 * 1024)) { + number_open_files.rlim_cur = number_open_files.rlim_max = 1024 * 1024; + + rlimit_ret = setrlimit(RLIMIT_NOFILE, &number_open_files); + } else { + number_open_files.rlim_cur = number_open_files.rlim_max; + } + + rlimit_ret = setrlimit(RLIMIT_NOFILE, &number_open_files); + + if (rlimit_ret != 0 && number_open_files.rlim_cur != number_open_files_max) { + number_open_files.rlim_cur = number_open_files.rlim_max = number_open_files_max; + + setrlimit(RLIMIT_NOFILE, &number_open_files); + } + } + } + /* * Enter the FUSE main loop -- this will process any arguments * and start servicing requests. */ appfs_fuse_started = 1; return(fuse_main(args.argc, args.argv, &appfs_operations, NULL)); }