1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-01-01 12:54:07 +00:00

Native raise file number limit to maximum

Refs #311
This commit is contained in:
M66B 2016-02-11 08:48:14 +01:00
parent 97d9bcf610
commit 1212c49e9b
3 changed files with 20 additions and 0 deletions

View file

@ -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;
}

View file

@ -11,6 +11,7 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <dlfcn.h>
#include <sys/resource.h>
#include <netdb.h>
#include <arpa/inet.h>

View file

@ -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);