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

Side by Side Diff: base/process_util_posix.cc

Issue 6689014: GTTF: Detect browser crashes on shutdown in UI tests. (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
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;
729 if (WIFSIGNALED(status)) { 727 if (WIFSIGNALED(status)) {
730 *exit_code = -1; 728 *exit_code = -1;
731 return true; 729 return true;
732 } 730 }
733 *exit_code = WEXITSTATUS(status); 731 if (WIFEXITED(status)) {
734 return true; 732 *exit_code = WEXITSTATUS(status);
733 return true;
734 }
735 return false;
735 } 736 }
736 737
737 #if defined(OS_MACOSX) 738 #if defined(OS_MACOSX)
738 // Using kqueue on Mac so that we can wait on non-child processes. 739 // Using kqueue on Mac so that we can wait on non-child processes.
739 // We can't use kqueues on child processes because we need to reap 740 // We can't use kqueues on child processes because we need to reap
740 // our own children using wait. 741 // our own children using wait.
741 static bool WaitForSingleNonChildProcess(ProcessHandle handle, 742 static bool WaitForSingleNonChildProcess(ProcessHandle handle,
742 int64 wait_milliseconds) { 743 int64 wait_milliseconds) {
743 int kq = kqueue(); 744 int kq = kqueue();
744 if (kq == -1) { 745 if (kq == -1) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 else 815 else
815 status = WaitpidWithTimeout(handle, wait_milliseconds, &waitpid_success); 816 status = WaitpidWithTimeout(handle, wait_milliseconds, &waitpid_success);
816 if (status != -1) { 817 if (status != -1) {
817 DCHECK(waitpid_success); 818 DCHECK(waitpid_success);
818 return WIFEXITED(status); 819 return WIFEXITED(status);
819 } else { 820 } else {
820 return false; 821 return false;
821 } 822 }
822 } 823 }
823 824
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
837 int64 TimeValToMicroseconds(const struct timeval& tv) { 825 int64 TimeValToMicroseconds(const struct timeval& tv) {
838 static const int kMicrosecondsPerSecond = 1000000; 826 static const int kMicrosecondsPerSecond = 1000000;
839 int64 ret = tv.tv_sec; // Avoid (int * int) integer overflow. 827 int64 ret = tv.tv_sec; // Avoid (int * int) integer overflow.
840 ret *= kMicrosecondsPerSecond; 828 ret *= kMicrosecondsPerSecond;
841 ret += tv.tv_usec; 829 ret += tv.tv_usec;
842 return ret; 830 return ret;
843 } 831 }
844 832
845 // Executes the application specified by |cl| and wait for it to exit. Stores 833 // Executes the application specified by |cl| and wait for it to exit. Stores
846 // the output (stdout) in |output|. If |do_search_path| is set, it searches the 834 // 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
998 const ProcessFilter* filter) { 986 const ProcessFilter* filter) {
999 bool exited_cleanly = 987 bool exited_cleanly =
1000 WaitForProcessesToExit(executable_name, wait_milliseconds, 988 WaitForProcessesToExit(executable_name, wait_milliseconds,
1001 filter); 989 filter);
1002 if (!exited_cleanly) 990 if (!exited_cleanly)
1003 KillProcesses(executable_name, exit_code, filter); 991 KillProcesses(executable_name, exit_code, filter);
1004 return exited_cleanly; 992 return exited_cleanly;
1005 } 993 }
1006 994
1007 } // namespace base 995 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698