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

Unified Diff: base/process_util_posix.cc

Issue 14497: POSIX: don't leak FDs when launching child Processes. (Closed)
Patch Set: Fix Windows Compilation Created 12 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process_util_mac.mm ('k') | base/process_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process_util_posix.cc
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc
index 3153a59aa0fce1c877cceb3754b680523a8aa79e..2cfa6f9a4c2ca000cd5839abfbda8d285694d650 100644
--- a/base/process_util_posix.cc
+++ b/base/process_util_posix.cc
@@ -9,6 +9,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
+#include <limits>
#include "base/basictypes.h"
#include "base/logging.h"
@@ -31,6 +32,23 @@ int GetProcId(ProcessHandle process) {
return process;
}
+int GetMaxFilesOpenInProcess() {
+ struct rlimit rlimit;
+ if (getrlimit(RLIMIT_NOFILE, &rlimit) != 0) {
+ return 0;
+ }
+
+ // rlim_t is a uint64 - clip to maxint.
+ // We do this since we use the value of this function to close FD #s in a loop
+ // if we didn't clamp the value, doing this would be too time consuming.
+ rlim_t max_int = static_cast<rlim_t>(std::numeric_limits<int32>::max());
+ if (rlimit.rlim_cur > max_int) {
+ return max_int;
+ }
+
+ return rlimit.rlim_cur;
+}
+
ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process),
last_time_(0),
last_system_time_(0) {
« no previous file with comments | « base/process_util_mac.mm ('k') | base/process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698