GH-124241: try reading `/proc/self/exe` to determine `sys.executable` by FFY00 · Pull Request #145486 · python/cpython · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Lib/test/test_getpath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
On POSIX, we now try to read the symlink target from ``/proc/self/exe`` to
determine :data:`sys.executable`.
5 changes: 5 additions & 0 deletions Modules/getpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,11 @@ progname_to_dict(PyObject *dict, const char *key)
PyMem_RawFree(path);
break;
}
#elif defined(HAVE_READLINK)
wchar_t resolved[MAXPATHLEN + 1];
if (_Py_wreadlink(L"/proc/self/exe", resolved, Py_ARRAY_LENGTH(resolved)) > 0) {
return wchar_to_dict(dict, key, resolved);
}
#endif
return PyDict_SetItemString(dict, key, Py_None) == 0;
}
Expand Down
11 changes: 11 additions & 0 deletions Modules/getpath.py
Loading