From e05cc7d83eda7f1637a03f42b5d10b98a53f8e81 Mon Sep 17 00:00:00 2001 From: 1951FDG <1951FDG@users.noreply.github.com> Date: Thu, 18 Mar 2021 19:26:36 +0100 Subject: [PATCH] Improvement: invocations of openpyn --kill will now exit with status code 0 --- openpyn/openpyn.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/openpyn/openpyn.py b/openpyn/openpyn.py index 8edfc1a..d86b530 100644 --- a/openpyn/openpyn.py +++ b/openpyn/openpyn.py @@ -3,11 +3,13 @@ import argparse import io import json +import locale import logging import logging.handlers import os import shlex import shutil +import signal import subprocess import sys import tempfile @@ -15,7 +17,6 @@ import zipfile from email.utils import parsedate from pathlib import Path -import locale from typing import List, Set import coloredlogs @@ -402,12 +403,7 @@ def run(init: bool, server: str, country_code: str, country: str, area: str, tcp systemd.update_service(openpyn_options, run=True) elif kill: - try: - kill_all() - # returns exit code 143 - except RuntimeError as e: - logger.critical(e) - return 1 + kill_all() elif kill_flush: if detected_os == "linux": @@ -424,12 +420,7 @@ def run(init: bool, server: str, country_code: str, country: str, area: str, tcp if internally_allowed: network_interfaces = get_network_interfaces() firewall.internally_allow_ports(network_interfaces, internally_allowed) - try: - kill_all() - # returns exit code 143 - except RuntimeError as e: - logger.critical(e) - return 1 + kill_all() elif update: try: @@ -862,6 +853,11 @@ def kill_all() -> None: if root_access is False: root.obtain_root_access() + # ignore interrupt from keyboard (CTRL + C) + signal.signal(signal.SIGINT, signal.SIG_IGN) + # ignore termination signal (143) + signal.signal(signal.SIGTERM, signal.SIG_IGN) + kill_management_client() kill_vpn_processes()