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

ruby-changes:52057

From: mrkn <ko1@a...>
Date: Fri, 10 Aug 2018 14:18:09 +0900 (JST)
Subject: [ruby-changes:52057] mrkn:r64265 (trunk): process.c: fix rubyspec of Process.groups

mrkn	2018-08-10 14:18:03 +0900 (Fri, 10 Aug 2018)

  New Revision: 64265

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64265

  Log:
    process.c: fix rubyspec of Process.groups
    
    getgroups(2) may return a GID list that includes duplicated GIDs.
    The behavior is totaly depends on what OS is used.
    
    This commit fixes the example of Process.groups so that the example
    is independent of this OS-dependent features.
    
    Additonaly, this commit adds the description of such system-dependent
    characteristics of Process.groups.
    
    [ruby-dev:50603] [Bug #14969]

  Modified files:
    trunk/process.c
    trunk/spec/ruby/core/process/groups_spec.rb
Index: process.c
===================================================================
--- process.c	(revision 64264)
+++ process.c	(revision 64265)
@@ -6136,6 +6136,19 @@ maxgroups(void) https://github.com/ruby/ruby/blob/trunk/process.c#L6136
  *
  *     Process.groups   #=> [27, 6, 10, 11]
  *
+ *  Note that this method is just a wrapper of getgroups(2).
+ *  This means that the following characteristics of
+ *  the results are completely depends on your system:
+ *
+ *  - the result is sorted
+ *  - the result includes effective GIDs
+ *  - the result does not include duplicated GIDs
+ *
+ *  You can certainly get a sorted unique GID list of
+ *  the current process by this expression:
+ *
+ *     Process.groups.unique.sort
+ *
  */
 
 static VALUE
Index: spec/ruby/core/process/groups_spec.rb
===================================================================
--- spec/ruby/core/process/groups_spec.rb	(revision 64264)
+++ spec/ruby/core/process/groups_spec.rb	(revision 64265)
@@ -6,8 +6,8 @@ describe "Process.groups" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/process/groups_spec.rb#L6
       groups = `id -G`.scan(/\d+/).map { |i| i.to_i }
       gid = Process.gid
 
-      expected = (groups.sort - [gid]).sort
-      actual = (Process.groups - [gid]).sort
+      expected = (groups.sort - [gid]).uniq.sort
+      actual = (Process.groups - [gid]).uniq.sort
       actual.should == expected
     end
   end

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

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