mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-104522: Fix OSError raised when run a subprocess (#114195)
Only set filename to cwd if it was caused by failed chdir(cwd). _fork_exec() now returns "noexec:chdir" for failed chdir(cwd). Co-authored-by: Robert O'Shea <PurityLake@users.noreply.github.com>
This commit is contained in:
parent
4c7e09d012
commit
e2c097ebde
4 changed files with 29 additions and 18 deletions
|
@ -1944,16 +1944,21 @@ class Popen:
|
|||
SubprocessError)
|
||||
if issubclass(child_exception_type, OSError) and hex_errno:
|
||||
errno_num = int(hex_errno, 16)
|
||||
child_exec_never_called = (err_msg == "noexec")
|
||||
if child_exec_never_called:
|
||||
if err_msg == "noexec:chdir":
|
||||
err_msg = ""
|
||||
# The error must be from chdir(cwd).
|
||||
err_filename = cwd
|
||||
elif err_msg == "noexec":
|
||||
err_msg = ""
|
||||
err_filename = None
|
||||
else:
|
||||
err_filename = orig_executable
|
||||
if errno_num != 0:
|
||||
err_msg = os.strerror(errno_num)
|
||||
raise child_exception_type(errno_num, err_msg, err_filename)
|
||||
if err_filename is not None:
|
||||
raise child_exception_type(errno_num, err_msg, err_filename)
|
||||
else:
|
||||
raise child_exception_type(errno_num, err_msg)
|
||||
raise child_exception_type(err_msg)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue