Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/SoftEtherVPN/SoftEtherVPN_Stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mayaqua/Unix.c')
-rw-r--r--src/Mayaqua/Unix.c81
1 files changed, 66 insertions, 15 deletions
diff --git a/src/Mayaqua/Unix.c b/src/Mayaqua/Unix.c
index 587baf71..f0b28109 100644
--- a/src/Mayaqua/Unix.c
+++ b/src/Mayaqua/Unix.c
@@ -3,9 +3,9 @@
//
// SoftEther VPN Server, Client and Bridge are free software under GPLv2.
//
-// Copyright (c) 2012-2014 Daiyuu Nobori.
-// Copyright (c) 2012-2014 SoftEther VPN Project, University of Tsukuba, Japan.
-// Copyright (c) 2012-2014 SoftEther Corporation.
+// Copyright (c) 2012-2016 Daiyuu Nobori.
+// Copyright (c) 2012-2016 SoftEther VPN Project, University of Tsukuba, Japan.
+// Copyright (c) 2012-2016 SoftEther Corporation.
//
// All Rights Reserved.
//
@@ -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)
{