mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] gh-127081: use getlogin_r if available (gh-132751) (gh-135097)
The `getlogin` function is not thread-safe: replace with `getlogin_r` where
available.
(cherry picked from commit 1ffe913c20)
Co-authored-by: Duane Griffin <duaneg@dghda.com>
This commit is contained in:
parent
81999f157f
commit
d8c2bfac1f
5 changed files with 79 additions and 1 deletions
|
|
@ -9548,6 +9548,24 @@ os_getlogin_impl(PyObject *module)
|
|||
}
|
||||
else
|
||||
result = PyErr_SetFromWindowsErr(GetLastError());
|
||||
#elif defined (HAVE_GETLOGIN_R)
|
||||
# if defined (HAVE_MAXLOGNAME)
|
||||
char name[MAXLOGNAME + 1];
|
||||
# elif defined (HAVE_UT_NAMESIZE)
|
||||
char name[UT_NAMESIZE + 1];
|
||||
# else
|
||||
char name[256];
|
||||
# endif
|
||||
int err = getlogin_r(name, sizeof(name));
|
||||
if (err) {
|
||||
int old_errno = errno;
|
||||
errno = -err;
|
||||
posix_error();
|
||||
errno = old_errno;
|
||||
}
|
||||
else {
|
||||
result = PyUnicode_DecodeFSDefault(name);
|
||||
}
|
||||
#else
|
||||
char *name;
|
||||
int old_errno = errno;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue