diff --git a/app/src/main/jni/netguard/netguard.c b/app/src/main/jni/netguard/netguard.c index ebe8c4a4..2d582aa6 100644 --- a/app/src/main/jni/netguard/netguard.c +++ b/app/src/main/jni/netguard/netguard.c @@ -59,6 +59,19 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) { const char *rr = "eu/faircode/netguard/ResourceRecord"; clsRR = jniGlobalRef(env, jniFindClass(env, rr)); + // Raise file number limit to maximum + struct rlimit rlim; + if (getrlimit(RLIMIT_NOFILE, &rlim)) + log_android(ANDROID_LOG_WARN, "getrlimit error %d: %s", errno, strerror(errno)); + else { + rlim_t soft = rlim.rlim_cur; + rlim.rlim_cur = rlim.rlim_max; + if (setrlimit(RLIMIT_NOFILE, &rlim)) + log_android(ANDROID_LOG_WARN, "setrlimit error %d: %s", errno, strerror(errno)); + else + log_android(ANDROID_LOG_WARN, "raised file limit from %d to %d", soft, rlim.rlim_cur); + } + return JNI_VERSION_1_6; } diff --git a/app/src/main/jni/netguard/netguard.h b/app/src/main/jni/netguard/netguard.h index 6ef39683..d2f851ce 100644 --- a/app/src/main/jni/netguard/netguard.h +++ b/app/src/main/jni/netguard/netguard.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include diff --git a/app/src/main/jni/netguard/session.c b/app/src/main/jni/netguard/session.c index 911050bd..1957030a 100644 --- a/app/src/main/jni/netguard/session.c +++ b/app/src/main/jni/netguard/session.c @@ -59,6 +59,12 @@ void *handle_events(void *a) { // Get SDK version sdk = sdk_int(env); + struct rlimit rlim; + if (getrlimit(RLIMIT_NOFILE, &rlim)) + log_android(ANDROID_LOG_WARN, "getrlimit error %d: %s", errno, strerror(errno)); + else + log_android(ANDROID_LOG_WARN, "getrlimit soft %d hard %d", rlim.rlim_cur, rlim.rlim_max); + // Block SIGUSR1 sigemptyset(&blockset); sigaddset(&blockset, SIGUSR1);