From f0529d8903acc9e397819e47deb55273ab285002 Mon Sep 17 00:00:00 2001 From: root <295172551@qq.com> Date: Sat, 14 Jun 2025 00:47:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=A4=8D=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CoreAgent.API/Configurations/netcommand.json | 4 ++-- .../Services/Network/CellularNetworkService.cs | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CoreAgent.API/Configurations/netcommand.json b/CoreAgent.API/Configurations/netcommand.json index db153af..856bb26 100644 --- a/CoreAgent.API/Configurations/netcommand.json +++ b/CoreAgent.API/Configurations/netcommand.json @@ -35,12 +35,12 @@ }, { "type": 0, - "template": "pkill tcpdump", + "template": "tcpdump", "timeout": 5000, "isEnabled": true, "needReturnResult": false, "needBackgroundExecution": false, - "canBeKilled": false, + "canBeKilled": true, "hasParameters": false }, { diff --git a/CoreAgent.Infrastructure/Services/Network/CellularNetworkService.cs b/CoreAgent.Infrastructure/Services/Network/CellularNetworkService.cs index 364b9ac..549fa23 100644 --- a/CoreAgent.Infrastructure/Services/Network/CellularNetworkService.cs +++ b/CoreAgent.Infrastructure/Services/Network/CellularNetworkService.cs @@ -192,7 +192,7 @@ public class CellularNetworkService : ICellularNetworkService { if (command.CanBeKilled) { - await KillProcessAsync(command.Template, command.Timeout); + return await KillProcessAsync(command.Template, command.Timeout); } var result = await _commandExecutor.ExecuteCommandAsync(command.Template, new CancellationTokenSource(),command.Timeout); @@ -205,11 +205,12 @@ public class CellularNetworkService : ICellularNetworkService } } - private async Task KillProcessAsync(string template,int Timeout) + private async Task KillProcessAsync(string template,int Timeout) { string killCmd = $"ps -ef | grep {template} | grep -v grep | awk '{{print $2}}' | xargs kill -9"; - await _commandExecutor.ExecuteCommandAsync(killCmd, new CancellationTokenSource()); + var result = await _commandExecutor.ExecuteCommandAsync(killCmd, new CancellationTokenSource()); _logger.LogInformation("已终止进程: {Template}", template); + return result.IsSuccess; } private async Task EnableNetworkInterfaceAsync(NetworkConfiguration networkConfig)