1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2025-07-07 08:14:58 +03:00

v4.10-9505-beta

This commit is contained in:
dnobori
2014-10-04 00:09:23 +09:00
parent 16b713b98d
commit 10d4b2c43d
349 changed files with 2640 additions and 898 deletions

View File

@ -966,6 +966,24 @@ void *UnixNewSingleInstance(char *instance_name)
}
}
// Set the high oom score
void UnixSetHighOomScore()
{
IO *o;
char tmp[256];
sprintf(tmp, "/proc/%u/oom_score_adj", getpid());
o = UnixFileCreate(tmp);
if (o != NULL)
{
char tmp[128];
sprintf(tmp, "%u\n", 800);
UnixFileWrite(o, tmp, strlen(tmp));
UnixFileClose(o, false);
}
}
// Raise the priority of the process
void UnixSetHighPriority()
{
@ -2139,10 +2157,24 @@ void UnixSigChldHandler(int sig)
signal(SIGCHLD, UnixSigChldHandler);
}
// Disable core dump
void UnixDisableCoreDump()
{
#ifdef RLIMIT_CORE
UnixSetResourceLimit(RLIMIT_CORE, 0);
#endif // RLIMIT_CORE
}
// Initialize the library for UNIX
void UnixInit()
{
UNIXIO *o;
UINT64 max_memory = UNIX_MAX_MEMORY;
if (UnixIs64BitRlimSupported())
{
max_memory = UNIX_MAX_MEMORY_64;
}
UnixInitSolarisSleep();
@ -2154,11 +2186,11 @@ void UnixInit()
current_process_id = getpid();
#ifdef RLIMIT_CORE
UnixSetResourceLimit(RLIMIT_CORE, UNIX_MAX_MEMORY);
UnixSetResourceLimit(RLIMIT_CORE, max_memory);
#endif // RLIMIT_CORE
#ifdef RLIMIT_DATA
UnixSetResourceLimit(RLIMIT_DATA, UNIX_MAX_MEMORY);
UnixSetResourceLimit(RLIMIT_DATA, max_memory);
#endif // RLIMIT_DATA
#ifdef RLIMIT_NOFILE
@ -2170,11 +2202,11 @@ void UnixInit()
#endif // RLIMIT_NOFILE
#ifdef RLIMIT_STACK
// UnixSetResourceLimit(RLIMIT_STACK, UNIX_MAX_MEMORY);
// UnixSetResourceLimit(RLIMIT_STACK, max_memory);
#endif // RLIMIT_STACK
#ifdef RLIMIT_RSS
UnixSetResourceLimit(RLIMIT_RSS, UNIX_MAX_MEMORY);
UnixSetResourceLimit(RLIMIT_RSS, max_memory);
#endif // RLIMIT_RSS
#ifdef RLIMIT_LOCKS
@ -2182,7 +2214,7 @@ void UnixInit()
#endif // RLIMIT_LOCKS
#ifdef RLIMIT_MEMLOCK
UnixSetResourceLimit(RLIMIT_MEMLOCK, UNIX_MAX_MEMORY);
UnixSetResourceLimit(RLIMIT_MEMLOCK, max_memory);
#endif // RLIMIT_MEMLOCK
#ifdef RLIMIT_NPROC
@ -2226,27 +2258,46 @@ void UnixFree()
}
// Adjust the upper limit of resources that may be occupied
void UnixSetResourceLimit(UINT id, UINT value)
void UnixSetResourceLimit(UINT id, UINT64 value)
{
struct rlimit t;
UINT hard_limit;
UINT64 hard_limit;
if (UnixIs64BitRlimSupported() == false)
{
if (value > (UINT64)4294967295ULL)
{
value = (UINT64)4294967295ULL;
}
}
Zero(&t, sizeof(t));
getrlimit(id, &t);
hard_limit = t.rlim_max;
hard_limit = (UINT64)t.rlim_max;
Zero(&t, sizeof(t));
t.rlim_cur = MIN(value, hard_limit);
t.rlim_max = hard_limit;
t.rlim_cur = (rlim_t)MIN(value, hard_limit);
t.rlim_max = (rlim_t)hard_limit;
setrlimit(id, &t);
Zero(&t, sizeof(t));
t.rlim_cur = value;
t.rlim_max = value;
t.rlim_cur = (rlim_t)value;
t.rlim_max = (rlim_t)value;
setrlimit(id, &t);
}
// Is the rlim_t type 64-bit?
bool UnixIs64BitRlimSupported()
{
if (sizeof(rlim_t) >= 8)
{
return true;
}
return false;
}
// Generate the PID file name
void UnixGenPidFileName(char *name, UINT size)
{