Project

General

Profile

Actions

Bug #14969

closed

Process.groups が返す GID が重複している場合がある

Added by mrkn (Kenta Murata) over 5 years ago. Updated over 5 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.6.0dev (2018-08-06 arith_seq 64201) [x86_64-linux]
[ruby-dev:50603]

Description

Ubuntu 16.04 から 18.04 にアップグレードした環境で以下の ruby spec が失敗することに気づきました。

1)
Process.groups gets an Array of the gids of groups in the supplemental group access list FAILED
Expected [4, 24, 27, 30, 46, 110, 114, 120, 120, 121]
to equal [4, 24, 27, 30, 46, 110, 114, 120, 121]

/home/mrkn/src/github.com/ruby/ruby/spec/ruby/core/process/groups_spec.rb:11:in `block (3 levels) in <top (required)>'
/home/mrkn/src/github.com/ruby/ruby/spec/ruby/core/process/groups_spec.rb:3:in `<top (required)>'

根本原因は、この環境に GID=120 のグループが2つ存在するからでした。

$ grep 120 /etc/group
libvirtd:x:120:mrkn
libvirt:x:120:mrkn

Ubuntu の Yakkety を堺にグループ名が libvirtd から libvirt に変わったらしく、私が 16.04 → 18.04 というアップグレードをしたことでこのような状態を作ってしまったようです。

https://help.ubuntu.com/lts/serverguide/libvirt.html.en

In more recent releases (>= Yakkety) the group was renamed to libvirt. Upgraded systems get a new libvirt group with the same gid as the libvirtd group to match that.

失敗したテストは、Process.groupsid -G の結果をソートして比較するものです。Process.groups が中で使っている getgroups(2) は重複した gid があっても重複したまま返すけど、id -G コマンドは結果を uniq して返すので、両者の内容が異なっていてテストが失敗しています。

私は getgroups(2) や Process.groups の用途を正確に理解していないので、Process.groups の方を弄るべきか、失敗したテストを修正すべきか判断できません。
どなたかこの件に詳しい方、どのように修正すべきか教えて頂けますか。

Updated by mame (Yusuke Endoh) over 5 years ago

Process.groupsはgetgroups(2)のラッパってことで、重複を省くなどの余計なことはしない、に一票です。
idコマンドの結果を期待値にしているspecの方にそもそも無理を感じます。なので、specの方をいじる、でよいのではないでしょうか。

Updated by kosaki (Motohiro KOSAKI) over 5 years ago

Process.groupsが
・結果が昇順にソートされている保証はない(OS依存)
・Effective gidが入っているかどうかはOS依存
・重複するIDはそのままarrayに入っていることもあれば、重複が取り除かれていることもある(OS依存)
というあたりは、ドキュメントに記載してもいいのではないかと思いました

Updated by kosaki (Motohiro KOSAKI) over 5 years ago

つまり、
・specを直すに賛成である
・ただ、API docで Process.groups.sort.uniq がふつうの使い方みたいに教えてあげるのが親切と思う
の2つが意見です

Updated by znz (Kazuhiro NISHIYAMA) over 5 years ago

(シェルスクリプトの uniq と違って) ruby の uniq は sort 済みかどうかに依存していないので、 .sort.uniq よりも .uniq.sort の方が良いと思います。

Updated by mrkn (Kenta Murata) over 5 years ago

  • Status changed from Open to Assigned
  • Assignee set to mrkn (Kenta Murata)
Actions #6

Updated by mrkn (Kenta Murata) over 5 years ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r64265.


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]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0