OLD | NEW |
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> |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 | 870 |
871 // TODO(viettrungluu): Conceivably, we should have a timeout as well, so we | 871 // TODO(viettrungluu): Conceivably, we should have a timeout as well, so we |
872 // don't hang if what we're calling hangs. | 872 // don't hang if what we're calling hangs. |
873 bool GetAppOutputRestricted(const CommandLine& cl, | 873 bool GetAppOutputRestricted(const CommandLine& cl, |
874 std::string* output, size_t max_output) { | 874 std::string* output, size_t max_output) { |
875 // Run |execve()| with the empty environment. | 875 // Run |execve()| with the empty environment. |
876 char* const empty_environ = NULL; | 876 char* const empty_environ = NULL; |
877 return GetAppOutputInternal(cl, &empty_environ, output, max_output, false); | 877 return GetAppOutputInternal(cl, &empty_environ, output, max_output, false); |
878 } | 878 } |
879 | 879 |
880 bool WaitForProcessesToExit(const std::wstring& executable_name, | 880 bool WaitForProcessesToExit(const FilePath::StringType& executable_name, |
881 int64 wait_milliseconds, | 881 int64 wait_milliseconds, |
882 const ProcessFilter* filter) { | 882 const ProcessFilter* filter) { |
883 bool result = false; | 883 bool result = false; |
884 | 884 |
885 // TODO(port): This is inefficient, but works if there are multiple procs. | 885 // TODO(port): This is inefficient, but works if there are multiple procs. |
886 // TODO(port): use waitpid to avoid leaving zombies around | 886 // TODO(port): use waitpid to avoid leaving zombies around |
887 | 887 |
888 base::Time end_time = base::Time::Now() + | 888 base::Time end_time = base::Time::Now() + |
889 base::TimeDelta::FromMilliseconds(wait_milliseconds); | 889 base::TimeDelta::FromMilliseconds(wait_milliseconds); |
890 do { | 890 do { |
891 NamedProcessIterator iter(executable_name, filter); | 891 NamedProcessIterator iter(executable_name, filter); |
892 if (!iter.NextProcessEntry()) { | 892 if (!iter.NextProcessEntry()) { |
893 result = true; | 893 result = true; |
894 break; | 894 break; |
895 } | 895 } |
896 PlatformThread::Sleep(100); | 896 PlatformThread::Sleep(100); |
897 } while ((base::Time::Now() - end_time) > base::TimeDelta()); | 897 } while ((base::Time::Now() - end_time) > base::TimeDelta()); |
898 | 898 |
899 return result; | 899 return result; |
900 } | 900 } |
901 | 901 |
902 bool CleanupProcesses(const std::wstring& executable_name, | 902 bool CleanupProcesses(const FilePath::StringType& executable_name, |
903 int64 wait_milliseconds, | 903 int64 wait_milliseconds, |
904 int exit_code, | 904 int exit_code, |
905 const ProcessFilter* filter) { | 905 const ProcessFilter* filter) { |
906 bool exited_cleanly = | 906 bool exited_cleanly = |
907 WaitForProcessesToExit(executable_name, wait_milliseconds, | 907 WaitForProcessesToExit(executable_name, wait_milliseconds, |
908 filter); | 908 filter); |
909 if (!exited_cleanly) | 909 if (!exited_cleanly) |
910 KillProcesses(executable_name, exit_code, filter); | 910 KillProcesses(executable_name, exit_code, filter); |
911 return exited_cleanly; | 911 return exited_cleanly; |
912 } | 912 } |
913 | 913 |
914 } // namespace base | 914 } // namespace base |
OLD | NEW |