rework killing all daemons to continue trying after a failure

Before, it would quit the process on the first exception while killing.
This makes it keep on trying each daemon.
This commit is contained in:
Hans-Christoph Steiner 2015-06-08 23:38:56 -04:00
parent 73658ce3cf
commit 2bc85a4a3a
1 changed files with 34 additions and 16 deletions

View File

@ -399,7 +399,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
{ {
Log.d(TAG,"Tor is stopping NOW"); Log.d(TAG,"Tor is stopping NOW");
shutdownTorProcess (); killAllDaemons ();
//stop the foreground priority and make sure to remove the persistant notification //stop the foreground priority and make sure to remove the persistant notification
stopForeground(true); stopForeground(true);
@ -505,31 +505,49 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
} }
private void shutdownTorProcess () throws Exception private void killAllDaemons() throws CannotKillException {
{ if (conn != null) {
if (conn != null)
{
logNotice("Using control port to shutdown Tor"); logNotice("Using control port to shutdown Tor");
try { try {
logNotice("sending HALT signal to Tor process"); logNotice("sending HALT signal to Tor process");
conn.shutdownTor("HALT"); conn.shutdownTor("HALT");
} catch (Exception e) { } catch (IOException e) {
Log.d(TAG,"error shutting down Tor via connection",e); Log.d(TAG, "error shutting down Tor via connection", e);
} }
conn = null; conn = null;
} }
killProcess(fileTor); // try these separately in case one fails, then it can try the next
File cannotKillFile = null;
killProcess(filePolipo); try {
killProcess(fileObfsclient); killProcess(fileObfsclient);
} catch (IOException e) {
e.printStackTrace();
cannotKillFile = fileObfsclient;
}
try {
killProcess(fileMeekclient); killProcess(fileMeekclient);
} catch (IOException e) {
e.printStackTrace();
cannotKillFile = fileMeekclient;
}
try {
killProcess(filePolipo);
} catch (IOException e) {
e.printStackTrace();
cannotKillFile = filePolipo;
}
try {
killProcess(fileTor);
} catch (IOException e) {
e.printStackTrace();
cannotKillFile = fileTor;
}
if (cannotKillFile != null)
throw new CannotKillException(cannotKillFile);
} }
public class CannotKillException extends IllegalStateException { public class CannotKillException extends IllegalStateException {
@ -540,7 +558,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
} }
} }
private void killProcess(File fileProcBin) throws IOException { private void killProcess(File fileProcBin) throws IOException, CannotKillException {
int procId = -1; int procId = -1;
int killAttempts = 0; int killAttempts = 0;