diff options
author | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-07 11:58:12 +0000 |
---|---|---|
committer | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-07 11:58:12 +0000 |
commit | 1a8ee910f3f923f50e2b21cd55b8d3ae50eac85a (patch) | |
tree | 7766f13b9c301ada6c0430b6b182c9781283cbe0 | |
parent | 1df42597d15416357a20bd68700ce1a2d245e8bb (diff) | |
download | ruby-1a8ee910f3f923f50e2b21cd55b8d3ae50eac85a.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | process.c | 27 |
2 files changed, 26 insertions, 6 deletions
@@ -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> * gc.c (rb_gc_set_params): allow GC parameter configuration by @@ -4541,7 +4541,18 @@ proc_setgid(VALUE obj, VALUE id) * Windows 1015 */ #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 @@ -4608,8 +4619,8 @@ proc_setgroups(VALUE obj, VALUE ary) Check_Type(ary, T_ARRAY); ngroups = RARRAY_LEN(ary); - if (ngroups > (size_t)maxgroups) - rb_raise(rb_eArgError, "too many groups, %u max", maxgroups); + if (ngroups > (size_t)maxgroups()) + rb_raise(rb_eArgError, "too many groups, %u max", maxgroups()); groups = ALLOCA_N(rb_gid_t, ngroups); @@ -4691,7 +4702,7 @@ proc_initgroups(VALUE obj, VALUE uname, VALUE base_grp) static VALUE proc_getmaxgroups(VALUE obj) { - return INT2FIX(maxgroups); + return INT2FIX(maxgroups()); } @@ -4707,6 +4718,7 @@ static VALUE proc_setmaxgroups(VALUE obj, VALUE val) { int ngroups = FIX2INT(val); + int ngroups_max = sysconf(_SC_NGROUPS_MAX); if (ngroups <= 0) 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) ngroups = RB_MAX_GROUPS; - maxgroups = ngroups; + if (ngroups_max > 0 && ngroups > ngroups_max) + ngroups = ngroups_max; + + _maxgroups = ngroups; - return INT2FIX(maxgroups); + return INT2FIX(_maxgroups); } #if defined(HAVE_DAEMON) || (defined(HAVE_FORK) && defined(HAVE_SETSID)) |