OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "bin/process.h" | 7 #include "bin/process.h" |
8 | 8 |
9 #include "bin/dartutils.h" | 9 #include "bin/dartutils.h" |
10 #include "bin/io_buffer.h" | 10 #include "bin/io_buffer.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 if (Dart_IsError(result)) { | 65 if (Dart_IsError(result)) { |
66 Dart_PropagateError(result); | 66 Dart_PropagateError(result); |
67 } | 67 } |
68 return NULL; | 68 return NULL; |
69 } | 69 } |
70 string_args[i] = const_cast<char*>(DartUtils::GetStringValue(arg)); | 70 string_args[i] = const_cast<char*>(DartUtils::GetStringValue(arg)); |
71 } | 71 } |
72 return string_args; | 72 return string_args; |
73 } | 73 } |
74 | 74 |
| 75 |
| 76 void Process::ClearAllSignalHandlers() { |
| 77 for (intptr_t i = 1; i <= kLastSignal; i++) { |
| 78 ClearSignalHandler(i); |
| 79 } |
| 80 } |
| 81 |
| 82 |
75 void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) { | 83 void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) { |
76 Dart_Handle process = Dart_GetNativeArgument(args, 0); | 84 Dart_Handle process = Dart_GetNativeArgument(args, 0); |
77 intptr_t process_stdin; | 85 intptr_t process_stdin; |
78 intptr_t process_stdout; | 86 intptr_t process_stdout; |
79 intptr_t process_stderr; | 87 intptr_t process_stderr; |
80 intptr_t exit_event; | 88 intptr_t exit_event; |
81 Dart_Handle result; | 89 Dart_Handle result; |
82 Dart_Handle status_handle = Dart_GetNativeArgument(args, 10); | 90 Dart_Handle status_handle = Dart_GetNativeArgument(args, 10); |
83 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1); | 91 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1); |
84 // The Dart code verifies that the path implements the String | 92 // The Dart code verifies that the path implements the String |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 9); | 154 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 9); |
147 intptr_t pid = -1; | 155 intptr_t pid = -1; |
148 char* os_error_message = NULL; // Scope allocated by Process::Start. | 156 char* os_error_message = NULL; // Scope allocated by Process::Start. |
149 | 157 |
150 int error_code = Process::Start( | 158 int error_code = Process::Start( |
151 path, string_args, args_length, working_directory, string_environment, | 159 path, string_args, args_length, working_directory, string_environment, |
152 environment_length, static_cast<ProcessStartMode>(mode), &process_stdout, | 160 environment_length, static_cast<ProcessStartMode>(mode), &process_stdout, |
153 &process_stdin, &process_stderr, &pid, &exit_event, &os_error_message); | 161 &process_stdin, &process_stderr, &pid, &exit_event, &os_error_message); |
154 if (error_code == 0) { | 162 if (error_code == 0) { |
155 if (mode != kDetached) { | 163 if (mode != kDetached) { |
156 Socket::SetSocketIdNativeField(stdin_handle, process_stdin); | 164 Socket::SetSocketIdNativeField(stdin_handle, process_stdin, false); |
157 Socket::SetSocketIdNativeField(stdout_handle, process_stdout); | 165 Socket::SetSocketIdNativeField(stdout_handle, process_stdout, false); |
158 Socket::SetSocketIdNativeField(stderr_handle, process_stderr); | 166 Socket::SetSocketIdNativeField(stderr_handle, process_stderr, false); |
159 } | 167 } |
160 if (mode == kNormal) { | 168 if (mode == kNormal) { |
161 Socket::SetSocketIdNativeField(exit_handle, exit_event); | 169 Socket::SetSocketIdNativeField(exit_handle, exit_event, false); |
162 } | 170 } |
163 Process::SetProcessIdNativeField(process, pid); | 171 Process::SetProcessIdNativeField(process, pid); |
164 } else { | 172 } else { |
165 result = | 173 result = |
166 DartUtils::SetIntegerField(status_handle, "_errorCode", error_code); | 174 DartUtils::SetIntegerField(status_handle, "_errorCode", error_code); |
167 if (Dart_IsError(result)) { | 175 if (Dart_IsError(result)) { |
168 Dart_PropagateError(result); | 176 Dart_PropagateError(result); |
169 } | 177 } |
170 result = DartUtils::SetStringField(status_handle, "_errorMessage", | 178 result = DartUtils::SetStringField(status_handle, "_errorMessage", |
171 os_error_message != NULL | 179 os_error_message != NULL |
172 ? os_error_message | 180 ? os_error_message |
173 : "Cannot get error message"); | 181 : "Cannot get error message"); |
174 if (Dart_IsError(result)) { | 182 if (Dart_IsError(result)) { |
175 Dart_PropagateError(result); | 183 Dart_PropagateError(result); |
176 } | 184 } |
177 } | 185 } |
178 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); | 186 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); |
179 } | 187 } |
180 | 188 |
181 | 189 |
182 void FUNCTION_NAME(Process_Wait)(Dart_NativeArguments args) { | 190 void FUNCTION_NAME(Process_Wait)(Dart_NativeArguments args) { |
183 Dart_Handle process = Dart_GetNativeArgument(args, 0); | 191 Dart_Handle process = Dart_GetNativeArgument(args, 0); |
184 intptr_t process_stdin = | 192 Socket* process_stdin = |
185 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 1)); | 193 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 1)); |
186 intptr_t process_stdout = | 194 Socket* process_stdout = |
187 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 2)); | 195 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 2)); |
188 intptr_t process_stderr = | 196 Socket* process_stderr = |
189 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 3)); | 197 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 3)); |
190 intptr_t exit_event = | 198 Socket* exit_event = |
191 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 4)); | 199 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 4)); |
192 ProcessResult result; | 200 ProcessResult result; |
193 intptr_t pid; | 201 intptr_t pid; |
194 Process::GetProcessIdNativeField(process, &pid); | 202 Process::GetProcessIdNativeField(process, &pid); |
195 if (Process::Wait(pid, process_stdin, process_stdout, process_stderr, | 203 bool success = Process::Wait(pid, process_stdin->fd(), process_stdout->fd(), |
196 exit_event, &result)) { | 204 process_stderr->fd(), exit_event->fd(), &result); |
| 205 // Process::Wait() closes the file handles, so blow away the fds in the |
| 206 // Sockets so that they don't get picked up by the finalizer on _NativeSocket. |
| 207 process_stdin->SetClosedFd(); |
| 208 process_stdout->SetClosedFd(); |
| 209 process_stderr->SetClosedFd(); |
| 210 exit_event->SetClosedFd(); |
| 211 if (success) { |
197 Dart_Handle out = result.stdout_data(); | 212 Dart_Handle out = result.stdout_data(); |
198 if (Dart_IsError(out)) { | 213 if (Dart_IsError(out)) { |
199 Dart_PropagateError(out); | 214 Dart_PropagateError(out); |
200 } | 215 } |
201 Dart_Handle err = result.stderr_data(); | 216 Dart_Handle err = result.stderr_data(); |
202 if (Dart_IsError(err)) { | 217 if (Dart_IsError(err)) { |
203 Dart_PropagateError(err); | 218 Dart_PropagateError(err); |
204 } | 219 } |
205 Dart_Handle list = Dart_NewList(4); | 220 Dart_Handle list = Dart_NewList(4); |
206 Dart_ListSetAt(list, 0, Dart_NewInteger(pid)); | 221 Dart_ListSetAt(list, 0, Dart_NewInteger(pid)); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 if (!Dart_IsError(external_array)) { | 359 if (!Dart_IsError(external_array)) { |
345 memmove(buffer, system_string, system_len); | 360 memmove(buffer, system_string, system_len); |
346 } | 361 } |
347 Dart_SetReturnValue(args, external_array); | 362 Dart_SetReturnValue(args, external_array); |
348 } | 363 } |
349 | 364 |
350 } // namespace bin | 365 } // namespace bin |
351 } // namespace dart | 366 } // namespace dart |
352 | 367 |
353 #endif // !defined(DART_IO_DISABLED) | 368 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |