Skip to content

Commit

Permalink
Merge pull request #17 from cisagov/improvement/signals
Browse files Browse the repository at this point in the history
Properly handle interrupt signals
  • Loading branch information
felddy committed Aug 16, 2022
2 parents 3b506bb + 6d9976a commit c48c3c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/awssh/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""This file defines the version of this module."""
__version__ = "1.0.0"
__version__ = "1.0.1"
5 changes: 5 additions & 0 deletions src/awssh/awssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import logging
import os
from pathlib import Path
import signal
import subprocess # nosec: B404 subprocess use is required for this tool
import sys
from typing import Any, Dict, Optional
Expand Down Expand Up @@ -144,9 +145,13 @@ def _run_subprocess(
for key in sorted(os.environ):
logging.debug("%s=%s", key, os.environ[key])
logging.debug("command: %s", " ".join(i for i in command))
# Ignore interrupt signals and allow the child process to handle them
interrupt_action = signal.signal(signal.SIGINT, signal.SIG_IGN)
completed_process = (
subprocess.run( # nosec: B603 subprocess input is carefully validated
args=command, env=awssh_env
)
)
# Restore the interrupt signal handler to previous state
signal.signal(signal.SIGINT, interrupt_action)
return completed_process.returncode

0 comments on commit c48c3c4

Please sign in to comment.