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:
Serhiy Storchaka 2024-01-18 02:52:42 +02:00 committed by GitHub
parent 4c7e09d012
commit e2c097ebde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 18 deletions

View file

@ -2017,11 +2017,12 @@ class POSIXProcessTestCase(BaseTestCase):
"import os; print(os.getuid())"],
user=user,
close_fds=close_fds)
except PermissionError: # (EACCES, EPERM)
pass
except PermissionError as e: # (EACCES, EPERM)
self.assertIsNone(e.filename)
except OSError as e:
if e.errno not in (errno.EACCES, errno.EPERM):
raise
self.assertIsNone(e.filename)
else:
if isinstance(user, str):
user_uid = pwd.getpwnam(user).pw_uid
@ -2065,8 +2066,8 @@ class POSIXProcessTestCase(BaseTestCase):
"import os; print(os.getgid())"],
group=group,
close_fds=close_fds)
except PermissionError: # (EACCES, EPERM)
pass
except PermissionError as e: # (EACCES, EPERM)
self.assertIsNone(e.filename)
else:
if isinstance(group, str):
group_gid = grp.getgrnam(group).gr_gid
@ -2114,7 +2115,8 @@ class POSIXProcessTestCase(BaseTestCase):
[sys.executable, "-c",
"import os, sys, json; json.dump(os.getgroups(), sys.stdout)"],
extra_groups=group_list)
except PermissionError:
except PermissionError as e:
self.assertIsNone(e.filename)
self.skipTest("setgroup() EPERM; this test may require root.")
else:
parent_groups = os.getgroups()