[ python-Bugs-1750013 ] os.getlogin should use the DISPLAY and not the tty
SourceForge.net
noreply at sourceforge.net
Tue Jul 10 10:45:31 CEST 2007
Bugs item #1750013, was opened at 2007-07-08 22:02
Message generated for change (Comment added) made by loewis
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1750013&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
>Status: Closed
>Resolution: Invalid
Priority: 5
Private: No
Submitted By: Serge Noiraud (snoiraud)
Assigned to: Nobody/Anonymous (nobody)
Summary: os.getlogin should use the DISPLAY and not the tty
Initial Comment:
Hi,
I have the following with gramps on kubuntu ( KDE ).
My terminals are "konsole". They don't register their pty
in utmp and I think they are correct. We are already logged. so if we register again for each konsole, we have a bad user count.
In these case, os.getlogin() return :
OSError: [Errno 2] No such file or directory
I think getlogin should use the DISPLAY instead of the tty when we get this error.
to correct this problem I use :
try:
user=os.getlogin()
except:
user=os.environ.get("USER")
but I'm not sure os.environ.get return the good value on every OSes ...
I have tested too :
except:
user = pwd.getpwuid(os.getuid())[0]
What is the best solution to this problem.
I looked at all bugs about getlogin and I saw we should avoid this function.
What is in this case the function we should use and which works correctly on every OS ( Linux, Unices, Windows, MAC OS/X, ... )
----------------------------------------------------------------------
>Comment By: Martin v. Löwis (loewis)
Date: 2007-07-10 10:45
Message:
Logged In: YES
user_id=21627
Originator: NO
os.getlogin is a wrapper around the getlogin(3) POSIX function. It is
important that Python exposes the function as-is, rather than trying to be
more clever than the operating system designers. getlogin(3) is specified
as "getlogin() returns a pointer to a string containing the name of the
user logged in on the controlling terminal of the process, or a null
pointer if this information cannot be determined." See the man page for the
precise list of error conditions; ENOENT is returned if there is no utmp
entry.
Whether konsole is correct in not listing the controlling terminal in
utmp, I don't know. Notice that xterm (which should be considered an
authority in such matters) *does* create an utmp entry.
It's not clear to me how DISPLAY could be used at all, but even if it
could, using it here would be incorrect.
Closing as invalid.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1750013&group_id=5470
More information about the Python-bugs-list
mailing list