| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
| 6 | 6 |
| 7 #include "platform/globals.h" | 7 #include "platform/globals.h" |
| 8 #if defined(TARGET_OS_ANDROID) | 8 #if defined(TARGET_OS_ANDROID) |
| 9 | 9 |
| 10 #include "bin/process.h" | 10 #include "bin/process.h" |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 intptr_t* id, | 761 intptr_t* id, |
| 762 intptr_t* exit_event, | 762 intptr_t* exit_event, |
| 763 char** os_error_message) { | 763 char** os_error_message) { |
| 764 ProcessStarter starter(path, arguments, arguments_length, working_directory, | 764 ProcessStarter starter(path, arguments, arguments_length, working_directory, |
| 765 environment, environment_length, mode, in, out, err, | 765 environment, environment_length, mode, in, out, err, |
| 766 id, exit_event, os_error_message); | 766 id, exit_event, os_error_message); |
| 767 return starter.Start(); | 767 return starter.Start(); |
| 768 } | 768 } |
| 769 | 769 |
| 770 | 770 |
| 771 class BufferList : public BufferListBase { | |
| 772 public: | |
| 773 BufferList() {} | |
| 774 | |
| 775 bool Read(int fd, intptr_t available) { | |
| 776 // Read all available bytes. | |
| 777 while (available > 0) { | |
| 778 if (free_size_ == 0) { | |
| 779 Allocate(); | |
| 780 } | |
| 781 ASSERT(free_size_ > 0); | |
| 782 ASSERT(free_size_ <= kBufferSize); | |
| 783 intptr_t block_size = dart::Utils::Minimum(free_size_, available); | |
| 784 intptr_t bytes = TEMP_FAILURE_RETRY( | |
| 785 read(fd, reinterpret_cast<void*>(FreeSpaceAddress()), block_size)); | |
| 786 if (bytes < 0) { | |
| 787 return false; | |
| 788 } | |
| 789 data_size_ += bytes; | |
| 790 free_size_ -= bytes; | |
| 791 available -= bytes; | |
| 792 } | |
| 793 return true; | |
| 794 } | |
| 795 | |
| 796 private: | |
| 797 DISALLOW_COPY_AND_ASSIGN(BufferList); | |
| 798 }; | |
| 799 | |
| 800 | |
| 801 static bool CloseProcessBuffers(struct pollfd fds[3]) { | 771 static bool CloseProcessBuffers(struct pollfd fds[3]) { |
| 802 int e = errno; | 772 int e = errno; |
| 803 VOID_TEMP_FAILURE_RETRY(close(fds[0].fd)); | 773 VOID_TEMP_FAILURE_RETRY(close(fds[0].fd)); |
| 804 VOID_TEMP_FAILURE_RETRY(close(fds[1].fd)); | 774 VOID_TEMP_FAILURE_RETRY(close(fds[1].fd)); |
| 805 VOID_TEMP_FAILURE_RETRY(close(fds[2].fd)); | 775 VOID_TEMP_FAILURE_RETRY(close(fds[2].fd)); |
| 806 errno = e; | 776 errno = e; |
| 807 return false; | 777 return false; |
| 808 } | 778 } |
| 809 | 779 |
| 810 | 780 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 if (i < alive) { | 844 if (i < alive) { |
| 875 fds[i] = fds[alive]; | 845 fds[i] = fds[alive]; |
| 876 } | 846 } |
| 877 } | 847 } |
| 878 } | 848 } |
| 879 } | 849 } |
| 880 | 850 |
| 881 // All handles closed and all data read. | 851 // All handles closed and all data read. |
| 882 result->set_stdout_data(out_data.GetData()); | 852 result->set_stdout_data(out_data.GetData()); |
| 883 result->set_stderr_data(err_data.GetData()); | 853 result->set_stderr_data(err_data.GetData()); |
| 854 DEBUG_ASSERT(out_data.IsEmpty()); |
| 855 DEBUG_ASSERT(err_data.IsEmpty()); |
| 884 | 856 |
| 885 // Calculate the exit code. | 857 // Calculate the exit code. |
| 886 intptr_t exit_code = exit_code_data.ints[0]; | 858 intptr_t exit_code = exit_code_data.ints[0]; |
| 887 intptr_t negative = exit_code_data.ints[1]; | 859 intptr_t negative = exit_code_data.ints[1]; |
| 888 if (negative != 0) { | 860 if (negative != 0) { |
| 889 exit_code = -exit_code; | 861 exit_code = -exit_code; |
| 890 } | 862 } |
| 891 result->set_exit_code(exit_code); | 863 result->set_exit_code(exit_code); |
| 892 | 864 |
| 893 return true; | 865 return true; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); | 990 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); |
| 1019 } | 991 } |
| 1020 } | 992 } |
| 1021 | 993 |
| 1022 } // namespace bin | 994 } // namespace bin |
| 1023 } // namespace dart | 995 } // namespace dart |
| 1024 | 996 |
| 1025 #endif // defined(TARGET_OS_ANDROID) | 997 #endif // defined(TARGET_OS_ANDROID) |
| 1026 | 998 |
| 1027 #endif // !defined(DART_IO_DISABLED) | 999 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |