Commit 89b9914f authored by Mygod's avatar Mygod

Fix ETXTBSY in copyAssets

parent 809b81a3
...@@ -63,9 +63,7 @@ import com.github.shadowsocks.database._ ...@@ -63,9 +63,7 @@ import com.github.shadowsocks.database._
import com.github.shadowsocks.utils.CloseUtils._ import com.github.shadowsocks.utils.CloseUtils._
import com.github.shadowsocks.utils._ import com.github.shadowsocks.utils._
import com.google.android.gms.ads.{AdRequest, AdSize, AdView} import com.google.android.gms.ads.{AdRequest, AdSize, AdView}
import eu.chainfire.libsuperuser.Shell
import scala.collection.mutable.ArrayBuffer
import scala.util.Random import scala.util.Random
object Typefaces { object Typefaces {
...@@ -189,8 +187,8 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -189,8 +187,8 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
} }
override def binderDied { override def binderDied {
detachService detachService()
crashRecovery app.crashRecovery()
attachService attachService
} }
...@@ -228,23 +226,6 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -228,23 +226,6 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
} }
} }
def crashRecovery() {
val cmd = new ArrayBuffer[String]()
for (task <- Array("ss-local", "ss-tunnel", "pdnsd", "redsocks", "tun2socks", "kcptun")) {
cmd.append("killall %s".formatLocal(Locale.ENGLISH, task))
cmd.append("rm -f %1$s/%2$s-nat.conf %1$s/%2$s-vpn.conf"
.formatLocal(Locale.ENGLISH, getApplicationInfo.dataDir, task))
}
if (app.isNatEnabled) {
cmd.append("iptables -t nat -F OUTPUT")
cmd.append("echo done")
val result = Shell.SU.run(cmd.toArray)
if (result != null && !result.isEmpty) return // fallback to SH
}
Shell.SH.run(cmd.toArray)
}
def cancelStart() { def cancelStart() {
clearDialog() clearDialog()
changeSwitch(checked = false) changeSwitch(checked = false)
...@@ -463,17 +444,11 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -463,17 +444,11 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
handler.removeCallbacksAndMessages(null) handler.removeCallbacksAndMessages(null)
} }
def reset() {
crashRecovery()
app.copyAssets()
}
def recovery() { def recovery() {
if (serviceStarted) serviceStop() if (serviceStarted) serviceStop()
val h = showProgress(R.string.recovering) val h = showProgress(R.string.recovering)
Utils.ThrowableFuture { Utils.ThrowableFuture {
reset() app.copyAssets()
h.sendEmptyMessage(0) h.sendEmptyMessage(0)
} }
} }
......
...@@ -62,6 +62,8 @@ import com.google.android.gms.tagmanager.{ContainerHolder, TagManager} ...@@ -62,6 +62,8 @@ import com.google.android.gms.tagmanager.{ContainerHolder, TagManager}
import com.j256.ormlite.logger.LocalLog import com.j256.ormlite.logger.LocalLog
import eu.chainfire.libsuperuser.Shell import eu.chainfire.libsuperuser.Shell
import scala.collection.mutable.ArrayBuffer
object ShadowsocksApplication { object ShadowsocksApplication {
var app: ShadowsocksApplication = _ var app: ShadowsocksApplication = _
...@@ -207,7 +209,25 @@ class ShadowsocksApplication extends Application { ...@@ -207,7 +209,25 @@ class ShadowsocksApplication extends Application {
IOUtils.copy(in, out))) IOUtils.copy(in, out)))
} }
def crashRecovery() {
val cmd = new ArrayBuffer[String]()
for (task <- Array("ss-local", "ss-tunnel", "pdnsd", "redsocks", "tun2socks", "kcptun")) {
cmd.append("killall %s".formatLocal(Locale.ENGLISH, task))
cmd.append("rm -f %1$s/%2$s-nat.conf %1$s/%2$s-vpn.conf"
.formatLocal(Locale.ENGLISH, getApplicationInfo.dataDir, task))
}
if (app.isNatEnabled) {
cmd.append("iptables -t nat -F OUTPUT")
cmd.append("echo done")
val result = Shell.SU.run(cmd.toArray)
if (result != null && !result.isEmpty) return // fallback to SH
}
Shell.SH.run(cmd.toArray)
}
def copyAssets() { def copyAssets() {
crashRecovery() // ensure executables are killed before writing to them
copyAssets(System.getABI) copyAssets(System.getABI)
copyAssets("acl") copyAssets("acl")
Shell.SH.run(EXECUTABLES.map("chmod 755 " + getApplicationInfo.dataDir + '/' + _)) Shell.SH.run(EXECUTABLES.map("chmod 755 " + getApplicationInfo.dataDir + '/' + _))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment