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