* <b>*limit</b>. Return a new limit if we can, or -1 if we fail. */
intset_max_file_descriptors(intlimit,intcap){
#ifndef HAVE_GETRLIMIT
log_fn(LOG_INFO,"This platform is missing getrlimit(). Proceeding.");
return0;/* hope we'll be ok */
if(limit>cap){
log(LOG_INFO,"ConnLimit must be at most %d. Capping it.",cap);
limit=cap;
}
#else
structrlimitrlim;
intmost;
if(getrlimit(RLIMIT_NOFILE,&rlim)!=0){
log_fn(LOG_WARN,"Could not get maximum number of file descriptors: %s",
strerror(errno));
return-1;
}
if(required_min>rlim.rlim_max){
log_fn(LOG_WARN,"We need %u file descriptors available, and we're limited to %lu. Please change your ulimit.",required_min,(unsignedlongint)rlim.rlim_max);
if(rlim.rlim_max<limit){
log_fn(LOG_WARN,"We need %d file descriptors available, and we're limited to %lu. Please change your ulimit -n.",limit,(unsignedlongint)rlim.rlim_max);
return-1;
}
if(required_min>rlim.rlim_cur){
log_fn(LOG_INFO,"Raising max file descriptors from %lu to %lu.",