Skip to content

Commit

Permalink
Handle condition going from privileged to non-privileged user in whic…
Browse files Browse the repository at this point in the history
…h the cwd disables descent.

Fall back to Mitogen's temporary directory. In relation to mitogen-hq#636.
  • Loading branch information
msaladna committed Feb 2, 2021
1 parent 9d404e0 commit e33b8e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ansible_mitogen/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,15 @@ def _setup_cwd(self):
"""
For situations like sudo to a non-privileged account, CWD could be
$HOME of the old account, which could have mode go=, which means it is
impossible to restore the old directory, so don't even try.
impossible to restore the old directory. Fallback to a neutral temp if so.
"""
if self.cwd:
os.chdir(self.cwd)
try:
os.chdir(self.cwd)
except OSError:
LOG.debug('%r: could not CHDIR to %r',
self, self.cwd)
self._revert_cwd()

def _setup_environ(self):
"""
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ To avail of fixes in an unreleased version, please download a ZIP file
v0.2.10 (unreleased)
--------------------

* :gh:issue:`636` os.chdir fails if the sudo/become user lacks adequate permissions to chdir prior to task
* :gh:issue:`597` mitogen does not support Ansible 2.8 Python interpreter detection
* :gh:issue:`655` wait_for_connection gives errors
* :gh:issue:`672` cannot perform relative import error
Expand Down

0 comments on commit e33b8e3

Please sign in to comment.