summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--process.c27
2 files changed, 26 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 3e5a93b23d..064b091215 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/process.c b/process.c
index 8711ab7c90..3da3543e2b 100644
--- a/process.c
+++ b/process.c
@@ -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))