Handle stdout/stderr of GuardedProcess properly
This commit is contained in:
+1
-1
Submodule kcptun/kcptun updated: e613b5ad61...c4054b07a6
+1
-1
Submodule src/main/jni/pdnsd updated: b51fd4f65c...7a76962795
@@ -39,18 +39,33 @@
|
||||
|
||||
package com.github.shadowsocks
|
||||
|
||||
import java.io.{IOException, InputStream, OutputStream}
|
||||
import java.io._
|
||||
import java.lang.System.currentTimeMillis
|
||||
import java.util.concurrent.Semaphore
|
||||
|
||||
import android.util.Log
|
||||
|
||||
import scala.collection.JavaConversions._
|
||||
import scala.collection.immutable.Stream
|
||||
import scala.util.control.Exception._
|
||||
|
||||
class StreamLogger(is: InputStream, tag: String) extends Thread {
|
||||
|
||||
def withCloseable[T <: Closeable, R](t: T)(f: T => R): R = {
|
||||
allCatch.andFinally{t.close} apply { f(t) }
|
||||
}
|
||||
|
||||
override def run() {
|
||||
withCloseable(new BufferedReader(new InputStreamReader(is))) {
|
||||
br => Stream.continually(br.readLine()).takeWhile(_ != null).foreach(Log.i(tag, _))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author ayanamist@gmail.com
|
||||
*/
|
||||
class GuardedProcess(cmd: Seq[String]) extends Process {
|
||||
class GuardedProcess(cmd: Seq[String]) {
|
||||
private val TAG = classOf[GuardedProcess].getSimpleName
|
||||
|
||||
@volatile private var guardThread: Thread = _
|
||||
@@ -72,6 +87,9 @@ class GuardedProcess(cmd: Seq[String]) extends Process {
|
||||
|
||||
process = new ProcessBuilder(cmd).redirectErrorStream(true).start
|
||||
|
||||
val is = process.getInputStream
|
||||
new StreamLogger(is, TAG).start
|
||||
|
||||
if (callback == null) callback = onRestartCallback else callback()
|
||||
|
||||
semaphore.release
|
||||
@@ -118,11 +136,6 @@ class GuardedProcess(cmd: Seq[String]) extends Process {
|
||||
process.destroy()
|
||||
}
|
||||
|
||||
def exitValue: Int = throw new UnsupportedOperationException
|
||||
def getErrorStream: InputStream = throw new UnsupportedOperationException
|
||||
def getInputStream: InputStream = throw new UnsupportedOperationException
|
||||
def getOutputStream: OutputStream = throw new UnsupportedOperationException
|
||||
|
||||
@throws(classOf[InterruptedException])
|
||||
def waitFor = {
|
||||
guardThread.join()
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
package com.github.shadowsocks
|
||||
|
||||
import java.io.File
|
||||
import java.lang.Process
|
||||
import java.net.{Inet6Address, InetAddress}
|
||||
import java.util.Locale
|
||||
|
||||
@@ -65,10 +64,10 @@ class ShadowsocksNatService extends BaseService {
|
||||
private var notification: ShadowsocksNotification = _
|
||||
val myUid = android.os.Process.myUid()
|
||||
|
||||
var sslocalProcess: Process = _
|
||||
var sstunnelProcess: Process = _
|
||||
var redsocksProcess: Process = _
|
||||
var pdnsdProcess: Process = _
|
||||
var sslocalProcess: GuardedProcess = _
|
||||
var sstunnelProcess: GuardedProcess = _
|
||||
var redsocksProcess: GuardedProcess = _
|
||||
var pdnsdProcess: GuardedProcess = _
|
||||
var su: Shell.Interactive = _
|
||||
|
||||
def startShadowsocksDaemon() {
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
package com.github.shadowsocks
|
||||
|
||||
import java.io.File
|
||||
import java.lang.Process
|
||||
import java.util.Locale
|
||||
|
||||
import android.content._
|
||||
@@ -63,10 +62,10 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
var vpnThread: ShadowsocksVpnThread = _
|
||||
private var notification: ShadowsocksNotification = _
|
||||
|
||||
var sslocalProcess: Process = _
|
||||
var sstunnelProcess: Process = _
|
||||
var pdnsdProcess: Process = _
|
||||
var tun2socksProcess: Process = _
|
||||
var sslocalProcess: GuardedProcess = _
|
||||
var sstunnelProcess: GuardedProcess = _
|
||||
var pdnsdProcess: GuardedProcess = _
|
||||
var tun2socksProcess: GuardedProcess = _
|
||||
|
||||
override def onBind(intent: Intent): IBinder = {
|
||||
val action = intent.getAction
|
||||
|
||||
Reference in New Issue
Block a user