mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Kill zombie Tor processes more reliably.
This commit is contained in:
@@ -376,9 +376,11 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
* killed. ActivityManager.killBackgroundProcesses() doesn't seem to work
|
* killed. ActivityManager.killBackgroundProcesses() doesn't seem to work
|
||||||
* in this case, so we must parse the output of ps to get the PID.
|
* in this case, so we must parse the output of ps to get the PID.
|
||||||
* <p>
|
* <p>
|
||||||
* On all tested devices, the output consists of a header line followed by
|
* On all devices we've tested, the output consists of a header line
|
||||||
* one line per process. The second column is the PID and the last column
|
* followed by one line per process. The second column is the PID and the
|
||||||
* is the process name, which includes the app's package name.
|
* last column is the process name, which includes the app's package name.
|
||||||
|
* On some devices tested by the Guardian Project, the first column is the
|
||||||
|
* PID.
|
||||||
*/
|
*/
|
||||||
private void killZombieProcess() {
|
private void killZombieProcess() {
|
||||||
String packageName = "/" + appContext.getPackageName() + "/";
|
String packageName = "/" + appContext.getPackageName() + "/";
|
||||||
@@ -388,12 +390,21 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
Scanner scanner = new Scanner(ps.getInputStream());
|
Scanner scanner = new Scanner(ps.getInputStream());
|
||||||
// Discard the header line
|
// Discard the header line
|
||||||
if(scanner.hasNextLine()) scanner.nextLine();
|
if(scanner.hasNextLine()) scanner.nextLine();
|
||||||
// Look for a Tor process with our package name
|
// Look for any Tor processes with our package name
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
while(scanner.hasNextLine()) {
|
while(scanner.hasNextLine()) {
|
||||||
String[] columns = scanner.nextLine().split("\\s+");
|
String[] columns = scanner.nextLine().split("\\s+");
|
||||||
if(columns.length < 3) break;
|
if(columns.length < 3) continue;
|
||||||
int pid = Integer.parseInt(columns[1]);
|
int pid;
|
||||||
|
try {
|
||||||
|
pid = Integer.parseInt(columns[1]);
|
||||||
|
} catch(NumberFormatException e) {
|
||||||
|
try {
|
||||||
|
pid = Integer.parseInt(columns[0]);
|
||||||
|
} catch(NumberFormatException e1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
String name = columns[columns.length - 1];
|
String name = columns[columns.length - 1];
|
||||||
if(name.contains(packageName) && name.endsWith("/tor")) {
|
if(name.contains(packageName) && name.endsWith("/tor")) {
|
||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
|
|||||||
Reference in New Issue
Block a user