Brian Silverman | 0f17ab6 | 2013-09-23 17:56:13 -0700 | [diff] [blame] | 1 | diff --git src/gtest-port.cc b/src/gtest-port.cc |
| 2 | index b860d48..acb459b 100644 |
| 3 | --- a/src/gtest-port.cc |
| 4 | +++ b/src/gtest-port.cc |
| 5 | @@ -98,6 +98,21 @@ size_t GetThreadCount() { |
| 6 | } |
| 7 | } |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 8 | |
Brian Silverman | 0f17ab6 | 2013-09-23 17:56:13 -0700 | [diff] [blame] | 9 | +#elif GTEST_OS_LINUX |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 10 | + |
Brian Silverman | 0f17ab6 | 2013-09-23 17:56:13 -0700 | [diff] [blame] | 11 | +size_t GetThreadCount() { |
| 12 | + size_t thread_count = 0; |
| 13 | + if (DIR *dir = opendir("/proc/self/task")) { |
| 14 | + while (dirent *entry = readdir(dir)) { |
| 15 | + if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { |
| 16 | + ++thread_count; |
| 17 | + } |
| 18 | + } |
| 19 | + closedir(dir); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 20 | + } |
Brian Silverman | 0f17ab6 | 2013-09-23 17:56:13 -0700 | [diff] [blame] | 21 | + return thread_count; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 22 | +} |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 23 | + |
Brian Silverman | 0f17ab6 | 2013-09-23 17:56:13 -0700 | [diff] [blame] | 24 | #else |
| 25 | |
| 26 | size_t GetThreadCount() { |
| 27 | diff --git a/src/gtest-death-test.cc b/src/gtest-death-test.cc |
| 28 | index 8b2e413..faad3a4 100644 |
| 29 | --- a/src/gtest-death-test.cc |
| 30 | +++ b/src/gtest-death-test.cc |
| 31 | @@ -44,6 +44,8 @@ |
| 32 | # include <fcntl.h> |
| 33 | # include <limits.h> |
| 34 | # include <stdarg.h> |
| 35 | +# include <sys/time.h> |
| 36 | +# include <sys/resource.h> |
| 37 | |
| 38 | # if GTEST_OS_WINDOWS |
| 39 | # include <windows.h> |
| 40 | @@ -898,6 +900,11 @@ inline char** GetEnviron() { return environ; } |
| 41 | // This function is called in a clone()-ed process and thus must avoid |
| 42 | // any potentially unsafe operations like malloc or libc functions. |
| 43 | static int ExecDeathTestChildMain(void* child_arg) { |
| 44 | + rlimit core_rlimit; |
| 45 | + core_rlimit.rlim_cur = 0; |
| 46 | + core_rlimit.rlim_max = 0; |
| 47 | + GTEST_DEATH_TEST_CHECK_SYSCALL_(setrlimit(RLIMIT_CORE, &core_limit)); |
| 48 | + |
| 49 | ExecDeathTestArgs* const args = static_cast<ExecDeathTestArgs*>(child_arg); |
| 50 | GTEST_DEATH_TEST_CHECK_SYSCALL_(close(args->close_fd)); |