Skip to content

os.getlogin() fails with OSError: [Errno 34] for usernames > 9 characters #135497

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

Closed
alebcay opened this issue Jun 14, 2025 · 3 comments
Closed
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@alebcay
Copy link
Contributor

alebcay commented Jun 14, 2025

Bug report

Bug description:

import os
print(os.getlogin())
$ python3 -c "import os; print(os.getlogin())"

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import os; print(os.getlogin())
                     ~~~~~~~~~~~^^
OSError: [Errno -34] Unknown error: -34

It appears that if Python is compiled in an environment without HAVE_MAXLOGNAME but with HAVE_UT_NAMESIZE, getlogin_r will return error 34 if username is >9 characters.

This appears to be a regression introduced in #132751:

https://github.com/duaneg/cpython/blob/675342cf59ffe53337d92af989b97dad687a10ea/configure.ac#L5434

The correct header file to search for is sys/param.h, not sys/params.h. As a result, HAVE_UT_NAMESIZE is satisfied (via utmp.h) but HAVE_MAXLOGNAME is not.

This was originally reported to Homebrew via Homebrew/homebrew-core#226857.

CPython versions tested on:

3.15

Operating systems tested on:

macOS

Linked PRs

@alebcay alebcay added the type-bug An unexpected behavior, bug, or error label Jun 14, 2025
@picnixz picnixz added the extension-modules C modules in the Modules dir label Jun 14, 2025
@sobolevn
Copy link
Member

@alebcay would you like to submit a PR with the fix?

@alebcay
Copy link
Contributor Author

alebcay commented Jun 14, 2025

Sure, I'd be happy to. As far as processes go, should I also regenerate configure, and is there a particular command/script I should use for that? I found https://devguide.python.org/contrib/workflows/regenerate/#regenerate-configure and will use that.

alebcay added a commit to alebcay/cpython that referenced this issue Jun 14, 2025
alebcay added a commit to alebcay/cpython that referenced this issue Jun 14, 2025
alebcay added a commit to alebcay/cpython that referenced this issue Jun 14, 2025
alebcay added a commit to alebcay/cpython that referenced this issue Jun 14, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 14, 2025
…GH-135508)

(cherry picked from commit 2e15a50)

Co-authored-by: Caleb Xu <calebcenter@live.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 14, 2025
…GH-135508)

(cherry picked from commit 2e15a50)

Co-authored-by: Caleb Xu <calebcenter@live.com>
picnixz pushed a commit that referenced this issue Jun 14, 2025
…5508) (#135517)

gh-135497: fix `MAXLOGNAME` detection in `configure.ac` (GH-135508)
(cherry picked from commit 2e15a50)

Co-authored-by: Caleb Xu <calebcenter@live.com>
picnixz pushed a commit that referenced this issue Jun 14, 2025
…5508) (#135516)

gh-135497: fix `MAXLOGNAME` detection in `configure.ac` (GH-135508)
(cherry picked from commit 2e15a50)

Co-authored-by: Caleb Xu <calebcenter@live.com>
@picnixz
Copy link
Member

picnixz commented Jun 14, 2025

Thank you for the report & the fix!

@picnixz picnixz closed this as completed Jun 14, 2025
shuimu5418 pushed a commit to shuimu5418/cpython001 that referenced this issue Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

3 participants