GH-124241: try reading /proc/self/exe to determine sys.executable#145486
GH-124241: try reading /proc/self/exe to determine sys.executable#145486FFY00 wants to merge 5 commits intopython:mainfrom
/proc/self/exe to determine sys.executable#145486Conversation
Signed-off-by: Filipe Laíns <lains@riseup.net>
Modules/getpath.py
Outdated
| if not executable and os_name == 'posix': | ||
| # On Linux, try resolving the executable path via procfs | ||
| try: | ||
| executable = realpath('/proc/self/exe') |
There was a problem hiding this comment.
realpath() returns /proc/self/exe unmodified if it cannot resolve the symlink. I would prefer using readlink() here. But it requires more work, since Modules/getpath.c doesn't implement it here. I can help implementing readlink() in getpath.c if you want.
There was a problem hiding this comment.
Right, using readlink would also be my preference, I just went for this implementation for simplicity. We could move this to progname_to_dict (computes real_executable), but we should still try to honor program_name if it points to the same path.
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
|
Well, this is kind of messy. It seems that several tests rely on being able to feed I'm gonna see if I can find a way to do this without breaking the module path calculation. |
$ bash -c "exec -a echo $(pwd)/python -c 'import sys; print(sys.executable)'" /home/anubis/git/cpython/python