Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't use Powershell for killing smartdnsblock processes #2258

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading