Add double Ctrl+C handling to wssshd for force exit

- Implement double SIGINT (Ctrl+C) detection in wssshd server
- First Ctrl+C: Initiates graceful shutdown with cleanup
- Second Ctrl+C: Forces immediate exit using os._exit(1) without cleanup
- Consistent behavior with wssshc double Ctrl+C handling
- Prevents hanging during shutdown when graceful shutdown fails
- Maintains backward compatibility with single Ctrl+C graceful shutdown

This ensures wssshd can be forcefully terminated if graceful shutdown gets stuck, while still allowing proper cleanup on normal shutdown.
parent 730d21eb
...@@ -195,10 +195,19 @@ async def run_server(): ...@@ -195,10 +195,19 @@ async def run_server():
# Set up signal handling for clean exit # Set up signal handling for clean exit
shutdown_event.clear() shutdown_event.clear()
sigint_count = 0
def signal_handler(signum, frame): def signal_handler(signum, frame):
if debug: print(f"[DEBUG] Received signal {signum}, initiating shutdown") nonlocal sigint_count
sigint_count += 1
if sigint_count == 1:
print("\nReceived SIGINT, attempting graceful shutdown...")
shutdown_event.set() shutdown_event.set()
elif sigint_count >= 2:
print("\nReceived second SIGINT, exiting immediately...")
# Force exit without cleanup
os._exit(1)
# Register signal handler for SIGINT (Ctrl+C) # Register signal handler for SIGINT (Ctrl+C)
signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGINT, signal_handler)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment