简体   繁体   English

“getgroups”的奇怪行为

[英]Strange behavier of "getgroups"

I'm working on a little learning project,need to call "getgroups(int gidsetsize, gid_t grouplist[])" I'v got "0" result of an id should have a list.我正在做一个小学习项目,需要调用“getgroups(int gidsetsize, gid_t grouplist[])”我得到一个 id 的“0”结果应该有一个列表。

while checking all possibilities,I found out the user's group must not be "0",or the function won't return none 0 result.在检查所有可能性时,我发现用户组不能为“0”,否则 function 不会返回 none 0 结果。 but i'm only meet this problem on my own computer which running archlinux.但我只在我自己运行 archlinux 的计算机上遇到这个问题。 I checked virtual machine which use manjaro or ubuntu,none of them has the problem, a co-league has an vps which use arch too do not has the problem.我检查了使用 manjaro 或 ubuntu 的虚拟机,它们都没有问题,一个联盟有一个使用 arch 的 vps 也没有问题。

arch bbs replied "the gid of user should not be 0",but it couldn't explain why my machine is the only one has the problem. arch bbs 回复“用户的gid 不应该是0”,但它无法解释为什么只有我的机器有问题。

I'v compared id output before the post.我在帖子之前比较了 id output。

Only the physical machine give me NULL list,and the strace output is different只有物理机给我 NULL 列表,而 strace output 是不同的

my machine result我的机器结果

    rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
    getgroups(0, NULL)                     = 0
    getgroups(0, [])                        = 0
    newfstatat(AT_FDCWD, "/etc/nsswitch.conf", {st_mode=S_IFREG|0644, st_size=359, ...}, 0) = 0

other machine's the first getgroups will return none 0 result,and then,the 2nd will use the result as the 1st para to get a list.其他机器的第一个 getgroups 将返回 none 0 结果,然后,第二个将使用结果作为第一个 para 来获取列表。 I couldn't find the difference by myself.我自己找不到区别。

The ubuntu vm result ubuntu 虚拟机结果

getgroups(0, NULL)                      = 7
getgroups(7, [0, 4, 24, 27, 30, 46, 110])                        = 7

"id" command only return the none zero result to get "self" result but not other's because of different execution branch.由于不同的执行分支,“id”命令只返回非零结果以获得“self”结果而不返回其他结果。

Tried edit the user's gid to none 0,after reboot,the result going to normal试过将用户的gid修改为none 0,重启后,结果正常

Change gid back to 0 again,after reboot,the result is NULL again.再次将gid改回0,重启后,结果又是NULL。 Might be something about user namespace?可能与用户命名空间有关?

Any suggestions?有什么建议么?

edit,more info:编辑,更多信息:

Seems the problem is related to "WHO IS THE FATHER".似乎问题与“WHO IS THE FATHER”有关。 When the process is child(or grand child etc.) of当过程是孩子(或孙子等)时

/usr/lib/systemd/systemd --user

getgroups will give bad result. getgroups 会产生不好的结果。

When not(running on i3wm,the process has no father)the result is good如果不是(在 i3wm 上运行,进程没有父亲)结果很好

following the trace of systemd,arch bbs give me this.跟随 systemd 的踪迹,arch bbs 给我这个。

User service not running with supplementary groups用户服务未与补充组一起运行

------------EDIT--------------- - - - - - - 编辑 - - - - - - - -

It's not the same problem,possible another bug.这不是同一个问题,可能是另一个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM