diff options
author | 2016-06-23 11:27:05 +0300 | |
---|---|---|
committer | 2016-06-23 11:27:36 +0300 | |
commit | 5f84648529772a4b0b52eedfbf3669c6e45d653f (patch) | |
tree | 191d61b3a332e7a007c63a716c561824b4f29538 /src/common | |
parent | f672c6c1ac980fa248298b679603da3645735787 (diff) |
allow coredump for TRex with --alow-coredump
by default, huge pages will not be mapped to the core
Diffstat (limited to 'src/common')
-rwxr-xr-x | src/common/basic_utils.cpp | 38 | ||||
-rwxr-xr-x | src/common/basic_utils.h | 10 |
2 files changed, 48 insertions, 0 deletions
diff --git a/src/common/basic_utils.cpp b/src/common/basic_utils.cpp index 4f5578a6..b2277697 100755 --- a/src/common/basic_utils.cpp +++ b/src/common/basic_utils.cpp @@ -18,6 +18,7 @@ limitations under the License. #include <stdio.h> #include <string> #include <sstream> +#include <sys/resource.h> bool utl_is_file_exists (const std::string& name) { if (FILE *file = fopen(name.c_str(), "r")) { @@ -198,3 +199,40 @@ utl_generate_random_str(unsigned int &seed, int len) { return (ss.str()); } +/** + * define the coredump size + * allowed when crashing + * + * @param size - -1 means unlimited + * @param map_huge_pages - should the core map the huge TLB + * pages + */ +void utl_set_coredump_size(long size, bool map_huge_pages) { + int mask; + struct rlimit core_limits; + + if (size == -1) { + core_limits.rlim_cur = core_limits.rlim_max = RLIM_INFINITY; + } else { + core_limits.rlim_cur = core_limits.rlim_max = size; + } + + setrlimit(RLIMIT_CORE, &core_limits); + + /* set core dump mask */ + FILE *fp = fopen("/proc/self/coredump_filter", "wb"); + if (!fp) { + printf("failed to open /proc/self/coredump_filter\n"); + exit(-1); + } + + /* huge pages is the 5th bit */ + if (map_huge_pages) { + mask = 0x33; + } else { + mask = 0x13; + } + + fprintf(fp, "%08x\n", mask); + fclose(fp); +} diff --git a/src/common/basic_utils.h b/src/common/basic_utils.h index 63e858ab..1884e896 100755 --- a/src/common/basic_utils.h +++ b/src/common/basic_utils.h @@ -87,6 +87,16 @@ void utl_macaddr_to_str(const uint8_t *macaddr, std::string &output); std::string utl_generate_random_str(unsigned int &seed, int len); +/** + * define the coredump size + * allowed when crashing + * + * @param size - -1 means unlimited + * @param map_huge_pages - should the core map the huge TLB + * pages + */ +void utl_set_coredump_size(long size, bool map_huge_pages = false); + #endif |