@@ -265,13 +265,6 @@ def search_up(prefix, *landmarks, test=isfile):
265265 if not executable :
266266 executable = real_executable
267267
268- if not executable and os_name == 'posix' :
269- # On Linux, try resolving the executable path via procfs
270- try :
271- executable = realpath ('/proc/self/exe' )
272- except (OSError , MemoryError ):
273- pass
274-
275268if not executable and SEP in program_name :
276269 # Resolve partial path program_name against current directory
277270 executable = abspath (program_name )
@@ -287,6 +280,17 @@ def search_up(prefix, *landmarks, test=isfile):
287280 # whether we are in a build tree. This is true even if the
288281 # executable path was provided in the config.
289282 real_executable = executable
283+ elif os_name == 'posix' :
284+ # real_executable is more accurate than the value we have computed for
285+ # executable, so use it instead if it resolves to a different path
286+ # (eg. GH-124241).
287+ # If real_executable and executable resolve to the same path, prefer
288+ # executable, as that is much more likely to be the path the user is using.
289+ try :
290+ if realpath (executable ) != real_executable :
291+ executable = real_executable
292+ except OSError :
293+ pass
290294
291295if not executable and program_name and ENV_PATH :
292296 # Resolve names against PATH.
0 commit comments