[前][次][番号順一覧][スレッド一覧]

ruby-changes:19009

From: kosaki <ko1@a...>
Date: Mon, 7 Mar 2011 20:58:18 +0900 (JST)
Subject: [ruby-changes:19009] Ruby:r31047 (trunk): * process.c (proc_getmaxgroups, proc_setmaxgroups): refrect

kosaki	2011-03-07 20:58:12 +0900 (Mon, 07 Mar 2011)

  New Revision: 31047

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31047

  Log:
    * process.c (proc_getmaxgroups, proc_setmaxgroups): refrect
      platform maxgroups limitation by default instead hardcoded 65536.

  Modified files:
    trunk/ChangeLog
    trunk/process.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31046)
+++ ChangeLog	(revision 31047)
@@ -1,3 +1,8 @@
+Mon Mar  7 20:49:12 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* 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@r...>
 
 	* gc.c (rb_gc_set_params): allow GC parameter configuration by
Index: process.c
===================================================================
--- process.c	(revision 31046)
+++ process.c	(revision 31047)
@@ -4541,9 +4541,20 @@
  * 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
 /*
  *  call-seq:
@@ -4608,8 +4619,8 @@
     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 @@
 static VALUE
 proc_getmaxgroups(VALUE obj)
 {
-    return INT2FIX(maxgroups);
+    return INT2FIX(maxgroups());
 }
 
 
@@ -4707,6 +4718,7 @@
 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 @@
     if (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))

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]