Skip to content

Commit

Permalink
Add RUST_BACKTRACE
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed May 4, 2020
1 parent cf37e75 commit fdff88e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Expand Up @@ -43,15 +43,18 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C
}
}

private inner class Guard(private val cmd: List<String>) {
private inner class Guard(private val cmd: List<String>, private val environment: Map<String, String>) {
private lateinit var process: Process

private fun streamLogger(input: InputStream, logger: (String) -> Unit) = try {
input.bufferedReader().forEachLine(logger)
} 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)?) {
Expand Down Expand Up @@ -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<String>, onRestartCallback: (suspend () -> Unit)? = null) {
fun start(cmd: List<String>, environment: Map<String, String> = 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) }
}
Expand Down
Expand Up @@ -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() {
Expand Down

0 comments on commit fdff88e

Please sign in to comment.