Fix TUN mode cleanup on Linux/macOS (#8202)
This commit is contained in:
@@ -34,7 +34,7 @@ public class CoreAdminManager
|
||||
StringBuilder sb = new();
|
||||
sb.AppendLine("#!/bin/bash");
|
||||
var cmdLine = $"{fileName.AppendQuotes()} {string.Format(coreInfo.Arguments, Utils.GetBinConfigPath(configPath).AppendQuotes())}";
|
||||
sb.AppendLine($"sudo -S {cmdLine}");
|
||||
sb.AppendLine($"exec sudo -S -- {cmdLine}");
|
||||
var shFilePath = await FileManager.CreateLinuxShellFile("run_as_sudo.sh", sb.ToString(), true);
|
||||
|
||||
var procService = new ProcessService(
|
||||
|
||||
@@ -47,6 +47,18 @@ echo "============================================"
|
||||
echo "Starting termination of process $PID and all its children"
|
||||
echo "============================================"
|
||||
|
||||
# Try graceful termination first
|
||||
echo "Attempting graceful termination (SIGTERM) of PID: $PID"
|
||||
kill -15 "$PID" 2>/dev/null || true
|
||||
sleep 1
|
||||
# If still running, fall back to kill_children
|
||||
if ps -p $PID > /dev/null; then
|
||||
echo "Process $PID did not exit after SIGTERM; proceeding with forced termination of its children and itself"
|
||||
else
|
||||
echo "Process $PID exited cleanly after SIGTERM"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Find and kill all child processes
|
||||
kill_children "$PID"
|
||||
|
||||
|
||||
@@ -42,6 +42,20 @@ echo "============================================"
|
||||
echo "Starting termination of process $PID and all its descendants"
|
||||
echo "============================================"
|
||||
|
||||
# Try graceful termination first
|
||||
echo "Attempting graceful termination (SIGTERM) of PID: $PID"
|
||||
kill -15 "$PID" 2>/dev/null || true
|
||||
sleep 1
|
||||
|
||||
# If still running, fall back to kill_descendants
|
||||
# Use the macOS-native 'kill -0' check
|
||||
if kill -0 $PID 2>/dev/null; then
|
||||
echo "Process $PID did not exit after SIGTERM; proceeding with forced termination of its descendants and itself"
|
||||
else
|
||||
echo "Process $PID exited cleanly after SIGTERM"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Find and kill all descendant processes
|
||||
kill_descendants "$PID"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user