Skip to content

Commit

Permalink
[core/process] Fix "Bad file descriptor" on 3>&3
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Mar 21, 2020
1 parent 8dd5a02 commit 10136ce
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def _PushDup(self, fd1, fd2):
Returns:
success Bool
"""
if fd1 == fd2: return True

need_restore = self._PushSave(fd2)

Expand Down Expand Up @@ -311,8 +312,10 @@ def _ApplyRedirect(self, r, waiter):
return False

# Apply redirect
if not self._PushDup(target_fd, r.fd):
ok = False
if target_fd != r.fd:
if not self._PushDup(target_fd, r.fd):
ok = False
posix.close(target_fd) # We already made a copy of it.

# Now handle the extra redirects for aliases &> and &>>.
#
Expand All @@ -333,7 +336,6 @@ def _ApplyRedirect(self, r, waiter):
if not self._PushDup(r.fd, 2):
ok = False

posix.close(target_fd) # We already made a copy of it.
# I don't think we need to close(0) because it will be restored from its
# saved position (10), which closes it.
#self._PushClose(r.fd)
Expand Down

0 comments on commit 10136ce

Please sign in to comment.