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

Side by Side Diff: base/process_util_posix.cc

Issue 6794056: Revert 80472 - GTTF: Detect browser crashes on shutdown in UI tests.Previously the automation fra... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 8 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/process_util_win.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 717
718 bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code, 718 bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code,
719 int64 timeout_milliseconds) { 719 int64 timeout_milliseconds) {
720 bool waitpid_success = false; 720 bool waitpid_success = false;
721 int status = WaitpidWithTimeout(handle, timeout_milliseconds, 721 int status = WaitpidWithTimeout(handle, timeout_milliseconds,
722 &waitpid_success); 722 &waitpid_success);
723 if (status == -1) 723 if (status == -1)
724 return false; 724 return false;
725 if (!waitpid_success) 725 if (!waitpid_success)
726 return false; 726 return false;
727 if (!WIFEXITED(status))
728 return false;
727 if (WIFSIGNALED(status)) { 729 if (WIFSIGNALED(status)) {
728 *exit_code = -1; 730 *exit_code = -1;
729 return true; 731 return true;
730 } 732 }
731 if (WIFEXITED(status)) { 733 *exit_code = WEXITSTATUS(status);
732 *exit_code = WEXITSTATUS(status); 734 return true;
733 return true;
734 }
735 return false;
736 } 735 }
737 736
738 #if defined(OS_MACOSX) 737 #if defined(OS_MACOSX)
739 // Using kqueue on Mac so that we can wait on non-child processes. 738 // Using kqueue on Mac so that we can wait on non-child processes.
740 // We can't use kqueues on child processes because we need to reap 739 // We can't use kqueues on child processes because we need to reap
741 // our own children using wait. 740 // our own children using wait.
742 static bool WaitForSingleNonChildProcess(ProcessHandle handle, 741 static bool WaitForSingleNonChildProcess(ProcessHandle handle,
743 int64 wait_milliseconds) { 742 int64 wait_milliseconds) {
744 int kq = kqueue(); 743 int kq = kqueue();
745 if (kq == -1) { 744 if (kq == -1) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 else 814 else
816 status = WaitpidWithTimeout(handle, wait_milliseconds, &waitpid_success); 815 status = WaitpidWithTimeout(handle, wait_milliseconds, &waitpid_success);
817 if (status != -1) { 816 if (status != -1) {
818 DCHECK(waitpid_success); 817 DCHECK(waitpid_success);
819 return WIFEXITED(status); 818 return WIFEXITED(status);
820 } else { 819 } else {
821 return false; 820 return false;
822 } 821 }
823 } 822 }
824 823
824 bool CrashAwareSleep(ProcessHandle handle, int64 wait_milliseconds) {
825 bool waitpid_success;
826 int status = WaitpidWithTimeout(handle, wait_milliseconds, &waitpid_success);
827 if (status != -1) {
828 DCHECK(waitpid_success);
829 return !(WIFEXITED(status) || WIFSIGNALED(status));
830 } else {
831 // If waitpid returned with an error, then the process doesn't exist
832 // (which most probably means it didn't exist before our call).
833 return waitpid_success;
834 }
835 }
836
825 int64 TimeValToMicroseconds(const struct timeval& tv) { 837 int64 TimeValToMicroseconds(const struct timeval& tv) {
826 static const int kMicrosecondsPerSecond = 1000000; 838 static const int kMicrosecondsPerSecond = 1000000;
827 int64 ret = tv.tv_sec; // Avoid (int * int) integer overflow. 839 int64 ret = tv.tv_sec; // Avoid (int * int) integer overflow.
828 ret *= kMicrosecondsPerSecond; 840 ret *= kMicrosecondsPerSecond;
829 ret += tv.tv_usec; 841 ret += tv.tv_usec;
830 return ret; 842 return ret;
831 } 843 }
832 844
833 // Executes the application specified by |cl| and wait for it to exit. Stores 845 // Executes the application specified by |cl| and wait for it to exit. Stores
834 // the output (stdout) in |output|. If |do_search_path| is set, it searches the 846 // the output (stdout) in |output|. If |do_search_path| is set, it searches the
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 const ProcessFilter* filter) { 998 const ProcessFilter* filter) {
987 bool exited_cleanly = 999 bool exited_cleanly =
988 WaitForProcessesToExit(executable_name, wait_milliseconds, 1000 WaitForProcessesToExit(executable_name, wait_milliseconds,
989 filter); 1001 filter);
990 if (!exited_cleanly) 1002 if (!exited_cleanly)
991 KillProcesses(executable_name, exit_code, filter); 1003 KillProcesses(executable_name, exit_code, filter);
992 return exited_cleanly; 1004 return exited_cleanly;
993 } 1005 }
994 1006
995 } // namespace base 1007 } // namespace base
OLDNEW
« no previous file with comments | « base/process_util.h ('k') | base/process_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698