OLD | NEW |
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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 if (pipe(pipe_fd) < 0) | 434 if (pipe(pipe_fd) < 0) |
435 return false; | 435 return false; |
436 | 436 |
437 switch (pid = fork()) { | 437 switch (pid = fork()) { |
438 case -1: // error | 438 case -1: // error |
439 close(pipe_fd[0]); | 439 close(pipe_fd[0]); |
440 close(pipe_fd[1]); | 440 close(pipe_fd[1]); |
441 return false; | 441 return false; |
442 case 0: // child | 442 case 0: // child |
443 { | 443 { |
| 444 // Obscure fork() rule: in the child, if you don't end up doing exec*(), |
| 445 // you call _exit() instead of exit(). This is because _exit() does not |
| 446 // call any previously-registered (in the parent) exit handlers, which |
| 447 // might do things like block waiting for threads that don't even exist |
| 448 // in the child. |
444 int dev_null = open("/dev/null", O_WRONLY); | 449 int dev_null = open("/dev/null", O_WRONLY); |
445 if (dev_null < 0) | 450 if (dev_null < 0) |
446 _exit(127); | 451 _exit(127); |
447 | 452 |
448 InjectiveMultimap fd_shuffle; | 453 InjectiveMultimap fd_shuffle; |
449 fd_shuffle.push_back(InjectionArc(pipe_fd[1], STDOUT_FILENO, true)); | 454 fd_shuffle.push_back(InjectionArc(pipe_fd[1], STDOUT_FILENO, true)); |
450 fd_shuffle.push_back(InjectionArc(dev_null, STDERR_FILENO, true)); | 455 fd_shuffle.push_back(InjectionArc(dev_null, STDERR_FILENO, true)); |
451 fd_shuffle.push_back(InjectionArc(dev_null, STDIN_FILENO, true)); | 456 fd_shuffle.push_back(InjectionArc(dev_null, STDIN_FILENO, true)); |
452 | 457 |
453 if (!ShuffleFileDescriptors(fd_shuffle)) | 458 if (!ShuffleFileDescriptors(fd_shuffle)) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 const ProcessFilter* filter) { | 548 const ProcessFilter* filter) { |
544 bool exited_cleanly = | 549 bool exited_cleanly = |
545 WaitForProcessesToExit(executable_name, wait_milliseconds, | 550 WaitForProcessesToExit(executable_name, wait_milliseconds, |
546 filter); | 551 filter); |
547 if (!exited_cleanly) | 552 if (!exited_cleanly) |
548 KillProcesses(executable_name, exit_code, filter); | 553 KillProcesses(executable_name, exit_code, filter); |
549 return exited_cleanly; | 554 return exited_cleanly; |
550 } | 555 } |
551 | 556 |
552 } // namespace base | 557 } // namespace base |
OLD | NEW |