diff options
author | Yaroslav Brustinov <ybrustin@cisco.com> | 2016-07-04 12:55:42 +0300 |
---|---|---|
committer | Yaroslav Brustinov <ybrustin@cisco.com> | 2016-07-04 12:55:42 +0300 |
commit | 7f58dadbd502f6fe504170c443505c7ad2eb3785 (patch) | |
tree | 1f86a439d24565332a7a286841913d080fb0be74 /src/common/basic_utils.cpp | |
parent | a76479bc269cad96475f9c71381b4f826d47709f (diff) | |
parent | 582e6dddb5693d5fa7576c19b0ef7c1c0723ff59 (diff) |
Merge branch 'master' into cpu_per_core
Diffstat (limited to 'src/common/basic_utils.cpp')
-rwxr-xr-x | src/common/basic_utils.cpp | 38 |
1 files changed, 38 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); +} |