Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.getlogin should use the DISPLAY and not the tty #45159

Closed
snoiraud mannequin opened this issue Jul 8, 2007 · 2 comments
Closed

os.getlogin should use the DISPLAY and not the tty #45159

snoiraud mannequin opened this issue Jul 8, 2007 · 2 comments

Comments

@snoiraud
Copy link
Mannequin

snoiraud mannequin commented Jul 8, 2007

BPO 1750013
Nosy @loewis

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2007-07-10.08:45:31.000>
created_at = <Date 2007-07-08.20:02:21.000>
labels = ['invalid']
title = 'os.getlogin should use the DISPLAY and not the tty'
updated_at = <Date 2007-07-10.08:45:31.000>
user = 'https://bugs.python.org/snoiraud'

bugs.python.org fields:

activity = <Date 2007-07-10.08:45:31.000>
actor = 'loewis'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['None']
creation = <Date 2007-07-08.20:02:21.000>
creator = 'snoiraud'
dependencies = []
files = []
hgrepos = []
issue_num = 1750013
keywords = []
message_count = 2.0
messages = ['32463', '32464']
nosy_count = 2.0
nosy_names = ['loewis', 'snoiraud']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1750013'
versions = []

@snoiraud
Copy link
Mannequin Author

snoiraud mannequin commented Jul 8, 2007

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, ... )

@snoiraud snoiraud mannequin closed this as completed Jul 8, 2007
@snoiraud snoiraud mannequin added the invalid label Jul 8, 2007
@snoiraud snoiraud mannequin closed this as completed Jul 8, 2007
@snoiraud snoiraud mannequin added the invalid label Jul 8, 2007
@loewis
Copy link
Mannequin

loewis mannequin commented Jul 10, 2007

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.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants