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 #if !TARGET_OS_IOS | 10 #if !TARGET_OS_IOS |
11 #include <crt_externs.h> // NOLINT | 11 #include <crt_externs.h> // NOLINT |
12 #endif | 12 #endif |
13 #include <errno.h> // NOLINT | 13 #include <errno.h> // NOLINT |
14 #include <fcntl.h> // NOLINT | 14 #include <fcntl.h> // NOLINT |
15 #include <poll.h> // NOLINT | 15 #include <poll.h> // NOLINT |
16 #include <signal.h> // NOLINT | 16 #include <signal.h> // NOLINT |
17 #include <stdio.h> // NOLINT | 17 #include <stdio.h> // NOLINT |
18 #include <stdlib.h> // NOLINT | 18 #include <stdlib.h> // NOLINT |
19 #include <string.h> // NOLINT | 19 #include <string.h> // NOLINT |
20 #include <unistd.h> // NOLINT | 20 #include <unistd.h> // NOLINT |
21 | 21 |
22 #include "bin/fdutils.h" | 22 #include "bin/fdutils.h" |
23 #include "bin/lockers.h" | 23 #include "bin/lockers.h" |
24 #include "bin/log.h" | 24 #include "bin/log.h" |
25 #include "bin/thread.h" | 25 #include "bin/thread.h" |
26 | 26 |
27 #include "platform/signal_blocker.h" | 27 #include "platform/signal_blocker.h" |
| 28 #include "platform/utils.h" |
28 | 29 |
29 | 30 |
30 | 31 |
31 namespace dart { | 32 namespace dart { |
32 namespace bin { | 33 namespace bin { |
33 | 34 |
34 // ProcessInfo is used to map a process id to the file descriptor for | 35 // ProcessInfo is used to map a process id to the file descriptor for |
35 // the pipe used to communicate the exit code of the process to Dart. | 36 // the pipe used to communicate the exit code of the process to Dart. |
36 // ProcessInfo objects are kept in the static singly-linked | 37 // ProcessInfo objects are kept in the static singly-linked |
37 // ProcessInfoList. | 38 // ProcessInfoList. |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 if (actual_errno == 0) actual_errno = EPERM; | 654 if (actual_errno == 0) actual_errno = EPERM; |
654 SetChildOsErrorMessage(); | 655 SetChildOsErrorMessage(); |
655 CloseAllPipes(); | 656 CloseAllPipes(); |
656 return actual_errno; | 657 return actual_errno; |
657 } | 658 } |
658 | 659 |
659 | 660 |
660 void SetChildOsErrorMessage() { | 661 void SetChildOsErrorMessage() { |
661 const int kBufferSize = 1024; | 662 const int kBufferSize = 1024; |
662 char error_message[kBufferSize]; | 663 char error_message[kBufferSize]; |
663 strerror_r(errno, error_message, kBufferSize); | 664 Utils::StrError(errno, error_message, kBufferSize); |
664 *os_error_message_ = strdup(error_message); | 665 *os_error_message_ = strdup(error_message); |
665 } | 666 } |
666 | 667 |
667 | 668 |
668 void ReportChildError() { | 669 void ReportChildError() { |
669 // In the case of failure in the child process write the errno and | 670 // In the case of failure in the child process write the errno and |
670 // the OS error message to the exec control pipe and exit. | 671 // the OS error message to the exec control pipe and exit. |
671 int child_errno = errno; | 672 int child_errno = errno; |
672 const int kBufferSize = 1024; | 673 const int kBufferSize = 1024; |
673 char os_error_message[kBufferSize]; | 674 char os_error_message[kBufferSize]; |
674 strerror_r(errno, os_error_message, kBufferSize); | 675 Utils::StrError(errno, os_error_message, kBufferSize); |
675 int bytes_written = | 676 int bytes_written = |
676 FDUtils::WriteToBlocking( | 677 FDUtils::WriteToBlocking( |
677 exec_control_[1], &child_errno, sizeof(child_errno)); | 678 exec_control_[1], &child_errno, sizeof(child_errno)); |
678 if (bytes_written == sizeof(child_errno)) { | 679 if (bytes_written == sizeof(child_errno)) { |
679 FDUtils::WriteToBlocking( | 680 FDUtils::WriteToBlocking( |
680 exec_control_[1], os_error_message, strlen(os_error_message) + 1); | 681 exec_control_[1], os_error_message, strlen(os_error_message) + 1); |
681 } | 682 } |
682 VOID_TEMP_FAILURE_RETRY(close(exec_control_[1])); | 683 VOID_TEMP_FAILURE_RETRY(close(exec_control_[1])); |
683 exit(1); | 684 exit(1); |
684 } | 685 } |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 bzero(&act, sizeof(act)); | 1063 bzero(&act, sizeof(act)); |
1063 act.sa_handler = SIG_DFL; | 1064 act.sa_handler = SIG_DFL; |
1064 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); | 1065 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); |
1065 } | 1066 } |
1066 } | 1067 } |
1067 | 1068 |
1068 } // namespace bin | 1069 } // namespace bin |
1069 } // namespace dart | 1070 } // namespace dart |
1070 | 1071 |
1071 #endif // defined(TARGET_OS_MACOS) | 1072 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |