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

Side by Side Diff: base/process_util_posix.cc

Issue 3119022: Header cleanup in base.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 4 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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>
11 #include <sys/time.h> 11 #include <sys/time.h>
12 #include <sys/types.h> 12 #include <sys/types.h>
13 #include <sys/wait.h> 13 #include <sys/wait.h>
14 #include <unistd.h> 14 #include <unistd.h>
15 15
16 #include <limits> 16 #include <limits>
17 #include <set> 17 #include <set>
18 18
19 #include "base/command_line.h" 19 #include "base/command_line.h"
20 #include "base/compiler_specific.h" 20 #include "base/compiler_specific.h"
21 #include "base/debug_util.h" 21 #include "base/debug_util.h"
22 #include "base/dir_reader_posix.h" 22 #include "base/dir_reader_posix.h"
23 #include "base/eintr_wrapper.h" 23 #include "base/eintr_wrapper.h"
24 #include "base/logging.h" 24 #include "base/logging.h"
25 #include "base/platform_thread.h" 25 #include "base/platform_thread.h"
26 #include "base/process_util.h" 26 #include "base/process_util.h"
27 #include "base/scoped_ptr.h" 27 #include "base/scoped_ptr.h"
28 #include "base/string_util.h" 28 #include "base/stringprintf.h"
29 #include "base/time.h" 29 #include "base/time.h"
30 #include "base/waitable_event.h" 30 #include "base/waitable_event.h"
31 31
32 #if defined(OS_MACOSX) 32 #if defined(OS_MACOSX)
33 #include <crt_externs.h> 33 #include <crt_externs.h>
34 #define environ (*_NSGetEnviron()) 34 #define environ (*_NSGetEnviron())
35 #include "base/mach_ipc_mac.h" 35 #include "base/mach_ipc_mac.h"
36 #include "base/rand_util.h" 36 #include "base/rand_util.h"
37 #else 37 #else
38 extern char** environ; 38 extern char** environ;
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // before closing. See https://bugs.kde.org/show_bug.cgi?id=191758 287 // before closing. See https://bugs.kde.org/show_bug.cgi?id=191758
288 if (fd < static_cast<int>(max_fds)) { 288 if (fd < static_cast<int>(max_fds)) {
289 int ret = HANDLE_EINTR(close(fd)); 289 int ret = HANDLE_EINTR(close(fd));
290 DPCHECK(ret == 0); 290 DPCHECK(ret == 0);
291 } 291 }
292 } 292 }
293 } 293 }
294 294
295 #if defined(OS_MACOSX) 295 #if defined(OS_MACOSX)
296 static std::string MachErrorCode(kern_return_t err) { 296 static std::string MachErrorCode(kern_return_t err) {
297 return StringPrintf("0x%x %s", err, mach_error_string(err)); 297 return StringPrintf("0x%x %s", err, mach_error_string(err));
viettrungluu 2010/08/17 05:09:15 base::?
298 } 298 }
299 299
300 // Forks the current process and returns the child's |task_t| in the parent 300 // Forks the current process and returns the child's |task_t| in the parent
301 // process. 301 // process.
302 static pid_t fork_and_get_task(task_t* child_task) { 302 static pid_t fork_and_get_task(task_t* child_task) {
303 const int kTimeoutMs = 100; 303 const int kTimeoutMs = 100;
304 kern_return_t err; 304 kern_return_t err;
305 305
306 // Put a random number into the channel name, so that a compromised renderer 306 // Put a random number into the channel name, so that a compromised renderer
307 // can't pretend being the child that's forked off. 307 // can't pretend being the child that's forked off.
308 std::string mach_connection_name = StringPrintf( 308 std::string mach_connection_name = StringPrintf(
viettrungluu 2010/08/17 05:09:15 "
309 "com.google.Chrome.samplingfork.%p.%d", 309 "com.google.Chrome.samplingfork.%p.%d",
310 child_task, base::RandInt(0, std::numeric_limits<int>::max())); 310 child_task, base::RandInt(0, std::numeric_limits<int>::max()));
311 ReceivePort parent_recv_port(mach_connection_name.c_str()); 311 ReceivePort parent_recv_port(mach_connection_name.c_str());
312 312
313 // Error handling philosophy: If Mach IPC fails, don't touch |child_task| but 313 // Error handling philosophy: If Mach IPC fails, don't touch |child_task| but
314 // return a valid pid. If IPC fails in the child, the parent will have to wait 314 // return a valid pid. If IPC fails in the child, the parent will have to wait
315 // until kTimeoutMs is over. This is not optimal, but I've never seen it 315 // until kTimeoutMs is over. This is not optimal, but I've never seen it
316 // happen, and stuff should still mostly work. 316 // happen, and stuff should still mostly work.
317 pid_t pid = fork(); 317 pid_t pid = fork();
318 switch (pid) { 318 switch (pid) {
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 const ProcessFilter* filter) { 896 const ProcessFilter* filter) {
897 bool exited_cleanly = 897 bool exited_cleanly =
898 WaitForProcessesToExit(executable_name, wait_milliseconds, 898 WaitForProcessesToExit(executable_name, wait_milliseconds,
899 filter); 899 filter);
900 if (!exited_cleanly) 900 if (!exited_cleanly)
901 KillProcesses(executable_name, exit_code, filter); 901 KillProcesses(executable_name, exit_code, filter);
902 return exited_cleanly; 902 return exited_cleanly;
903 } 903 }
904 904
905 } // namespace base 905 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698