From aca954d3642cfa2e6cac7b56c3c3a0fb9cf42180 Mon Sep 17 00:00:00 2001 From: zenaku Date: Sat, 20 Jun 2026 08:43:43 -0500 Subject: [PATCH] small fix 20-06-26 --- core/utils/encrypted_proxy/singbox.py | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/core/utils/encrypted_proxy/singbox.py b/core/utils/encrypted_proxy/singbox.py index 784e689..3589ade 100644 --- a/core/utils/encrypted_proxy/singbox.py +++ b/core/utils/encrypted_proxy/singbox.py @@ -198,5 +198,61 @@ class SingboxRunner: time.sleep(0.3) + for pid in pids: + try: + subprocess.run( + ['sudo', 'kill', '-9', str(pid)], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + stdin=subprocess.DEVNULL, + env={**os.environ, 'SUDO_ASKPASS': '/bin/false'}, + timeout=5, + ) + except (OSError, subprocess.TimeoutExpired): + pass + + except (OSError, ValueError, subprocess.TimeoutExpired): + pass + try: + result = subprocess.run( + ['pgrep', '-x', 'sing-box'], + capture_output=True, + text=True, + ) + + if result.returncode != 0: + return + + pids = [ + int(p) + for p in result.stdout.strip().splitlines() + if p.strip().isdigit() + ] + + if not pids: + return + + subprocess.run( + ['sudo', self._WRAPPER, '', 'stop'], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + stdin=subprocess.DEVNULL, + env={**os.environ, 'SUDO_ASKPASS': '/bin/false'}, + timeout=15, + ) + + deadline = time.monotonic() + 4.0 + + while time.monotonic() < deadline: + check = subprocess.run( + ['pgrep', '-x', 'sing-box'], + capture_output=True, + ) + + if check.returncode != 0: + return + + time.sleep(0.3) + except (OSError, ValueError, subprocess.TimeoutExpired): pass \ No newline at end of file