This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.getlogin() goes **poof**
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, wilson1442
Priority: normal Keywords:

Created on 2006-01-12 20:59 by wilson1442, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg27287 - (view) Author: Jim Wilson (wilson1442) Date: 2006-01-12 20:59
"python -c "import os; getlogin()" rears its ugly head
again.  It complains it can't open "<string>" (Python
2.4.1, FC4).

Strace confirms it:

open("<string>", ...)  = -1 ENOENT (No such file or ...
open("<string>", ...)  = -1 ENOENT ...
open("/usr/lib/python24.zip/<string>", ...) = -1 ...
open("/usr/lib/python2.4/<string>", ...) = -1 ...
open("/usr/lib/python2.4/plat-linux2/<string>", ... 
open("/usr/lib/python2.4/lib-tk/<string>", ...
open("/usr/lib/python2.4/lib-dynload/<string>", ...
open("/usr/lib/python2.4/site-packages/<string>", ... 
[<two more long obscure directories>/<string> snipped.]

I don't know what's in that "<string>" file, but it
surely must be important.
msg27288 - (view) Author: Jim Wilson (wilson1442) Date: 2006-01-12 21:17
Logged In: YES 
user_id=1191155

Er...  Of course, I intended:

python -c "import os; os.getlogin()"

diagnostic output was from:

strace -e trace=open python -c "import os; os.getlogin()"
msg27289 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-01-12 21:34
Logged In: YES 
user_id=1188172

Your diagnosis is incorrect. The system's getlogin() sets
errno 2, that is "No such file or directory". Thus
os.getlogin() raises an OSError with this description.

Python's "file name" for -c scripts is "<string>", and
because Python wants to give you a traceback with lines and
code context, it looks for the file "<string>". This has
nothing to do with getlogin.
msg27290 - (view) Author: Jim Wilson (wilson1442) Date: 2006-01-12 21:58
Logged In: YES 
user_id=1191155

Actually, my diagnosis was meant to be jocular.  I don't
have a clue what's happening.  Someone else suggested using
strace when this problem was reported earlier.  Your
explanation makes perfect sense.

But ... that certainly narrows it down.  If it ain't
"os.getlogin()", that leaves only "import os;", right?
msg27291 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-01-12 22:10
Logged In: YES 
user_id=1188172

It is os.getlogin(), but the search for <string> doesn't
have to do anything with it.

As for why getlogin() is failing, consult your local manpage
for details what getlogin() is doing (wrong).
msg27292 - (view) Author: Jim Wilson (wilson1442) Date: 2006-01-12 22:11
Logged In: YES 
user_id=1191155

OK.  Skip it.  I "man getlogin()", and sure enough, it can
ENOENT "when there's no entry in the utmp-file" (whatever
the hell that is).  It looks like getlogin() is sufficiently
broken that it should never be used.

Thanks for the guidance.
History
Date User Action Args
2022-04-11 14:56:14adminsetgithub: 42791
2006-01-12 20:59:53wilson1442create