Move read stderr inside doInit
This commit is contained in:
@@ -131,6 +131,7 @@ class RootServer {
|
||||
}
|
||||
}
|
||||
private fun doInit(context: Context, niceName: String) {
|
||||
try {
|
||||
val (reader, writer) = try {
|
||||
process = ProcessBuilder("su").start()
|
||||
val token1 = UUID.randomUUID().toString()
|
||||
@@ -153,8 +154,8 @@ class RootServer {
|
||||
UUID.randomUUID().toString().also { persistence.writeText(it) }
|
||||
}
|
||||
val (script, relocated) = AppProcess.relocateScript(uuid)
|
||||
script.appendLine(AppProcess.launchString(context.packageCodePath, RootServer::class.java.name, relocated,
|
||||
niceName) + " $token2")
|
||||
script.appendLine(AppProcess.launchString(context.packageCodePath, RootServer::class.java.name,
|
||||
relocated, niceName) + " $token2")
|
||||
writer.writeBytes(script.toString())
|
||||
writer.flush()
|
||||
reader.lookForToken(token2) // wait for ready signal
|
||||
@@ -165,6 +166,13 @@ class RootServer {
|
||||
require(!active)
|
||||
active = true
|
||||
Logger.me.d("Root server initialized")
|
||||
} finally {
|
||||
try {
|
||||
readUnexpectedStderr()?.let { Logger.me.e(it) }
|
||||
} catch (e: IOException) {
|
||||
Logger.me.e("Failed to read from stderr", e) // avoid the real exception being swallowed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun callbackSpin() {
|
||||
@@ -196,17 +204,7 @@ class RootServer {
|
||||
* @param niceName Name to call the rooted Java process.
|
||||
*/
|
||||
suspend fun init(context: Context, niceName: String = "${context.packageName}:root") {
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
doInit(context, niceName)
|
||||
} finally {
|
||||
try {
|
||||
readUnexpectedStderr()?.let { Logger.me.e(it) }
|
||||
} catch (e: IOException) {
|
||||
Logger.me.e("Failed to read from stderr", e) // avoid the real exception being swallowed
|
||||
}
|
||||
}
|
||||
}
|
||||
withContext(Dispatchers.IO) { doInit(context, niceName) }
|
||||
callbackListenerExit = GlobalScope.async(Dispatchers.IO) {
|
||||
val errorReader = async(Dispatchers.IO) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user