| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 close(read_err[0]); | 182 close(read_err[0]); |
| 183 close(read_err[1]); | 183 close(read_err[1]); |
| 184 close(write_out[0]); | 184 close(write_out[0]); |
| 185 close(write_out[1]); | 185 close(write_out[1]); |
| 186 close(exec_control[0]); | 186 close(exec_control[0]); |
| 187 close(exec_control[1]); | 187 close(exec_control[1]); |
| 188 fprintf(stderr, "fcntl failed: %s\n", os_error_message); | 188 fprintf(stderr, "fcntl failed: %s\n", os_error_message); |
| 189 return errno; | 189 return errno; |
| 190 } | 190 } |
| 191 | 191 |
| 192 char* program_arguments[arguments_length + 2]; | 192 char** program_arguments = new char*[arguments_length + 2]; |
| 193 program_arguments[0] = const_cast<char *>(path); | 193 program_arguments[0] = const_cast<char *>(path); |
| 194 for (int i = 0; i < arguments_length; i++) { | 194 for (int i = 0; i < arguments_length; i++) { |
| 195 program_arguments[i + 1] = arguments[i]; | 195 program_arguments[i + 1] = arguments[i]; |
| 196 } | 196 } |
| 197 program_arguments[arguments_length + 1] = NULL; | 197 program_arguments[arguments_length + 1] = NULL; |
| 198 | 198 |
| 199 struct sigaction act; | 199 struct sigaction act; |
| 200 bzero(&act, sizeof(act)); | 200 bzero(&act, sizeof(act)); |
| 201 act.sa_sigaction = ExitHandler; | 201 act.sa_sigaction = ExitHandler; |
| 202 act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO; | 202 act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO; |
| 203 if (sigaction(SIGCHLD, &act, 0) != 0) { | 203 if (sigaction(SIGCHLD, &act, 0) != 0) { |
| 204 perror("Process start: setting signal handler failed"); | 204 perror("Process start: setting signal handler failed"); |
| 205 } | 205 } |
| 206 pid = fork(); | 206 pid = fork(); |
| 207 if (pid < 0) { | 207 if (pid < 0) { |
| 208 SetChildOsErrorMessage(os_error_message, os_error_message_len); | 208 SetChildOsErrorMessage(os_error_message, os_error_message_len); |
| 209 delete[] program_arguments; |
| 209 close(read_in[0]); | 210 close(read_in[0]); |
| 210 close(read_in[1]); | 211 close(read_in[1]); |
| 211 close(read_err[0]); | 212 close(read_err[0]); |
| 212 close(read_err[1]); | 213 close(read_err[1]); |
| 213 close(write_out[0]); | 214 close(write_out[0]); |
| 214 close(write_out[1]); | 215 close(write_out[1]); |
| 215 close(exec_control[0]); | 216 close(exec_control[0]); |
| 216 close(exec_control[1]); | 217 close(exec_control[1]); |
| 217 return errno; | 218 return errno; |
| 218 } else if (pid == 0) { | 219 } else if (pid == 0) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 248 FDUtils::WriteToBlocking( | 249 FDUtils::WriteToBlocking( |
| 249 exec_control[1], &child_errno, sizeof(child_errno)); | 250 exec_control[1], &child_errno, sizeof(child_errno)); |
| 250 if (bytes_written == sizeof(child_errno)) { | 251 if (bytes_written == sizeof(child_errno)) { |
| 251 FDUtils::WriteToBlocking( | 252 FDUtils::WriteToBlocking( |
| 252 exec_control[1], os_error_message, strlen(os_error_message) + 1); | 253 exec_control[1], os_error_message, strlen(os_error_message) + 1); |
| 253 } | 254 } |
| 254 close(exec_control[1]); | 255 close(exec_control[1]); |
| 255 exit(1); | 256 exit(1); |
| 256 } | 257 } |
| 257 | 258 |
| 259 // The arguments for the spawned process are not needed any longer. |
| 260 delete[] program_arguments; |
| 261 |
| 258 int event_fds[2]; | 262 int event_fds[2]; |
| 259 result = pipe(event_fds); | 263 result = pipe(event_fds); |
| 260 if (result < 0) { | 264 if (result < 0) { |
| 261 SetChildOsErrorMessage(os_error_message, os_error_message_len); | 265 SetChildOsErrorMessage(os_error_message, os_error_message_len); |
| 262 close(read_in[0]); | 266 close(read_in[0]); |
| 263 close(read_in[1]); | 267 close(read_in[1]); |
| 264 close(read_err[0]); | 268 close(read_err[0]); |
| 265 close(read_err[1]); | 269 close(read_err[1]); |
| 266 close(write_out[0]); | 270 close(write_out[0]); |
| 267 close(write_out[1]); | 271 close(write_out[1]); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 if (result == -1) { | 338 if (result == -1) { |
| 335 return false; | 339 return false; |
| 336 } | 340 } |
| 337 return true; | 341 return true; |
| 338 } | 342 } |
| 339 | 343 |
| 340 | 344 |
| 341 void Process::Exit(intptr_t id) { | 345 void Process::Exit(intptr_t id) { |
| 342 RemoveProcess(id); | 346 RemoveProcess(id); |
| 343 } | 347 } |
| OLD | NEW |