Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

logname may not produce a login name

Aperta
#898 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
ruby
Ambito
testing-qa

Direzione di ricerca

Inizia da spec/ruby/library/etc/getlogin_spec.rb:22 e riproduci l’esempio non funzionante di Etc.getlogin su JRuby nell’ambiente GitHub Actions. Confronta i comandi disponibili per ottenere il nome di accesso e il valore dell’ambiente descritto nell’issue, quindi fai in modo che la spec gestisca gli ambienti senza un terminale di controllo. Il lavoro è completato quando la spec passa su JRuby mantenendo un fallback quando i comandi non sono disponibili.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Ruby
Stelle
622
Fork
402
Merge medio
14h 51m
PR unite (30g)
6

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/spec

Tutte le issue di ruby/spec

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.