aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--file.c59
-rw-r--r--test/ruby/test_process.rb2
3 files changed, 43 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index a06125b65e..be4e91b850 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Feb 21 12:56:19 2013 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
+
+ * 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@ruby-lang.org>
* ruby.c (ruby_init_loadpath_safe): try two levels upper for stripping
diff --git a/file.c b/file.c
index 08cd5f8dcf..1cc6066e99 100644
--- a/file.c
+++ b/file.c
@@ -1013,39 +1013,52 @@ rb_file_lstat(VALUE obj)
#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
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index 6616955502..049446334e 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -1588,6 +1588,8 @@ class TestProcess < Test::Unit::TestCase
sleep
EOS
begin
+ sleep 0.1
+
# test Process.getsid() w/o arg
assert_equal(Marshal.load(io), Process.getsid)