Commit abb97e16 authored by Max Lv's avatar Max Lv

play tricks to close fd manually

parent 541f8de2
...@@ -46,4 +46,5 @@ public class System { ...@@ -46,4 +46,5 @@ public class System {
public static native void exec(String cmd); public static native void exec(String cmd);
public static native String getABI(); public static native String getABI();
public static native int sendfd(int fd); public static native int sendfd(int fd);
public static native void jniclose(int fd);
} }
...@@ -43,6 +43,10 @@ void Java_com_github_shadowsocks_system_exec(JNIEnv *env, jobject thiz, jstring ...@@ -43,6 +43,10 @@ void Java_com_github_shadowsocks_system_exec(JNIEnv *env, jobject thiz, jstring
env->ReleaseStringUTFChars(cmd, str); env->ReleaseStringUTFChars(cmd, str);
} }
void Java_com_github_shadowsocks_system_jniclose(JNIEnv *env, jobject thiz, jint fd) {
close(fd);
}
jint Java_com_github_shadowsocks_system_sendfd(JNIEnv *env, jobject thiz, jint tun_fd) { jint Java_com_github_shadowsocks_system_sendfd(JNIEnv *env, jobject thiz, jint tun_fd) {
int fd; int fd;
struct sockaddr_un addr; struct sockaddr_un addr;
...@@ -75,6 +79,8 @@ jint Java_com_github_shadowsocks_system_sendfd(JNIEnv *env, jobject thiz, jint t ...@@ -75,6 +79,8 @@ jint Java_com_github_shadowsocks_system_sendfd(JNIEnv *env, jobject thiz, jint t
static const char *classPathName = "com/github/shadowsocks/System"; static const char *classPathName = "com/github/shadowsocks/System";
static JNINativeMethod method_table[] = { static JNINativeMethod method_table[] = {
{ "jniclose", "(I)V",
(void*) Java_com_github_shadowsocks_system_jniclose },
{ "sendfd", "(I)I", { "sendfd", "(I)I",
(void*) Java_com_github_shadowsocks_system_sendfd }, (void*) Java_com_github_shadowsocks_system_sendfd },
{ "exec", "(Ljava/lang/String;)V", { "exec", "(Ljava/lang/String;)V",
......
...@@ -105,6 +105,9 @@ class ShadowsocksVpnThread(vpnService: ShadowsocksVpnService) extends Thread { ...@@ -105,6 +105,9 @@ class ShadowsocksVpnThread(vpnService: ShadowsocksVpnService) extends Thread {
val fd = getInt.invoke(fds(0)).asInstanceOf[Int] val fd = getInt.invoke(fds(0)).asInstanceOf[Int]
ret = vpnService.protect(fd) ret = vpnService.protect(fd)
// Trick to close file decriptor
System.jniclose(fd)
if (ret) { if (ret) {
output.write(0) output.write(0)
} else { } else {
......
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