Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: base/process_util_unittest.cc

Issue 18801: Add routine to close file descriptors on exec (Closed)
Patch Set: final cleanups Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/process_util_posix.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #define _CRT_SECURE_NO_WARNINGS 5 #define _CRT_SECURE_NO_WARNINGS
6 6
7 #include "base/multiprocess_test.h" 7 #include "base/multiprocess_test.h"
8 #include "base/platform_thread.h" 8 #include "base/platform_thread.h"
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 EXPECT_GE(expected_total, free_mem2.total); 135 EXPECT_GE(expected_total, free_mem2.total);
136 EXPECT_GE(expected_largest, free_mem2.largest); 136 EXPECT_GE(expected_largest, free_mem2.largest);
137 EXPECT_TRUE(NULL != free_mem2.largest_ptr); 137 EXPECT_TRUE(NULL != free_mem2.largest_ptr);
138 138
139 delete[] alloc; 139 delete[] alloc;
140 delete metrics; 140 delete metrics;
141 } 141 }
142 #endif // defined(OS_WIN) 142 #endif // defined(OS_WIN)
143 143
144 #if defined(OS_POSIX) 144 #if defined(OS_POSIX)
145 // Returns the maximum number of files that a process can have open.
146 // Returns 0 on error.
147 int GetMaxFilesOpenInProcess() {
148 struct rlimit rlim;
149 if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
150 return 0;
151 }
152
153 // rlim_t is a uint64 - clip to maxint. We do this since FD #s are ints
154 // which are all 32 bits on the supported platforms.
155 rlim_t max_int = static_cast<rlim_t>(std::numeric_limits<int32>::max());
156 if (rlim.rlim_cur > max_int) {
157 return max_int;
158 }
159
160 return rlim.rlim_cur;
161 }
162
145 const int kChildPipe = 20; // FD # for write end of pipe in child process. 163 const int kChildPipe = 20; // FD # for write end of pipe in child process.
146 MULTIPROCESS_TEST_MAIN(ProcessUtilsLeakFDChildProcess) { 164 MULTIPROCESS_TEST_MAIN(ProcessUtilsLeakFDChildProcess) {
147 // This child process counts the number of open FDs, it then writes that 165 // This child process counts the number of open FDs, it then writes that
148 // number out to a pipe connected to the parent. 166 // number out to a pipe connected to the parent.
149 int num_open_files = 0; 167 int num_open_files = 0;
150 int write_pipe = kChildPipe; 168 int write_pipe = kChildPipe;
151 int max_files = GetMaxFilesOpenInProcess(); 169 int max_files = GetMaxFilesOpenInProcess();
152 for (int i = STDERR_FILENO + 1; i < max_files; i++) { 170 for (int i = STDERR_FILENO + 1; i < max_files; i++) {
153 if (i != kChildPipe) { 171 if (i != kChildPipe) {
154 if (close(i) != -1) { 172 if (close(i) != -1) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 EXPECT_TRUE(WaitForSingleProcess(handle, 1000)); 223 EXPECT_TRUE(WaitForSingleProcess(handle, 1000));
206 close(fds[0]); 224 close(fds[0]);
207 close(sockets[0]); 225 close(sockets[0]);
208 close(sockets[1]); 226 close(sockets[1]);
209 close(dev_null); 227 close(dev_null);
210 } 228 }
211 229
212 #endif // defined(OS_POSIX) 230 #endif // defined(OS_POSIX)
213 231
214 } // namespace base 232 } // namespace base
OLDNEW
« no previous file with comments | « base/process_util_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698