Skip to content

Commit

Permalink
cleanup SIGWINCH signal handler when command channel is done
Browse files Browse the repository at this point in the history
  • Loading branch information
ploxiln committed Dec 31, 2021
1 parent 8c22d17 commit 92244f2
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions fabric/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ def _execute(channel, command, pty=True, combine_stderr=None,
# Request pty with size params (default to 80x24, obtain real
# parameters if on POSIX platform)
if using_pty:
sigwinch_orig = None
rows, cols = _pty_size()
channel.get_pty(width=cols, height=rows)

Expand All @@ -773,7 +774,7 @@ def handle_window_change(signum, frame):
channel.resize_pty(width=cols, height=rows)

if hasattr(signal, "SIGWINCH"):
signal.signal(signal.SIGWINCH, handle_window_change)
sigwinch_orig = signal.signal(signal.SIGWINCH, handle_window_change)

# Use SSH agent forwarding from 'ssh' if enabled by user
config_agent = ssh_config().get('forwardagent', 'no').lower() == 'yes'
Expand Down Expand Up @@ -804,21 +805,25 @@ def handle_window_change(signum, frame):
ThreadHandler('in', input_loop, channel, stdin, using_pty)
)

while True:
if channel.exit_status_ready():
break
else:
# Check for thread exceptions here so we can raise ASAP
# (without chance of getting blocked by, or hidden by an
# exception within, recv_exit_status())
for worker in workers:
worker.raise_if_needed()
try:
time.sleep(ssh.io_sleep)
except KeyboardInterrupt:
if not remote_interrupt:
raise
channel.send('\x03')
try:
while True:
if channel.exit_status_ready():
break
else:
# Check for thread exceptions here so we can raise ASAP
# (without chance of getting blocked by, or hidden by an
# exception within, recv_exit_status())
for worker in workers:
worker.raise_if_needed()
try:
time.sleep(ssh.io_sleep)
except KeyboardInterrupt:
if not remote_interrupt:
raise
channel.send('\x03')
finally:
if using_pty and sigwinch_orig is not None:
signal.signal(signal.SIGWINCH, sigwinch_orig)

# Obtain exit code of remote program now that we're done.
status = channel.recv_exit_status()
Expand Down

0 comments on commit 92244f2

Please sign in to comment.