classification
Title: os.getlogin should use the DISPLAY and not the tty
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: loewis, snoiraud (2)
Priority: normal Keywords

Created on 2007-07-08 20:02 by snoiraud, last changed 2007-07-10 08:45 by loewis.

Messages (2)
msg32463 - (view) Author: Serge Noiraud (snoiraud) Date: 2007-07-08 20:02
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, ... )
msg32464 - (view) Author: Martin v. Löwis (loewis) Date: 2007-07-10 08:45
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.
History
Date User Action Args
2007-07-08 20:02:21snoiraudcreate