Skip to content

Commit cafd1ac

Browse files
committed
Handle condition going from privileged to non-privileged user
in which the cwd disables descent. Fall back to Mitogen's temporary directory. Fixes #636.
1 parent b130cd9 commit cafd1ac

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

ansible_mitogen/runner.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,15 @@ def _setup_cwd(self):
367367
"""
368368
For situations like sudo to a non-privileged account, CWD could be
369369
$HOME of the old account, which could have mode go=, which means it is
370-
impossible to restore the old directory, so don't even try.
370+
impossible to restore the old directory. Fallback to a neutral temp if so.
371371
"""
372372
if self.cwd:
373-
os.chdir(self.cwd)
373+
try:
374+
os.chdir(self.cwd)
375+
except OSError:
376+
LOG.debug('%r: could not CHDIR to %r fallback to %r',
377+
self, self.cwd, self.good_temp_dir)
378+
os.chdir(self.good_temp_dir)
374379

375380
def _setup_environ(self):
376381
"""

docs/changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ v0.3.9 (2024-08-13)
198198
v0.3.8 (2024-07-30)
199199
-------------------
200200

201+
* :gh:issue:`636` os.chdir fails if the sudo/become user lacks adequate permissions to chdir prior to task
201202
* :gh:issue:`952` Fix Ansible `--ask-become-pass`, add test coverage
202203
* :gh:issue:`957` Fix Ansible exception when executing against 10s of hosts
203204
"ValueError: filedescriptor out of range in select()"

0 commit comments

Comments
 (0)