use "SIGNAL HUP" to request Tor re-read its config
The tor daemon supports both "SIGNAL HUP" via its control port or the UNIX signal `kill -HUP` via the terminal as a way to trigger the tor daemon to reload its config. This is needed for new bridges and hidden services. It is not necessary to restart everything to add those. https://stem.torproject.org/faq.html#how-do-i-reload-my-torrc
This commit is contained in:
parent
6ac9a2cee6
commit
21c3bfb3c5
|
@ -479,12 +479,10 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
|
||||||
|
|
||||||
if (onionHostname == null || onionHostname.length() == 0)
|
if (onionHostname == null || onionHostname.length() == 0)
|
||||||
{
|
{
|
||||||
stopTor();
|
requestTorRereadConfig();
|
||||||
startTor();
|
|
||||||
|
|
||||||
new Thread () {
|
new Thread () {
|
||||||
|
|
||||||
|
|
||||||
public void run ()
|
public void run ()
|
||||||
{
|
{
|
||||||
String onionHostname = mPrefs.getString("pref_hs_hostname","");
|
String onionHostname = mPrefs.getString("pref_hs_hostname","");
|
||||||
|
@ -945,37 +943,13 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
|
||||||
String bridgeList = Prefs.getBridgesList();
|
String bridgeList = Prefs.getBridgesList();
|
||||||
if (bridgeList != null && bridgeList.length() > 0)
|
if (bridgeList != null && bridgeList.length() > 0)
|
||||||
{
|
{
|
||||||
restartTor ();
|
requestTorRereadConfig ();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restartTor ()
|
private void requestTorRereadConfig() {
|
||||||
{
|
sendIntentToService (TorServiceConstants.CMD_START);
|
||||||
try
|
|
||||||
{
|
|
||||||
//do auto restart
|
|
||||||
stopTor ();
|
|
||||||
|
|
||||||
mStatusUpdateHandler.postDelayed(new Runnable () {
|
|
||||||
public void run ()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
startTor();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.e(TAG,"can't start orbot",e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 2000);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.e(TAG,"can't stop orbot",e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void promptStartVpnService ()
|
public void promptStartVpnService ()
|
||||||
|
|
|
@ -344,6 +344,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
if (action.equals(CMD_START)) {
|
if (action.equals(CMD_START)) {
|
||||||
startTor();
|
startTor();
|
||||||
// stopTor() is called when the Service is destroyed
|
// stopTor() is called when the Service is destroyed
|
||||||
|
} else if (action.equals(CMD_SIGNAL_HUP)) {
|
||||||
|
requestTorRereadConfig();
|
||||||
} else if (action.equals(CMD_NEWNYM)) {
|
} else if (action.equals(CMD_NEWNYM)) {
|
||||||
newIdentity();
|
newIdentity();
|
||||||
} else if (action.equals(CMD_FLUSH)) {
|
} else if (action.equals(CMD_FLUSH)) {
|
||||||
|
@ -534,7 +536,28 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void requestTorRereadConfig() {
|
||||||
|
try {
|
||||||
|
conn.signal("HUP");
|
||||||
|
return;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// if that fails, try again using native utils
|
||||||
|
try {
|
||||||
|
killProcess(fileTor, "-1"); // this is -HUP
|
||||||
|
} catch (CannotKillException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void killProcess(File fileProcBin) throws IOException, CannotKillException {
|
private void killProcess(File fileProcBin) throws IOException, CannotKillException {
|
||||||
|
killProcess(fileProcBin, "-9"); // this is -KILL
|
||||||
|
}
|
||||||
|
|
||||||
|
private void killProcess(File fileProcBin, String signal) throws IOException, CannotKillException {
|
||||||
int procId = -1;
|
int procId = -1;
|
||||||
int killAttempts = 0;
|
int killAttempts = 0;
|
||||||
|
|
||||||
|
@ -554,10 +577,10 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
} else {
|
} else {
|
||||||
shell = Shell.startShell();
|
shell = Shell.startShell();
|
||||||
}
|
}
|
||||||
shell.add(new SimpleCommand("busybox killall " + fileProcBin.getName()));
|
shell.add(new SimpleCommand("busybox killall " + signal + " " + fileProcBin.getName()));
|
||||||
shell.add(new SimpleCommand("toolbox kill -9 " + pidString));
|
shell.add(new SimpleCommand("toolbox kill " + signal + " " + pidString));
|
||||||
shell.add(new SimpleCommand("busybox kill -9 " + pidString));
|
shell.add(new SimpleCommand("busybox kill " + signal + " " + pidString));
|
||||||
shell.add(new SimpleCommand("kill -9 " + pidString));
|
shell.add(new SimpleCommand("kill " + signal + " " + pidString));
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|
|
@ -84,6 +84,7 @@ public interface TorServiceConstants {
|
||||||
public static final int LOG_MSG = 4;
|
public static final int LOG_MSG = 4;
|
||||||
|
|
||||||
public static final String CMD_START = "start";
|
public static final String CMD_START = "start";
|
||||||
|
public static final String CMD_SIGNAL_HUP = "signal_hup";
|
||||||
public static final String CMD_FLUSH = "flush";
|
public static final String CMD_FLUSH = "flush";
|
||||||
public static final String CMD_NEWNYM = "newnym";
|
public static final String CMD_NEWNYM = "newnym";
|
||||||
public static final String CMD_VPN = "vpn";
|
public static final String CMD_VPN = "vpn";
|
||||||
|
|
Loading…
Reference in New Issue