Skip to content

Commit

Permalink
Fix issue when plugin program file is in system environment path
Browse files Browse the repository at this point in the history
  • Loading branch information
celeron533 committed Dec 14, 2019
1 parent a4101f8 commit 95f18f5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions shadowsocks-csharp/Controller/Service/Sip003Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,24 @@ public bool StartIfNeeded()
return false;
}

if (!File.Exists(_pluginProcess.StartInfo.FileName))
{
throw new FileNotFoundException(I18N.GetString("Cannot find the plugin program file"), _pluginProcess.StartInfo.FileName);
}

var localPort = GetNextFreeTcpPort();
LocalEndPoint = new IPEndPoint(IPAddress.Loopback, localPort);

_pluginProcess.StartInfo.Environment["SS_LOCAL_HOST"] = LocalEndPoint.Address.ToString();
_pluginProcess.StartInfo.Environment["SS_LOCAL_PORT"] = LocalEndPoint.Port.ToString();
_pluginProcess.StartInfo.Arguments = ExpandEnvironmentVariables(_pluginProcess.StartInfo.Arguments, _pluginProcess.StartInfo.EnvironmentVariables);
_pluginProcess.Start();
try
{
_pluginProcess.Start();
}
catch (System.ComponentModel.Win32Exception ex)
{
// do not use File.Exists(...), it can not handle the scenarios when the plugin file is in system environment path.
if ((uint)ex.ErrorCode == 0x80004005) // file not found
{
throw new FileNotFoundException(I18N.GetString("Cannot find the plugin program file"), _pluginProcess.StartInfo.FileName, ex);
}
}
_pluginJob.AddProcess(_pluginProcess.Handle);
_started = true;
}
Expand Down

0 comments on commit 95f18f5

Please sign in to comment.