| 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 #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 <poll.h> | 9 #include <poll.h> |
| 10 #include <signal.h> | 10 #include <signal.h> |
| 11 #include <stdio.h> | 11 #include <stdio.h> |
| 12 #include <stdlib.h> | 12 #include <stdlib.h> |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 #include <unistd.h> | 14 #include <unistd.h> |
| 15 | 15 |
| 16 #include "bin/fdutils.h" | 16 #include "bin/fdutils.h" |
| 17 #include "bin/thread.h" | 17 #include "bin/thread.h" |
| 18 | 18 |
| 19 extern char **environ; |
| 19 | 20 |
| 20 // ProcessInfo is used to map a process id to the file descriptor for | 21 // ProcessInfo is used to map a process id to the file descriptor for |
| 21 // the pipe used to communicate the exit code of the process to Dart. | 22 // the pipe used to communicate the exit code of the process to Dart. |
| 22 // ProcessInfo objects are kept in the static singly-linked | 23 // ProcessInfo objects are kept in the static singly-linked |
| 23 // ProcessInfoList. | 24 // ProcessInfoList. |
| 24 class ProcessInfo { | 25 class ProcessInfo { |
| 25 public: | 26 public: |
| 26 ProcessInfo(pid_t pid, intptr_t fd) : pid_(pid), fd_(fd) { } | 27 ProcessInfo(pid_t pid, intptr_t fd) : pid_(pid), fd_(fd) { } |
| 27 ~ProcessInfo() { | 28 ~ProcessInfo() { |
| 28 int closed = TEMP_FAILURE_RETRY(close(fd_)); | 29 int closed = TEMP_FAILURE_RETRY(close(fd_)); |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 if (TEMP_FAILURE_RETRY(dup2(read_err[1], STDERR_FILENO)) == -1) { | 454 if (TEMP_FAILURE_RETRY(dup2(read_err[1], STDERR_FILENO)) == -1) { |
| 454 ReportChildError(exec_control[1]); | 455 ReportChildError(exec_control[1]); |
| 455 } | 456 } |
| 456 TEMP_FAILURE_RETRY(close(read_err[1])); | 457 TEMP_FAILURE_RETRY(close(read_err[1])); |
| 457 | 458 |
| 458 if (working_directory != NULL && | 459 if (working_directory != NULL && |
| 459 TEMP_FAILURE_RETRY(chdir(working_directory)) == -1) { | 460 TEMP_FAILURE_RETRY(chdir(working_directory)) == -1) { |
| 460 ReportChildError(exec_control[1]); | 461 ReportChildError(exec_control[1]); |
| 461 } | 462 } |
| 462 | 463 |
| 463 if (environment != NULL) { | 464 if (program_environment != NULL) { |
| 464 TEMP_FAILURE_RETRY( | 465 environ = program_environment; |
| 465 execve(path, | |
| 466 const_cast<char* const*>(program_arguments), | |
| 467 program_environment)); | |
| 468 } else { | |
| 469 TEMP_FAILURE_RETRY( | |
| 470 execvp(path, const_cast<char* const*>(program_arguments))); | |
| 471 } | 466 } |
| 467 |
| 468 TEMP_FAILURE_RETRY( |
| 469 execvp(path, const_cast<char* const*>(program_arguments))); |
| 470 |
| 472 ReportChildError(exec_control[1]); | 471 ReportChildError(exec_control[1]); |
| 473 } | 472 } |
| 474 | 473 |
| 475 // The arguments and environment for the spawned process are not needed | 474 // The arguments and environment for the spawned process are not needed |
| 476 // any longer. | 475 // any longer. |
| 477 delete[] program_arguments; | 476 delete[] program_arguments; |
| 478 delete[] program_environment; | 477 delete[] program_environment; |
| 479 | 478 |
| 480 int event_fds[2]; | 479 int event_fds[2]; |
| 481 result = TEMP_FAILURE_RETRY(pipe(event_fds)); | 480 result = TEMP_FAILURE_RETRY(pipe(event_fds)); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 | 555 |
| 557 | 556 |
| 558 void Process::TerminateExitCodeHandler() { | 557 void Process::TerminateExitCodeHandler() { |
| 559 ExitCodeHandler::TerminateExitCodeThread(); | 558 ExitCodeHandler::TerminateExitCodeThread(); |
| 560 } | 559 } |
| 561 | 560 |
| 562 | 561 |
| 563 intptr_t Process::CurrentProcessId() { | 562 intptr_t Process::CurrentProcessId() { |
| 564 return static_cast<intptr_t>(getpid()); | 563 return static_cast<intptr_t>(getpid()); |
| 565 } | 564 } |
| OLD | NEW |