logname may not produce a login name
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- ruby
- 领域
- testing-qa
调研方向
从 spec/ruby/library/etc/getlogin_spec.rb:22 开始,在 GitHub Actions 环境中的 JRuby 上重现失败的 Etc.getlogin 示例。比较可用的登录名命令和 issue 中描述的环境值,然后让 spec 处理没有控制终端的环境。当 spec 在 JRuby 上通过,同时在命令不可用时保留回退方案,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Running the specs on JRuby on Github Actions, we see the following message and failing spec:
...
logname: no login name
...
1)
Etc.getlogin returns the name associated with the current login activity FAILED
Expected "runner" == ""
to be truthy but was false
/home/runner/work/jruby/jruby/spec/ruby/library/etc/getlogin_spec.rb:22:in `block in <main>'
...
This can occur when logname is run without a controlling terminal. I'm unsure whether this GHA env is not setting up a tty, or if there's an issue launching the command in JRuby that prevents it inheriting the parent terminal, but it seems like id would be a more reliable command to use:
diff --git a/spec/ruby/library/etc/getlogin_spec.rb b/spec/ruby/library/etc/getlogin_spec.rb
index 7a4fd79ae2..f0dde84ccb 100644
--- a/spec/ruby/library/etc/getlogin_spec.rb
+++ b/spec/ruby/library/etc/getlogin_spec.rb
@@ -18,11 +18,13 @@ describe "Etc.getlogin" do
else
# Etc.getlogin returns the same result of logname(2)
# if it returns non NULL
- if system("which logname", out: File::NULL, err: File::NULL)
+ if system("which id", out: File::NULL, err: File::NULL)
+ Etc.getlogin.should == `id -un`.chomp
+ elsif system("which logname", out: File::NULL, err: File::NULL)
+ # fallback to `logname` command since `id` is not available
Etc.getlogin.should == `logname`.chomp
else
- # fallback to `id` command since `logname` is not available
- Etc.getlogin.should == `id -un`.chomp
+ Etc.getlogin.should == ENV['LOGNAME']
end
end
else
However I think we are also stacking too many conditions here. I'm unsure of the "best" way to get the current login, but clearly logname has issues that make it undesirable.
FWIW some forums suggest logname -t which will ensure a tty is created, but this flag is not present on BSD-likes.
- 主要语言
- Ruby
- 星标
- 622
- 派生
- 402
- 平均合并
- 14 小时 51 分钟
- 30 天内合并 PR
- 6
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/spec 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 52/100
-
难度 4/5 3-5 天 新手友好度 38/100
-
难度 5/5 一周以上 新手友好度 35/100
-
难度 3/5 1-2 天 新手友好度 38/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
simp/pupmod-simp-simp#395 ·
-
难度 2/5 1-3 小时 新手友好度 80/100
simp/pupmod-simp-rsyslog#219 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
simp/pupmod-simp-pupmod#256 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
simp/pupmod-simp-sudo#150 ·
-
难度 1/5 1 小时以内 新手友好度 90/100