diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/root/MiscCommands.kt b/mobile/src/main/java/be/mygod/vpnhotspot/root/MiscCommands.kt index e2906cf6..91eb5f23 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/root/MiscCommands.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/root/MiscCommands.kt @@ -20,12 +20,19 @@ import java.io.FileOutputStream import java.io.InterruptedIOException import java.util.concurrent.Executor +fun ProcessBuilder.fixPath(redirect: Boolean = false) = apply { + environment().compute("PATH") { _, value -> + if (value.isNullOrEmpty()) "/system/bin" else "$value:/system/bin" + } + redirectErrorStream(redirect) +} + @Parcelize class Dump(val path: String, val cacheDir: File = app.deviceStorage.codeCacheDir) : RootCommandNoResult { @Suppress("BlockingMethodInNonBlockingContext") override suspend fun execute() = withContext(Dispatchers.IO) { FileOutputStream(path, true).use { out -> - val process = ProcessBuilder("sh").redirectErrorStream(true).start() + val process = ProcessBuilder("sh").fixPath(true).start() process.outputStream.bufferedWriter().use { commands -> // https://android.googlesource.com/platform/external/iptables/+/android-7.0.0_r1/iptables/Android.mk#34 val iptablesSave = if (Build.VERSION.SDK_INT < 24) File(cacheDir, "iptables-save").absolutePath.also { @@ -191,7 +198,7 @@ class SettingsGlobalPut(val name: String, val value: String) : RootCommandNoResu @Suppress("BlockingMethodInNonBlockingContext") override suspend fun execute() = withContext(Dispatchers.IO) { - val process = ProcessBuilder("settings", "put", "global", name, value).redirectErrorStream(true).start() + val process = ProcessBuilder("settings", "put", "global", name, value).fixPath(true).start() val error = process.inputStream.bufferedReader().readText() check(process.waitFor() == 0) if (error.isNotEmpty()) throw RemoteException(error) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/root/RoutingCommands.kt b/mobile/src/main/java/be/mygod/vpnhotspot/root/RoutingCommands.kt index c90ad964..868d20dd 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/root/RoutingCommands.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/root/RoutingCommands.kt @@ -16,7 +16,7 @@ object RoutingCommands { class Clean : RootCommandOneWay { @Suppress("BlockingMethodInNonBlockingContext") override suspend fun execute() = withContext(Dispatchers.IO) { - val process = ProcessBuilder("sh").redirectErrorStream(true).start() + val process = ProcessBuilder("sh").fixPath(true).start() process.outputStream.bufferedWriter().use(Routing.Companion::appendCleanCommands) when (val code = process.waitFor()) { 0 -> { } @@ -48,7 +48,7 @@ object RoutingCommands { class Process(val command: List, private val redirect: Boolean = false) : RootCommand { @Suppress("BlockingMethodInNonBlockingContext") override suspend fun execute() = withContext(Dispatchers.IO) { - val process = ProcessBuilder(command).redirectErrorStream(redirect).start() + val process = ProcessBuilder(command).fixPath(redirect).start() coroutineScope { val output = async { process.inputStream.bufferedReader().readText() } val error = async { if (redirect) "" else process.errorStream.bufferedReader().readText() }