blob: f0ee20091d79817af86bce3adabb95334f3c4694 [file] [log] [blame]
Brian Silverman0f17ab62013-09-23 17:56:13 -07001diff --git src/gtest-port.cc b/src/gtest-port.cc
2index b860d48..acb459b 100644
3--- a/src/gtest-port.cc
4+++ b/src/gtest-port.cc
Brian Silverman29458232014-04-30 15:53:46 -07005@@ -35,6 +35,8 @@
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9+#include <sys/types.h>
10+#include <dirent.h>
11
12 #if GTEST_OS_WINDOWS_MOBILE
13 # include <windows.h> // For TerminateProcess()
Brian Silverman0f17ab62013-09-23 17:56:13 -070014@@ -98,6 +98,21 @@ size_t GetThreadCount() {
15 }
16 }
brians343bc112013-02-10 01:53:46 +000017
Brian Silverman0f17ab62013-09-23 17:56:13 -070018+#elif GTEST_OS_LINUX
brians343bc112013-02-10 01:53:46 +000019+
Brian Silverman0f17ab62013-09-23 17:56:13 -070020+size_t GetThreadCount() {
21+ size_t thread_count = 0;
22+ if (DIR *dir = opendir("/proc/self/task")) {
23+ while (dirent *entry = readdir(dir)) {
24+ if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
25+ ++thread_count;
26+ }
27+ }
28+ closedir(dir);
brians343bc112013-02-10 01:53:46 +000029+ }
Brian Silverman0f17ab62013-09-23 17:56:13 -070030+ return thread_count;
brians343bc112013-02-10 01:53:46 +000031+}
brians343bc112013-02-10 01:53:46 +000032+
Brian Silverman0f17ab62013-09-23 17:56:13 -070033 #else
34
35 size_t GetThreadCount() {
36diff --git a/src/gtest-death-test.cc b/src/gtest-death-test.cc
37index 8b2e413..faad3a4 100644
38--- a/src/gtest-death-test.cc
39+++ b/src/gtest-death-test.cc
40@@ -44,6 +44,8 @@
41 # include <fcntl.h>
42 # include <limits.h>
43 # include <stdarg.h>
44+# include <sys/time.h>
45+# include <sys/resource.h>
46
47 # if GTEST_OS_WINDOWS
48 # include <windows.h>
49@@ -898,6 +900,11 @@ inline char** GetEnviron() { return environ; }
50 // This function is called in a clone()-ed process and thus must avoid
51 // any potentially unsafe operations like malloc or libc functions.
52 static int ExecDeathTestChildMain(void* child_arg) {
53+ rlimit core_rlimit;
54+ core_rlimit.rlim_cur = 0;
55+ core_rlimit.rlim_max = 0;
Brian Silverman29458232014-04-30 15:53:46 -070056+ GTEST_DEATH_TEST_CHECK_SYSCALL_(setrlimit(RLIMIT_CORE, &core_rlimit));
Brian Silverman0f17ab62013-09-23 17:56:13 -070057+
58 ExecDeathTestArgs* const args = static_cast<ExecDeathTestArgs*>(child_arg);
59 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(args->close_fd));