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() not working
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Manickaraja Kumarappan, christian.heimes, mephinet
Priority: normal Keywords:

Created on 2020-05-29 20:31 by Manickaraja Kumarappan, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg370336 - (view) Author: Manickaraja Kumarappan (Manickaraja Kumarappan) Date: 2020-05-29 20:31
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.
msg370369 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2020-05-30 11:24
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.
msg383161 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2020-12-16 12:32
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().
History
Date User Action Args
2022-04-11 14:59:31adminsetgithub: 84998
2021-12-10 11:54:44iritkatrielsetstatus: pending -> closed
stage: resolved
2020-12-16 12:32:22christian.heimessetstatus: open -> pending
resolution: not a bug
messages: + msg383161
2020-12-16 12:11:38mephinetsetnosy: + mephinet
2020-05-30 11:24:08christian.heimessetnosy: + christian.heimes
messages: + msg370369
2020-05-29 20:31:30Manickaraja Kumarappancreate