* process.c (proc_getmaxgroups, proc_setmaxgroups): refrect

platform maxgroups limitation by default instead hardcoded 65536.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kosaki 2011-03-07 11:58:12 +00:00
parent 1df42597d1
commit 1a8ee910f3
2 changed files with 26 additions and 6 deletions

View File

@ -1,3 +1,8 @@
Mon Mar 7 20:49:12 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* process.c (proc_getmaxgroups, proc_setmaxgroups): refrect
platform maxgroups limitation by default instead hardcoded 65536.
Mon Mar 7 17:13:00 2011 Yukihiro Matsumoto <matz@ruby-lang.org> Mon Mar 7 17:13:00 2011 Yukihiro Matsumoto <matz@ruby-lang.org>
* gc.c (rb_gc_set_params): allow GC parameter configuration by * gc.c (rb_gc_set_params): allow GC parameter configuration by

View File

@ -4541,7 +4541,18 @@ proc_setgid(VALUE obj, VALUE id)
* Windows 1015 * Windows 1015
*/ */
#define RB_MAX_GROUPS (65536) #define RB_MAX_GROUPS (65536)
static int maxgroups = RB_MAX_GROUPS; static int _maxgroups = -1;
static int maxgroups(void)
{
if (_maxgroups < 0) {
_maxgroups = sysconf(_SC_NGROUPS_MAX);
if (_maxgroups < 0)
_maxgroups = RB_MAX_GROUPS;
}
return _maxgroups;
}
#ifdef HAVE_GETGROUPS #ifdef HAVE_GETGROUPS
@ -4608,8 +4619,8 @@ proc_setgroups(VALUE obj, VALUE ary)
Check_Type(ary, T_ARRAY); Check_Type(ary, T_ARRAY);
ngroups = RARRAY_LEN(ary); ngroups = RARRAY_LEN(ary);
if (ngroups > (size_t)maxgroups) if (ngroups > (size_t)maxgroups())
rb_raise(rb_eArgError, "too many groups, %u max", maxgroups); rb_raise(rb_eArgError, "too many groups, %u max", maxgroups());
groups = ALLOCA_N(rb_gid_t, ngroups); groups = ALLOCA_N(rb_gid_t, ngroups);
@ -4691,7 +4702,7 @@ proc_initgroups(VALUE obj, VALUE uname, VALUE base_grp)
static VALUE static VALUE
proc_getmaxgroups(VALUE obj) proc_getmaxgroups(VALUE obj)
{ {
return INT2FIX(maxgroups); return INT2FIX(maxgroups());
} }
@ -4707,6 +4718,7 @@ static VALUE
proc_setmaxgroups(VALUE obj, VALUE val) proc_setmaxgroups(VALUE obj, VALUE val)
{ {
int ngroups = FIX2INT(val); int ngroups = FIX2INT(val);
int ngroups_max = sysconf(_SC_NGROUPS_MAX);
if (ngroups <= 0) if (ngroups <= 0)
rb_raise(rb_eArgError, "maxgroups %d shold be positive", ngroups); rb_raise(rb_eArgError, "maxgroups %d shold be positive", ngroups);
@ -4714,9 +4726,12 @@ proc_setmaxgroups(VALUE obj, VALUE val)
if (ngroups > RB_MAX_GROUPS) if (ngroups > RB_MAX_GROUPS)
ngroups = RB_MAX_GROUPS; ngroups = RB_MAX_GROUPS;
maxgroups = ngroups; if (ngroups_max > 0 && ngroups > ngroups_max)
ngroups = ngroups_max;
return INT2FIX(maxgroups); _maxgroups = ngroups;
return INT2FIX(_maxgroups);
} }
#if defined(HAVE_DAEMON) || (defined(HAVE_FORK) && defined(HAVE_SETSID)) #if defined(HAVE_DAEMON) || (defined(HAVE_FORK) && defined(HAVE_SETSID))