| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #include "bin/process.h" | 5 #include "bin/process.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <signal.h> | 9 #include <signal.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 exec_control_fd, os_error_message, strlen(os_error_message) + 1); | 126 exec_control_fd, os_error_message, strlen(os_error_message) + 1); |
| 127 } | 127 } |
| 128 close(exec_control_fd); | 128 close(exec_control_fd); |
| 129 exit(1); | 129 exit(1); |
| 130 } | 130 } |
| 131 | 131 |
| 132 | 132 |
| 133 int Process::Start(const char* path, | 133 int Process::Start(const char* path, |
| 134 char* arguments[], | 134 char* arguments[], |
| 135 intptr_t arguments_length, | 135 intptr_t arguments_length, |
| 136 const char* working_directory, |
| 136 intptr_t* in, | 137 intptr_t* in, |
| 137 intptr_t* out, | 138 intptr_t* out, |
| 138 intptr_t* err, | 139 intptr_t* err, |
| 139 intptr_t* id, | 140 intptr_t* id, |
| 140 intptr_t* exit_event, | 141 intptr_t* exit_event, |
| 141 char* os_error_message, | 142 char* os_error_message, |
| 142 int os_error_message_len) { | 143 int os_error_message_len) { |
| 143 pid_t pid; | 144 pid_t pid; |
| 144 int read_in[2]; // Pipe for stdout to child process. | 145 int read_in[2]; // Pipe for stdout to child process. |
| 145 int read_err[2]; // Pipe for stderr to child process. | 146 int read_err[2]; // Pipe for stderr to child process. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 if (dup2(read_in[1], STDOUT_FILENO) == -1) { | 254 if (dup2(read_in[1], STDOUT_FILENO) == -1) { |
| 254 ReportChildError(exec_control[1]); | 255 ReportChildError(exec_control[1]); |
| 255 } | 256 } |
| 256 close(read_in[1]); | 257 close(read_in[1]); |
| 257 | 258 |
| 258 if (dup2(read_err[1], STDERR_FILENO) == -1) { | 259 if (dup2(read_err[1], STDERR_FILENO) == -1) { |
| 259 ReportChildError(exec_control[1]); | 260 ReportChildError(exec_control[1]); |
| 260 } | 261 } |
| 261 close(read_err[1]); | 262 close(read_err[1]); |
| 262 | 263 |
| 264 if (working_directory != NULL && chdir(working_directory) == -1) { |
| 265 ReportChildError(exec_control[1]); |
| 266 } |
| 267 |
| 263 execvp(path, const_cast<char* const*>(program_arguments)); | 268 execvp(path, const_cast<char* const*>(program_arguments)); |
| 264 ReportChildError(exec_control[1]); | 269 ReportChildError(exec_control[1]); |
| 265 } | 270 } |
| 266 | 271 |
| 267 // The arguments for the spawned process are not needed any longer. | 272 // The arguments for the spawned process are not needed any longer. |
| 268 delete[] program_arguments; | 273 delete[] program_arguments; |
| 269 | 274 |
| 270 int event_fds[2]; | 275 int event_fds[2]; |
| 271 result = pipe(event_fds); | 276 result = pipe(event_fds); |
| 272 if (result < 0) { | 277 if (result < 0) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 if (result == -1) { | 351 if (result == -1) { |
| 347 return false; | 352 return false; |
| 348 } | 353 } |
| 349 return true; | 354 return true; |
| 350 } | 355 } |
| 351 | 356 |
| 352 | 357 |
| 353 void Process::Exit(intptr_t id) { | 358 void Process::Exit(intptr_t id) { |
| 354 RemoveProcess(id); | 359 RemoveProcess(id); |
| 355 } | 360 } |
| OLD | NEW |