From fdff88e0ee9dcba3ed95ca36b10684082045c062 Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 5 May 2020 01:43:24 +0800 Subject: [PATCH] Add RUST_BACKTRACE --- .../com/github/shadowsocks/bg/GuardedProcessPool.kt | 12 ++++++++---- .../java/com/github/shadowsocks/bg/ProxyInstance.kt | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/github/shadowsocks/bg/GuardedProcessPool.kt b/core/src/main/java/com/github/shadowsocks/bg/GuardedProcessPool.kt index 6abea59dbe..6ad6f97c18 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/GuardedProcessPool.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/GuardedProcessPool.kt @@ -43,7 +43,7 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C } } - private inner class Guard(private val cmd: List) { + private inner class Guard(private val cmd: List, private val environment: Map) { private lateinit var process: Process private fun streamLogger(input: InputStream, logger: (String) -> Unit) = try { @@ -51,7 +51,10 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C } catch (_: IOException) { } // ignore fun start() { - process = ProcessBuilder(cmd).directory(Core.deviceStorage.noBackupFilesDir).start() + process = ProcessBuilder(cmd).apply { + directory(Core.deviceStorage.noBackupFilesDir) + environment().putAll(environment) + }.start() } suspend fun looper(onRestartCallback: (suspend () -> Unit)?) { @@ -111,9 +114,10 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C override val coroutineContext = Dispatchers.Main.immediate + Job() @MainThread - fun start(cmd: List, onRestartCallback: (suspend () -> Unit)? = null) { + fun start(cmd: List, environment: Map = emptyMap(), + onRestartCallback: (suspend () -> Unit)? = null) { Timber.i("start process: ${Commandline.toString(cmd)}") - Guard(cmd).apply { + Guard(cmd, environment).apply { start() // if start fails, IOException will be thrown directly launch { looper(onRestartCallback) } } diff --git a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt index e8134709f8..fc0bf4d353 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt @@ -129,7 +129,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro cmd += Acl.getFile(route).absolutePath } - service.data.processes!!.start(cmd) + service.data.processes!!.start(cmd, mapOf("RUST_BACKTRACE" to "1")) } fun scheduleUpdate() {