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

Side by Side Diff: base/process_util_posix.cc

Issue 183016: Port some of the base module to FreeBSD. Extracted from... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Minor edits Created 11 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « base/process_util.h ('k') | base/sys_info_posix.cc » ('j') | 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 #include <dirent.h> 5 #include <dirent.h>
6 #include <errno.h> 6 #include <errno.h>
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <signal.h> 8 #include <signal.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <sys/resource.h> 10 #include <sys/resource.h>
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 }; 110 };
111 typedef scoped_ptr_malloc<DIR, ScopedDIRClose> ScopedDIR; 111 typedef scoped_ptr_malloc<DIR, ScopedDIRClose> ScopedDIR;
112 112
113 void CloseSuperfluousFds(const base::InjectiveMultimap& saved_mapping) { 113 void CloseSuperfluousFds(const base::InjectiveMultimap& saved_mapping) {
114 #if defined(OS_LINUX) 114 #if defined(OS_LINUX)
115 static const rlim_t kSystemDefaultMaxFds = 8192; 115 static const rlim_t kSystemDefaultMaxFds = 8192;
116 static const char fd_dir[] = "/proc/self/fd"; 116 static const char fd_dir[] = "/proc/self/fd";
117 #elif defined(OS_MACOSX) 117 #elif defined(OS_MACOSX)
118 static const rlim_t kSystemDefaultMaxFds = 256; 118 static const rlim_t kSystemDefaultMaxFds = 256;
119 static const char fd_dir[] = "/dev/fd"; 119 static const char fd_dir[] = "/dev/fd";
120 #elif defined(OS_FREEBSD)
121 static const rlim_t kSystemDefaultMaxFds = 8192;
122 static const char fd_dir[] = "/dev/fd";
120 #endif 123 #endif
121 std::set<int> saved_fds; 124 std::set<int> saved_fds;
122 125
123 // Get the maximum number of FDs possible. 126 // Get the maximum number of FDs possible.
124 struct rlimit nofile; 127 struct rlimit nofile;
125 rlim_t max_fds; 128 rlim_t max_fds;
126 if (getrlimit(RLIMIT_NOFILE, &nofile)) { 129 if (getrlimit(RLIMIT_NOFILE, &nofile)) {
127 // getrlimit failed. Take a best guess. 130 // getrlimit failed. Take a best guess.
128 max_fds = kSystemDefaultMaxFds; 131 max_fds = kSystemDefaultMaxFds;
129 DLOG(ERROR) << "getrlimit(RLIMIT_NOFILE) failed: " << errno; 132 DLOG(ERROR) << "getrlimit(RLIMIT_NOFILE) failed: " << errno;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 189 }
187 } 190 }
188 191
189 // Sets all file descriptors to close on exec except for stdin, stdout 192 // Sets all file descriptors to close on exec except for stdin, stdout
190 // and stderr. 193 // and stderr.
191 // TODO(agl): Remove this function. It's fundamentally broken for multithreaded 194 // TODO(agl): Remove this function. It's fundamentally broken for multithreaded
192 // apps. 195 // apps.
193 void SetAllFDsToCloseOnExec() { 196 void SetAllFDsToCloseOnExec() {
194 #if defined(OS_LINUX) 197 #if defined(OS_LINUX)
195 const char fd_dir[] = "/proc/self/fd"; 198 const char fd_dir[] = "/proc/self/fd";
196 #elif defined(OS_MACOSX) 199 #elif defined(OS_MACOSX) || defined(OS_FREEBSD)
197 const char fd_dir[] = "/dev/fd"; 200 const char fd_dir[] = "/dev/fd";
198 #endif 201 #endif
199 ScopedDIR dir_closer(opendir(fd_dir)); 202 ScopedDIR dir_closer(opendir(fd_dir));
200 DIR *dir = dir_closer.get(); 203 DIR *dir = dir_closer.get();
201 if (NULL == dir) { 204 if (NULL == dir) {
202 DLOG(ERROR) << "Unable to open " << fd_dir; 205 DLOG(ERROR) << "Unable to open " << fd_dir;
203 return; 206 return;
204 } 207 }
205 208
206 struct dirent *ent; 209 struct dirent *ent;
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 const ProcessFilter* filter) { 627 const ProcessFilter* filter) {
625 bool exited_cleanly = 628 bool exited_cleanly =
626 WaitForProcessesToExit(executable_name, wait_milliseconds, 629 WaitForProcessesToExit(executable_name, wait_milliseconds,
627 filter); 630 filter);
628 if (!exited_cleanly) 631 if (!exited_cleanly)
629 KillProcesses(executable_name, exit_code, filter); 632 KillProcesses(executable_name, exit_code, filter);
630 return exited_cleanly; 633 return exited_cleanly;
631 } 634 }
632 635
633 } // namespace base 636 } // namespace base
OLDNEW
« no previous file with comments | « base/process_util.h ('k') | base/sys_info_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698