Browse Source

Improve exception handling

tags/3.3.6
noisyfox 8 years ago
parent
commit
da6466e247
2 changed files with 26 additions and 26 deletions
  1. +11
    -0
      shadowsocks-csharp/Controller/Logging.cs
  2. +15
    -26
      shadowsocks-csharp/Controller/Service/PrivoxyRunner.cs

+ 11
- 0
shadowsocks-csharp/Controller/Logging.cs View File

@@ -1,4 +1,5 @@
using System; using System;
using System.ComponentModel;
using System.IO; using System.IO;
using System.Net.Sockets; using System.Net.Sockets;
using System.Net; using System.Net;
@@ -123,6 +124,16 @@ namespace Shadowsocks.Controller
else if (e is ObjectDisposedException) else if (e is ObjectDisposedException)
{ {
} }
else if (e is Win32Exception)
{
var ex = (Win32Exception) e;
// Win32Exception (0x80004005): A 32 bit processes cannot access modules of a 64 bit process.
if ((uint) ex.ErrorCode != 0x80004005)
{
Info(e);
}
}
else else
{ {
Info(e); Info(e);


+ 15
- 26
shadowsocks-csharp/Controller/Service/PrivoxyRunner.cs View File

@@ -125,43 +125,32 @@ namespace Shadowsocks.Controller
private static bool IsChildProcess(Process process) private static bool IsChildProcess(Process process)
{ {
if (Utils.IsPortableMode())
try
{ {
/*
* Under PortableMode, we could identify it by the path of ss_privoxy.exe.
*/
try
if (Utils.IsPortableMode())
{ {
/* /*
* Sometimes Process.GetProcessesByName will return some processes that
* are already dead, and that will cause exceptions here.
* We could simply ignore those exceptions.
* Under PortableMode, we could identify it by the path of ss_privoxy.exe.
*/ */
string path = process.MainModule.FileName;
var path = process.MainModule.FileName;
return Utils.GetTempPath("ss_privoxy.exe").Equals(path); return Utils.GetTempPath("ss_privoxy.exe").Equals(path);
} }
catch (Exception ex)
{
Logging.LogUsefulException(ex);
return false;
}
}
else
{
try
else
{ {
var cmd = process.GetCommandLine(); var cmd = process.GetCommandLine();
return cmd.Contains(UniqueConfigFile); return cmd.Contains(UniqueConfigFile);
} }
catch (Win32Exception ex)
{
if ((uint) ex.ErrorCode != 0x80004005)
{
throw;
}
}
}
catch (Exception ex)
{
/*
* Sometimes Process.GetProcessesByName will return some processes that
* are already dead, and that will cause exceptions here.
* We could simply ignore those exceptions.
*/
Logging.LogUsefulException(ex);
return false; return false;
} }
} }


Loading…
Cancel
Save