Index: /tmp/exechelp-posix.c =================================================================== --- /tmp/exechelp-posix.c +++ /tmp/exechelp-posix.c @@ -76,44 +76,62 @@ int get_max_fds (void) { - int max_fds = -1; + int max_fds = INT32_MAX; + +#if 0 +fprintf(stderr,"start:\t\tmax_fds:%10d\n", max_fds); +#endif #ifdef HAVE_GETRLIMIT struct rlimit rl; # ifdef RLIMIT_NOFILE if (!getrlimit (RLIMIT_NOFILE, &rl)) max_fds = rl.rlim_max; +#if 0 +fprintf(stderr,"RLIMIT_NOFILE:\tmax_fds:%10d\n", max_fds); +#endif # endif # ifdef RLIMIT_OFILE - if (max_fds == -1 && !getrlimit (RLIMIT_OFILE, &rl)) - max_fds = rl.rlim_max; + if (!getrlimit (RLIMIT_OFILE, &rl)) + max_fds = (rl.rlim_max < max_fds) ? rl.rlim_max : max_fds; +#if 0 +fprintf(stderr,"RLIMIT_OFILE:\tmax_fds:%10d\n", max_fds); +#endif # endif #endif /*HAVE_GETRLIMIT*/ #ifdef _SC_OPEN_MAX - if (max_fds == -1) { long int scres = sysconf (_SC_OPEN_MAX); if (scres >= 0) - max_fds = scres; + max_fds = (scres < max_fds) ? scres : max_fds; +#if 0 +fprintf(stderr,"_SC_OPEN_MAX:\tmax_fds:%10d\n", max_fds); +#endif } #endif #ifdef _POSIX_OPEN_MAX - if (max_fds == -1) - max_fds = _POSIX_OPEN_MAX; + max_fds = (_POSIX_OPEN_MAX < max_fds) ? _POSIX_OPEN_MAX : max_fds; +#if 0 +fprintf(stderr,"_POSIX_OPEN_MAX:max_fds:%10d\n", max_fds); +#endif #endif #ifdef OPEN_MAX - if (max_fds == -1) - max_fds = OPEN_MAX; + max_fds = (OPEN_MAX < max_fds) ? OPEN_MAX : max_fds; +#if 0 +fprintf(stderr,"OPEN_MAX:\tmax_fds:%10d\n", max_fds); +#endif #endif - if (max_fds == -1) - max_fds = 256; /* Arbitrary limit. */ + max_fds = (max_fds > 256) ? 256 : max_fds; +#if 0 +fprintf(stderr,"return:\t\tmax_fds:%10d\n", max_fds); +#endif return max_fds; }