Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

logname may not produce a login name

Abierto
#898 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
ruby
Área
testing-qa

Línea de trabajo

Comienza con spec/ruby/library/etc/getlogin_spec.rb:22 y reproduce el ejemplo fallido de Etc.getlogin en JRuby en el entorno de GitHub Actions. Compara los comandos disponibles para obtener el nombre de inicio de sesión y el valor de entorno descrito en el issue, y luego haz que la spec gestione los entornos sin una terminal de control. La tarea estará terminada cuando la spec pase en JRuby y conserve un fallback cuando los comandos no estén disponibles.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Ruby
Estrellas
622
Forks
402
Merge medio
14 h 51 min
PR fusionados (30 d)
6

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ruby/spec

Todos los issues de ruby/spec

Issues similares

Más issues de Ruby

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.