diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-29 17:51:51 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-29 17:51:51 +0000 |
commit | 05d4b0ae3154d410443f5ac5d6f74c970ce8d700 (patch) | |
tree | 32662f7f9bbb25f81123fb7e34b8bd177d39f161 /base/process_util_unittest.cc | |
parent | 3216fbdae4d6887bc87240879530fb9f688d013b (diff) | |
download | chromium_src-05d4b0ae3154d410443f5ac5d6f74c970ce8d700.zip chromium_src-05d4b0ae3154d410443f5ac5d6f74c970ce8d700.tar.gz chromium_src-05d4b0ae3154d410443f5ac5d6f74c970ce8d700.tar.bz2 |
Add routine to close file descriptors on exec
for linux and mac. See BUG 6598.
Review URL: http://codereview.chromium.org/18801
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8892 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_unittest.cc')
-rw-r--r-- | base/process_util_unittest.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index a6eb8a7..0b3bc21 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -142,6 +142,24 @@ TEST_F(ProcessUtilTest, CalcFreeMemory) { #endif // defined(OS_WIN) #if defined(OS_POSIX) +// Returns the maximum number of files that a process can have open. +// Returns 0 on error. +int GetMaxFilesOpenInProcess() { + struct rlimit rlim; + if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) { + return 0; + } + + // rlim_t is a uint64 - clip to maxint. We do this since FD #s are ints + // which are all 32 bits on the supported platforms. + rlim_t max_int = static_cast<rlim_t>(std::numeric_limits<int32>::max()); + if (rlim.rlim_cur > max_int) { + return max_int; + } + + return rlim.rlim_cur; +} + const int kChildPipe = 20; // FD # for write end of pipe in child process. MULTIPROCESS_TEST_MAIN(ProcessUtilsLeakFDChildProcess) { // This child process counts the number of open FDs, it then writes that |