[tor-commits] [orbot/master] reduce use of "kill" process command for only PDSND and not tor
n8fr8 at torproject.org
n8fr8 at torproject.org
Tue Apr 28 21:05:01 UTC 2020
commit f23e9540eb6bf7e192eef94c5f9ab45217a46b00
Author: n8fr8 <nathan at guardianproject.info>
Date: Tue Feb 4 13:23:34 2020 -0500
reduce use of "kill" process command for only PDSND and not tor
- it is no longer needed for tor, and was causing the app to exit on some devices
- also, now specifically kill pdnsd using the stored PID
---
.../torproject/android/service/OrbotService.java | 7 +++---
.../android/service/vpn/OrbotVpnManager.java | 22 ++++++++++++++++--
.../torproject/android/service/vpn/VpnUtils.java | 27 +++++++++++++++++++---
3 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
index f806e42a..dbd36dbd 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
@@ -85,7 +85,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeoutException;
import static org.torproject.android.service.vpn.VpnUtils.getSharedPrefs;
-import static org.torproject.android.service.vpn.VpnUtils.killProcess;
public class OrbotService extends Service implements TorServiceConstants, OrbotConstants
{
@@ -472,6 +471,7 @@ public class OrbotService extends Service implements TorServiceConstants, OrbotC
conn = null;
}
+ /**
if (mLastProcessId != -1)
killProcess(mLastProcessId + "", "-9");
@@ -489,7 +489,7 @@ public class OrbotService extends Service implements TorServiceConstants, OrbotC
killProcess(fileTor, "-9"); // this is -HUP
} catch (Exception e) {
e.printStackTrace();
- }
+ }**/
}
@@ -502,12 +502,13 @@ public class OrbotService extends Service implements TorServiceConstants, OrbotC
} catch (IOException e) {
e.printStackTrace();
}
+ /**
// if that fails, try again using native utils
try {
killProcess(fileTor, "-1"); // this is -HUP
} catch (Exception e) {
e.printStackTrace();
- }
+ }**/
}
protected void logNotice (String msg)
diff --git a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java
index 0367ad04..14ecc20d 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java
@@ -33,6 +33,8 @@ import android.util.Log;
import android.widget.Toast;
import com.runjva.sourceforge.jsocks.protocol.ProxyServer;
import com.runjva.sourceforge.jsocks.server.ServerAuthenticatorNone;
+
+import org.apache.commons.io.IOUtils;
import org.torproject.android.service.OrbotConstants;
import org.torproject.android.service.OrbotService;
import org.torproject.android.service.R;
@@ -49,6 +51,7 @@ import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.InetAddress;
import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.TimeoutException;
import static org.torproject.android.service.TorServiceConstants.ACTION_START;
@@ -92,11 +95,12 @@ public class OrbotVpnManager implements Handler.Callback {
filePdnsd = CustomNativeLoader.loadNativeBinary(service.getApplicationContext(),PDNSD_BIN,new File(service.getFilesDir(),PDNSD_BIN));
+ /**
try {
killProcess(filePdnsd, "-1");
} catch (Exception e) {
e.printStackTrace();
- }
+ }**/
Tun2Socks.init();
@@ -417,6 +421,8 @@ public class OrbotVpnManager implements Handler.Callback {
File fileConf = makePdnsdConf(mService, mService.getFilesDir(), torDnsHost, torDnsPort, pdnsdHost, pdnsdPort);
+
+
String[] cmdString = {pdnsPath,"-c",fileConf.toString(),"-g","-v2"};
ProcessBuilder pb = new ProcessBuilder(cmdString);
pb.redirectErrorStream(true);
@@ -441,6 +447,18 @@ public class OrbotVpnManager implements Handler.Callback {
private boolean stopDns ()
{
+ File filePdnsPid = new File(mService.getFilesDir(),"pdnsd.pid");
+ List<String> lines = null;
+ try {
+ lines = IOUtils.readLines(new FileReader(filePdnsPid));
+ String dnsPid = lines.get(0);
+ killProcess(dnsPid,"");
+ } catch (Exception e) {
+ Log.e("OrbotVPN","error killing dns process",e);
+ }
+
+
+ /**
// if that fails, try again using native utils
try {
killProcess(filePdnsd, "-1"); // this is -HUP
@@ -466,7 +484,7 @@ public class OrbotVpnManager implements Handler.Callback {
} catch (Exception e) {
Log.e(TAG,"error killing DNS Process: " + pid,e);
}
- }
+ }**/
return false;
diff --git a/orbotservice/src/main/java/org/torproject/android/service/vpn/VpnUtils.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/VpnUtils.java
index acc15316..4ac71410 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/vpn/VpnUtils.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/VpnUtils.java
@@ -3,6 +3,9 @@ package org.torproject.android.service.vpn;
import android.app.ActivityManager;
import android.content.Context;
import android.content.SharedPreferences;
+import android.util.Log;
+
+import org.apache.commons.io.IOUtils;
import java.io.BufferedReader;
import java.io.File;
@@ -22,9 +25,10 @@ public class VpnUtils {
Context.MODE_MULTI_PROCESS);
}
+
public static int findProcessId(String command) throws IOException {
- String[] cmds = {"ps -ef","ps -A","toolbox ps","busybox ps"};
+ String[] cmds = {"ps -ef","ps -A","toolbox ps"};
for (int i = 0; i < cmds.length;i++) {
Process procPs = getRuntime().exec(cmds[i]);
@@ -96,12 +100,29 @@ public class VpnUtils {
public static void killProcess(String pidString, String signal) throws Exception {
- String[] cmds = {"","busybox ","toolbox "};
+ String[] cmds = {"","toolbox ","busybox "};
for (int i = 0; i < cmds.length;i++) {
try {
- getRuntime().exec("toolbox kill " + signal + " " + pidString);
+ Process proc = getRuntime().exec(cmds[i] + "kill " + signal + " " + pidString);
+ int exitVal = proc.exitValue();
+ List<String> lineErrors = IOUtils.readLines(proc.getErrorStream());
+ List<String> lineInputs = IOUtils.readLines(proc.getInputStream());
+
+ if (exitVal != 0)
+ {
+ Log.d("Orbot.killProcess","exit=" + exitVal);
+ for (String line: lineErrors)
+ Log.d("Orbot.killProcess",line);
+
+ for (String line: lineInputs)
+ Log.d("Orbot.killProcess",line);
+
+ }
+
+
} catch (IOException ioe) {
+ Log.e("Orbot.killprcess","error killing process: " + pidString,ioe);
}
}
More information about the tor-commits
mailing list