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() not working #84998

Closed
ManickarajaKumarappan mannequin opened this issue May 29, 2020 · 3 comments
Closed

os.getlogin() not working #84998

ManickarajaKumarappan mannequin opened this issue May 29, 2020 · 3 comments
Labels
3.7 (EOL) end of life extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@ManickarajaKumarappan
Copy link
Mannequin

ManickarajaKumarappan mannequin commented May 29, 2020

BPO 40821
Nosy @tiran, @mephinet

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 2021-12-10.11:54:44.241>
created_at = <Date 2020-05-29.20:31:30.406>
labels = ['extension-modules', 'invalid', 'type-bug', '3.7']
title = 'os.getlogin() not working'
updated_at = <Date 2021-12-10.11:54:44.241>
user = 'https://bugs.python.org/ManickarajaKumarappan'

bugs.python.org fields:

activity = <Date 2021-12-10.11:54:44.241>
actor = 'iritkatriel'
assignee = 'none'
closed = True
closed_date = <Date 2021-12-10.11:54:44.241>
closer = 'iritkatriel'
components = ['Extension Modules']
creation = <Date 2020-05-29.20:31:30.406>
creator = 'Manickaraja Kumarappan'
dependencies = []
files = []
hgrepos = []
issue_num = 40821
keywords = []
message_count = 3.0
messages = ['370336', '370369', '383161']
nosy_count = 3.0
nosy_names = ['christian.heimes', 'mephinet', 'Manickaraja Kumarappan']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue40821'
versions = ['Python 3.7']

@ManickarajaKumarappan
Copy link
Mannequin Author

ManickarajaKumarappan mannequin commented May 29, 2020

Hi,
We are using below command to get the original login user. In some cases folks sudo as different user and run commands. In some cases folks use switch to different user (su - <>) and then run command. In all cases we would like to get original user who logged into the terminal to run the command. We are using below command to get the same.

user=os.getlogin()

We got three RHEL linux systems with Python 3 and strangely on two of them this command works fine. However only on third system it is failing with below error

OSError: [Errno 6] No such device or address

Not sure if it is some o/s env setup which is causing this command to fail. Any pointers to run this command will be of great help so that we can pin point the issue.

Please note on faiing system if I do python and then run the command it works fine without any issue. However if it is triggered through our Scheduler (Control M) it is failing with above message.

Give below is the command how Scheduler triggers the job.

/bin/su - edwadm -c /bin/sh -x <>

Thanks
Manick.

@ManickarajaKumarappan ManickarajaKumarappan mannequin added 3.7 (EOL) end of life extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels May 29, 2020
@tiran
Copy link
Member

tiran commented May 30, 2020

On POSIX os.getlogin() is a thin wrapper around the glibc function getlogin() https://linux.die.net/man/3/getlogin . The error is coming from glibc.

@tiran
Copy link
Member

tiran commented Dec 16, 2020

errno 6 is ENXIO. According to https://www.man7.org/linux/man-pages/man3/getlogin.3.html the error code means "The calling process has no controlling terminal.".

os.getlogin() returns the name of the user logged in on the controlling terminal of the process. Typically processes in user session (tty, X session) have a controlling terminal. Processes spawned by a service manager like init, systemd, or upstart usually do not have a controlling terminal. You have to get the user information by other means. Our documentation for os.getlogin() recommends getpass.getuser().

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
openstack-mirroring pushed a commit to openstack/openstack that referenced this issue May 10, 2022
* Update tacker from branch 'master'
  to 87ff1bddbac9e99d9bd1266ddd4df6ae3f2b7d5f
  - Use getpass.getuser() in test_privsep
    
    For some reasons method os.getlogin() is failing in
    Zuul CI in Centos8 job [1].
    As recommended in [2], change method to getpass.getuser().
    
    [1] https://review.rdoproject.org/zuul/build/bee7ccaba673409c82cc1f212311fdc2/log/job-output.txt
    [2] python/cpython#84998 (comment)
    
    Change-Id: I842dccc196c7611506f2115b4bea42bb406f2c3f
openstack-mirroring pushed a commit to openstack/tacker that referenced this issue May 10, 2022
For some reasons method os.getlogin() is failing in
Zuul CI in Centos8 job [1].
As recommended in [2], change method to getpass.getuser().

[1] https://review.rdoproject.org/zuul/build/bee7ccaba673409c82cc1f212311fdc2/log/job-output.txt
[2] python/cpython#84998 (comment)

Change-Id: I842dccc196c7611506f2115b4bea42bb406f2c3f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants