From 513e01d747b3c3815a13aa815d8c55dd4e921a93 Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 7 Jul 2020 03:24:18 +0800 Subject: [PATCH] Log errors from su --- .../src/main/java/be/mygod/librootkotlinx/RootServer.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt index 9e112f77..6ea67d6a 100644 --- a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt +++ b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt @@ -191,6 +191,13 @@ class RootServer @JvmOverloads constructor(private val warnLogger: (String) -> U future.completeExceptionally(e) return@async } + val errorReader = async(Dispatchers.IO) { + try { + process.errorStream.bufferedReader().useLines { seq -> + for (line in seq) warnLogger(line) + } + } catch (_: IOException) { } + } try { callbackSpin() if (active) throw RemoteException("Root process exited unexpectedly") @@ -199,10 +206,10 @@ class RootServer @JvmOverloads constructor(private val warnLogger: (String) -> U throw e } finally { if (DEBUG) Log.d(TAG, "Waiting for exit") + errorReader.await() process.waitFor() withContext(NonCancellable) { closeInternal(true) } } - check(process.errorStream.available() == 0) // stderr should not be used } future.await() }