Merge pull request #51 from trapexit/rlimits

Try RLIMIT_INFINITY first, then cur = max, then loop and try to increase...
This commit is contained in:
Antonio SJ Musumeci 2015-02-17 11:48:55 -05:00
commit e0f0bb53f7

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