summaryrefslogtreecommitdiffstats
path: root/base/process_util_posix.cc
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-17 22:41:50 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-17 22:41:50 +0000
commitfa3097a6a5ec6c6e7c092a6339c283dc34d42ca7 (patch)
tree7fc997f0a3cb9ce2aca5411e43c1987e6618b7d1 /base/process_util_posix.cc
parent6f666448fe72b6f98a241cb9d83a2a15aa4ff24e (diff)
downloadchromium_src-fa3097a6a5ec6c6e7c092a6339c283dc34d42ca7.zip
chromium_src-fa3097a6a5ec6c6e7c092a6339c283dc34d42ca7.tar.gz
chromium_src-fa3097a6a5ec6c6e7c092a6339c283dc34d42ca7.tar.bz2
* On POSIX, make sure we don't leak FDs when launching child Processes.
* Add a facility to LaunchProcess() to remap a given FD into a child process. This change is needed for 2 reasons: 1)We want to use a socketpair() for IPC, the child process needs a known FD # for it's side of the socket. 2)The OS X Sandbox doesn't close FDs. Review URL: http://codereview.chromium.org/14497 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7175 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_posix.cc')
-rw-r--r--base/process_util_posix.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc
index 3153a59..2cfa6f9 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) {