| 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 "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
| 7 | 7 |
| 8 #include "bin/process.h" | 8 #include "bin/process.h" |
| 9 | 9 |
| 10 #include <crt_externs.h> // NOLINT | 10 #include <crt_externs.h> // NOLINT |
| 11 #include <errno.h> // NOLINT | 11 #include <errno.h> // NOLINT |
| 12 #include <fcntl.h> // NOLINT | 12 #include <fcntl.h> // NOLINT |
| 13 #include <poll.h> // NOLINT | 13 #include <poll.h> // NOLINT |
| 14 #include <signal.h> // NOLINT | 14 #include <signal.h> // NOLINT |
| 15 #include <stdio.h> // NOLINT | 15 #include <stdio.h> // NOLINT |
| 16 #include <stdlib.h> // NOLINT | 16 #include <stdlib.h> // NOLINT |
| 17 #include <string.h> // NOLINT | 17 #include <string.h> // NOLINT |
| 18 #include <unistd.h> // NOLINT | 18 #include <unistd.h> // NOLINT |
| 19 | 19 |
| 20 #include "bin/fdutils.h" | 20 #include "bin/fdutils.h" |
| 21 #include "bin/lockers.h" | 21 #include "bin/lockers.h" |
| 22 #include "bin/log.h" | 22 #include "bin/log.h" |
| 23 #include "bin/thread.h" | 23 #include "bin/thread.h" |
| 24 | 24 |
| 25 #include "platform/signal_blocker.h" | 25 #include "platform/signal_blocker.h" |
| 26 | 26 |
| 27 | 27 |
| 28 extern char** environ; |
| 29 |
| 30 |
| 28 namespace dart { | 31 namespace dart { |
| 29 namespace bin { | 32 namespace bin { |
| 30 | 33 |
| 31 // ProcessInfo is used to map a process id to the file descriptor for | 34 // ProcessInfo is used to map a process id to the file descriptor for |
| 32 // the pipe used to communicate the exit code of the process to Dart. | 35 // the pipe used to communicate the exit code of the process to Dart. |
| 33 // ProcessInfo objects are kept in the static singly-linked | 36 // ProcessInfo objects are kept in the static singly-linked |
| 34 // ProcessInfoList. | 37 // ProcessInfoList. |
| 35 class ProcessInfo { | 38 class ProcessInfo { |
| 36 public: | 39 public: |
| 37 ProcessInfo(pid_t pid, intptr_t fd) : pid_(pid), fd_(fd) { } | 40 ProcessInfo(pid_t pid, intptr_t fd) : pid_(pid), fd_(fd) { } |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 if (TEMP_FAILURE_RETRY(dup2(read_err_[1], STDERR_FILENO)) == -1) { | 445 if (TEMP_FAILURE_RETRY(dup2(read_err_[1], STDERR_FILENO)) == -1) { |
| 443 ReportChildError(); | 446 ReportChildError(); |
| 444 } | 447 } |
| 445 | 448 |
| 446 if (working_directory_ != NULL && | 449 if (working_directory_ != NULL && |
| 447 TEMP_FAILURE_RETRY(chdir(working_directory_)) == -1) { | 450 TEMP_FAILURE_RETRY(chdir(working_directory_)) == -1) { |
| 448 ReportChildError(); | 451 ReportChildError(); |
| 449 } | 452 } |
| 450 | 453 |
| 451 if (program_environment_ != NULL) { | 454 if (program_environment_ != NULL) { |
| 452 VOID_TEMP_FAILURE_RETRY( | 455 environ = program_environment_; |
| 453 execvpe(path_, const_cast<char* const*>(program_arguments_), | |
| 454 program_environment_)); | |
| 455 } else { | |
| 456 VOID_TEMP_FAILURE_RETRY( | |
| 457 execvp(path_, const_cast<char* const*>(program_arguments_))); | |
| 458 } | 456 } |
| 459 | 457 |
| 458 VOID_TEMP_FAILURE_RETRY( |
| 459 execvp(path_, const_cast<char* const*>(program_arguments_))); |
| 460 |
| 460 ReportChildError(); | 461 ReportChildError(); |
| 461 } | 462 } |
| 462 | 463 |
| 463 | 464 |
| 464 void ExecDetachedProcess() { | 465 void ExecDetachedProcess() { |
| 465 if (mode_ == kDetached) { | 466 if (mode_ == kDetached) { |
| 466 ASSERT(write_out_[0] == -1); | 467 ASSERT(write_out_[0] == -1); |
| 467 ASSERT(write_out_[1] == -1); | 468 ASSERT(write_out_[1] == -1); |
| 468 ASSERT(read_err_[0] == -1); | 469 ASSERT(read_err_[0] == -1); |
| 469 ASSERT(read_err_[1] == -1); | 470 ASSERT(read_err_[1] == -1); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 int bytes_written = | 676 int bytes_written = |
| 676 FDUtils::WriteToBlocking(exec_control_[1], &pid, sizeof(pid)); | 677 FDUtils::WriteToBlocking(exec_control_[1], &pid, sizeof(pid)); |
| 677 ASSERT(bytes_written == sizeof(int)); | 678 ASSERT(bytes_written == sizeof(int)); |
| 678 USE(bytes_written); | 679 USE(bytes_written); |
| 679 } | 680 } |
| 680 | 681 |
| 681 | 682 |
| 682 void SetOSErrorMessage(int child_errno) { | 683 void SetOSErrorMessage(int child_errno) { |
| 683 const int kMaxMessageSize = 256; | 684 const int kMaxMessageSize = 256; |
| 684 char* message = static_cast<char*>(calloc(kMaxMessageSize, 0)); | 685 char* message = static_cast<char*>(calloc(kMaxMessageSize, 0)); |
| 685 char* os_error_message = strerror_r( | 686 strerror_r(child_errno, message, kMaxMessageSize - 1); |
| 686 child_errno, message, kMaxMessageSize - 1); | 687 *os_error_message_ = message; |
| 687 if (message == os_error_message) { | |
| 688 *os_error_message_ = message; | |
| 689 } else { | |
| 690 free(message); | |
| 691 *os_error_message_ = strdup(os_error_message); | |
| 692 } | |
| 693 } | 688 } |
| 694 | 689 |
| 695 | 690 |
| 696 void ClosePipe(int* fds) { | 691 void ClosePipe(int* fds) { |
| 697 for (int i = 0; i < 2; i++) { | 692 for (int i = 0; i < 2; i++) { |
| 698 if (fds[i] != -1) { | 693 if (fds[i] != -1) { |
| 699 VOID_TEMP_FAILURE_RETRY(close(fds[i])); | 694 VOID_TEMP_FAILURE_RETRY(close(fds[i])); |
| 700 fds[i] = -1; | 695 fds[i] = -1; |
| 701 } | 696 } |
| 702 } | 697 } |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 bzero(&act, sizeof(act)); | 1042 bzero(&act, sizeof(act)); |
| 1048 act.sa_handler = SIG_DFL; | 1043 act.sa_handler = SIG_DFL; |
| 1049 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); | 1044 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); |
| 1050 } | 1045 } |
| 1051 } | 1046 } |
| 1052 | 1047 |
| 1053 } // namespace bin | 1048 } // namespace bin |
| 1054 } // namespace dart | 1049 } // namespace dart |
| 1055 | 1050 |
| 1056 #endif // defined(TARGET_OS_MACOS) | 1051 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |