Skip to content

Commit 9612ef4

Browse files
Merge pull request #70 from appdevforall/refactor/ADFA-4459-proot-process-handle
ADFA-4459 refactor(proot): make process handle safe + reap on kill (D19)
2 parents a2c49b7 + 6137b6f commit 9612ef4

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

‎controller/app/src/main/java/org/iiab/controller/PRootEngine.java‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import android.os.Looper;
1515
import android.util.Log;
1616

17+
import org.iiab.controller.util.AppExecutors;
18+
1719
import java.io.BufferedReader;
1820
import java.io.File;
1921
import java.io.InputStreamReader;
@@ -26,8 +28,8 @@
2628

2729
public class PRootEngine {
2830
private static final String TAG = "IIAB-PRootEngine";
29-
private Process currentProcess;
30-
private java.io.OutputStream processOutputStream;
31+
private volatile Process currentProcess;
32+
private volatile java.io.OutputStream processOutputStream;
3133

3234
public interface OutputListener {
3335
void onOutputLine(String line);
@@ -369,8 +371,19 @@ public void writeToShell(String command) {
369371
}
370372

371373
public void killProcess() {
372-
if (currentProcess != null) {
373-
currentProcess.destroy();
374-
}
374+
final Process p = currentProcess;
375+
if (p == null) return;
376+
p.destroy();
377+
// Reap the child off the caller's thread so it does not linger as a
378+
// zombie / hold proot mounts. Process.waitFor(timeout) is API 26+ and
379+
// minSdk is 24, so we drain on the shared io() executor instead of
380+
// blocking the caller.
381+
AppExecutors.get().io().execute(() -> {
382+
try {
383+
p.waitFor();
384+
} catch (InterruptedException e) {
385+
Thread.currentThread().interrupt();
386+
}
387+
});
375388
}
376389
}

0 commit comments

Comments
 (0)