Skip to content

Commit

Permalink
Use native Process.Kill() because powershell might not always be avai…
Browse files Browse the repository at this point in the history
…lable
  • Loading branch information
ezhevita committed Oct 23, 2024
1 parent 805fd85 commit 93cc038
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public void ResetRouting(string proxyIp, int gatewayInterfaceIndex)

try
{
// This is only necessary when disconecting without network connectivity.
// This is only necessary when disconecting without network connectivity.
StartRoutingIpv4();
}
catch (Exception) {}
Expand Down Expand Up @@ -531,7 +531,7 @@ public void ResetRouting(string proxyIp, int gatewayInterfaceIndex)
{
StopSmartDnsBlock();
eventLog.WriteEntry($"stopped smartdnsblock");
}
}
catch (Exception e)
{
eventLog.WriteEntry($"failed to stop smartdnsblock: {e.Message}",
Expand Down Expand Up @@ -606,15 +606,24 @@ private void StartSmartDnsBlock()
}
}

private void StopSmartDnsBlock()
private static void StopSmartDnsBlock()
{
try
var errors = new List<string>(0);
foreach (var process in Process.GetProcessesByName("smartdnsblock"))
{
RunCommand("powershell", "stop-process -name smartdnsblock");
try
{
process.Kill();
}
catch (Exception e)
{
errors.Add(e.Message);
}
}
catch (Exception e)

if (errors.Count > 0)
{
throw new Exception($"could not stop smartdnsblock: {e.Message}");
throw new Exception($"could not stop smartdnsblock: {string.Join("; ", errors)}");
}
}

Expand Down Expand Up @@ -693,7 +702,7 @@ private void StopRoutingIpv4()
{
RunCommand(CMD_NETSH, $"interface ipv4 set route {subnet} interface={NetworkInterface.LoopbackInterfaceIndex} metric=0 store=active");
}
}
}
}

private void StartRoutingIpv6()
Expand Down Expand Up @@ -938,7 +947,7 @@ private void NetworkAddressChanged(object sender, EventArgs evt)
// Only send on actual change, to prevent duplicate notifications (mostly
// harmless but can make debugging harder).
eventLog.WriteEntry($"network changed but gateway and interface stayed the same");
return;
return;
}
else if (gatewayIp == null)
{
Expand Down

0 comments on commit 93cc038

Please sign in to comment.