Merge pull request #1645 from XairRrR/fix/raise-open-file-limit
fix(libkernel): raise the open file soft limit on Linux
This commit is contained in:
commit
c963432db0
|
|
@ -7,6 +7,7 @@ add_library(libkernel SHARED EXCLUDE_FROM_ALL
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/File/src/NativeStat.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/File/src/Terminal.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/File/src/Open.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/File/src/OpenFileLimit.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/File/src/Stdio.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../libc/src/Rename.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Semaphore/src/Semaphore.cpp
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
#if defined(__linux__)
|
||||
|
||||
#include <cerrno>
|
||||
#include <system_error>
|
||||
#include <sys/resource.h>
|
||||
|
||||
namespace {
|
||||
|
||||
struct OpenFileLimit {
|
||||
OpenFileLimit() {
|
||||
rlimit limit{};
|
||||
if (getrlimit(RLIMIT_NOFILE, &limit) != 0) throw std::system_error(errno, std::generic_category(), "read open file limit");
|
||||
if (limit.rlim_cur >= limit.rlim_max) return;
|
||||
limit.rlim_cur = limit.rlim_max;
|
||||
if (setrlimit(RLIMIT_NOFILE, &limit) != 0) throw std::system_error(errno, std::generic_category(), "raise open file limit");
|
||||
}
|
||||
} openFileLimit;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue