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

ruby-changes:27297

From: kosaki <ko1@a...>
Date: Thu, 21 Feb 2013 13:41:10 +0900 (JST)
Subject: [ruby-changes:27297] kosaki:r39349 (trunk): * file.c (rb_group_member): get rid of NGROUPS dependency.

kosaki	2013-02-21 13:40:58 +0900 (Thu, 21 Feb 2013)

  New Revision: 39349

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

  Log:
    * file.c (rb_group_member): get rid of NGROUPS dependency.
      [Bug #7886] [ruby-core:52537]

  Modified files:
    trunk/ChangeLog
    trunk/file.c
    trunk/test/ruby/test_process.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39348)
+++ ChangeLog	(revision 39349)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Feb 21 12:56:19 2013  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* file.c (rb_group_member): get rid of NGROUPS dependency.
+	  [Bug #7886] [ruby-core:52537]
+
 Thu Feb 21 12:45:03 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* ruby.c (ruby_init_loadpath_safe): try two levels upper for stripping
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 39348)
+++ test/ruby/test_process.rb	(revision 39349)
@@ -1588,6 +1588,8 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1588
 	sleep
 EOS
       begin
+        sleep 0.1
+
         # test Process.getsid() w/o arg
         assert_equal(Marshal.load(io), Process.getsid)
 
Index: file.c
===================================================================
--- file.c	(revision 39348)
+++ file.c	(revision 39349)
@@ -1013,39 +1013,52 @@ rb_file_lstat(VALUE obj) https://github.com/ruby/ruby/blob/trunk/file.c#L1013
 #endif
 }
 
+/* Linux allow 65536 groups and it is maximum value as far as we know. */
+#define RUBY_GROUP_MAX 65536
+
 static int
 rb_group_member(GETGROUPS_T gid)
 {
+#ifdef _WIN32
+    return FALSE;
+#else
     int rv = FALSE;
-#ifndef _WIN32
+    int groups = 16;
+    VALUE v = 0;
+    GETGROUPS_T *gary;
+    int anum;
+
     if (getgid() == gid || getegid() == gid)
 	return TRUE;
 
-# ifdef HAVE_GETGROUPS
-#  ifndef NGROUPS
-#   ifdef NGROUPS_MAX
-#    define NGROUPS NGROUPS_MAX
-#   else
-#    define NGROUPS 32
-#   endif
-#  endif
-    {
-	GETGROUPS_T *gary;
-	int anum;
-
-	gary = xmalloc(NGROUPS * sizeof(GETGROUPS_T));
-	anum = getgroups(NGROUPS, gary);
-	while (--anum >= 0) {
-	    if (gary[anum] == gid) {
-		rv = TRUE;
-		break;
-	    }
+    /*
+     * On Mac OS X (Mountain Lion), NGROUPS is 16. But libc and kernel
+     * accept more larger value.
+     * So we don't trunk NGROUPS anymore.
+     */
+    while (groups <= RUBY_GROUP_MAX) {
+	gary = ALLOCV_N(GETGROUPS_T, v, groups);
+	anum = getgroups(groups, gary);
+	if (anum != groups)
+	    break;
+	groups *= 2;
+	if (v) {
+	    ALLOCV_END(v);
+	    v = 0;
 	}
-	xfree(gary);
     }
-# endif
-#endif
+
+    while (--anum >= 0) {
+	if (gary[anum] == gid) {
+	    rv = TRUE;
+	    break;
+	}
+    }
+    if (v)
+	ALLOCV_END(v);
+
     return rv;
+#endif
 }
 
 #ifndef S_IXUGO

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

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