Try RLIMIT_INFINITY first, then cur = max, then loop and try to increase till error. closes #50

This commit is contained in:
Antonio SJ Musumeci 2015-02-17 11:46:54 -05:00
parent dba9e00adc
commit 283a2b2285

View File

@ -42,25 +42,29 @@ namespace mergerfs
int
maxout_rlimit(int resource)
{
int rv;
struct rlimit rlim;
if(geteuid() == 0)
{
rlim.rlim_cur = RLIM_INFINITY;
rlim.rlim_max = RLIM_INFINITY;
}
else
{
int rv;
rlim.rlim_cur = RLIM_INFINITY;
rlim.rlim_max = RLIM_INFINITY;
rv = ::setrlimit(resource,&rlim);
if(rv == 0)
return 0;
rv = ::getrlimit(resource,&rlim);
if(rv == -1)
return -1;
rv = ::getrlimit(resource,&rlim);
if(rv == -1)
return -1;
rlim.rlim_cur = rlim.rlim_max;
rv = 0;
rlim.rlim_cur = rlim.rlim_max;
while(rv == 0)
{
rv = ::setrlimit(resource,&rlim);
rlim.rlim_max *= 2;
rlim.rlim_cur = rlim.rlim_max;
}
return ::setrlimit(resource,&rlim);
return rv;
}
int