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_MACOS) | 8 #if defined(TARGET_OS_MACOS) |
9 | 9 |
10 #include "bin/process.h" | 10 #include "bin/process.h" |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 intptr_t* id, | 777 intptr_t* id, |
778 intptr_t* exit_event, | 778 intptr_t* exit_event, |
779 char** os_error_message) { | 779 char** os_error_message) { |
780 ProcessStarter starter(path, arguments, arguments_length, working_directory, | 780 ProcessStarter starter(path, arguments, arguments_length, working_directory, |
781 environment, environment_length, mode, in, out, err, | 781 environment, environment_length, mode, in, out, err, |
782 id, exit_event, os_error_message); | 782 id, exit_event, os_error_message); |
783 return starter.Start(); | 783 return starter.Start(); |
784 } | 784 } |
785 | 785 |
786 | 786 |
787 class BufferList : public BufferListBase { | |
788 public: | |
789 BufferList() {} | |
790 | |
791 bool Read(int fd, intptr_t available) { | |
792 // Read all available bytes. | |
793 while (available > 0) { | |
794 if (free_size_ == 0) { | |
795 Allocate(); | |
796 } | |
797 ASSERT(free_size_ > 0); | |
798 ASSERT(free_size_ <= kBufferSize); | |
799 size_t block_size = dart::Utils::Minimum(free_size_, available); | |
800 ssize_t bytes = TEMP_FAILURE_RETRY( | |
801 read(fd, reinterpret_cast<void*>(FreeSpaceAddress()), block_size)); | |
802 if (bytes < 0) { | |
803 return false; | |
804 } | |
805 data_size_ += bytes; | |
806 free_size_ -= bytes; | |
807 available -= bytes; | |
808 } | |
809 return true; | |
810 } | |
811 | |
812 private: | |
813 DISALLOW_COPY_AND_ASSIGN(BufferList); | |
814 }; | |
815 | |
816 | |
817 static bool CloseProcessBuffers(struct pollfd fds[3]) { | 787 static bool CloseProcessBuffers(struct pollfd fds[3]) { |
818 int e = errno; | 788 int e = errno; |
819 VOID_TEMP_FAILURE_RETRY(close(fds[0].fd)); | 789 VOID_TEMP_FAILURE_RETRY(close(fds[0].fd)); |
820 VOID_TEMP_FAILURE_RETRY(close(fds[1].fd)); | 790 VOID_TEMP_FAILURE_RETRY(close(fds[1].fd)); |
821 VOID_TEMP_FAILURE_RETRY(close(fds[2].fd)); | 791 VOID_TEMP_FAILURE_RETRY(close(fds[2].fd)); |
822 errno = e; | 792 errno = e; |
823 return false; | 793 return false; |
824 } | 794 } |
825 | 795 |
826 | 796 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 if (i < alive) { | 866 if (i < alive) { |
897 fds[i] = fds[alive]; | 867 fds[i] = fds[alive]; |
898 } | 868 } |
899 } | 869 } |
900 } | 870 } |
901 } | 871 } |
902 | 872 |
903 // All handles closed and all data read. | 873 // All handles closed and all data read. |
904 result->set_stdout_data(out_data.GetData()); | 874 result->set_stdout_data(out_data.GetData()); |
905 result->set_stderr_data(err_data.GetData()); | 875 result->set_stderr_data(err_data.GetData()); |
| 876 DEBUG_ASSERT(out_data.IsEmpty()); |
| 877 DEBUG_ASSERT(err_data.IsEmpty()); |
906 | 878 |
907 // Calculate the exit code. | 879 // Calculate the exit code. |
908 intptr_t exit_code = exit_code_data.ints[0]; | 880 intptr_t exit_code = exit_code_data.ints[0]; |
909 intptr_t negative = exit_code_data.ints[1]; | 881 intptr_t negative = exit_code_data.ints[1]; |
910 if (negative != 0) { | 882 if (negative != 0) { |
911 exit_code = -exit_code; | 883 exit_code = -exit_code; |
912 } | 884 } |
913 result->set_exit_code(exit_code); | 885 result->set_exit_code(exit_code); |
914 | 886 |
915 return true; | 887 return true; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); | 1086 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); |
1115 } | 1087 } |
1116 } | 1088 } |
1117 | 1089 |
1118 } // namespace bin | 1090 } // namespace bin |
1119 } // namespace dart | 1091 } // namespace dart |
1120 | 1092 |
1121 #endif // defined(TARGET_OS_MACOS) | 1093 #endif // defined(TARGET_OS_MACOS) |
1122 | 1094 |
1123 #endif // !defined(DART_IO_DISABLED) | 1095 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |