Ensure /system/bin is in PATH
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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<String>, private val redirect: Boolean = false) : RootCommand<ProcessResult> {
|
||||
@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() }
|
||||
|
||||
Reference in New Issue
Block a user