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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
7 | 7 |
8 #include "bin/process.h" | 8 #include "bin/process.h" |
9 | 9 |
10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
11 #include <fcntl.h> // NOLINT | 11 #include <fcntl.h> // NOLINT |
12 #include <poll.h> // NOLINT | 12 #include <poll.h> // NOLINT |
13 #include <stdio.h> // NOLINT | 13 #include <stdio.h> // NOLINT |
14 #include <stdlib.h> // NOLINT | 14 #include <stdlib.h> // NOLINT |
15 #include <string.h> // NOLINT | 15 #include <string.h> // NOLINT |
16 #include <sys/wait.h> // NOLINT | 16 #include <sys/wait.h> // NOLINT |
17 #include <unistd.h> // NOLINT | 17 #include <unistd.h> // NOLINT |
18 | 18 |
| 19 #include "bin/dartutils.h" |
19 #include "bin/fdutils.h" | 20 #include "bin/fdutils.h" |
20 #include "bin/lockers.h" | 21 #include "bin/lockers.h" |
21 #include "bin/log.h" | 22 #include "bin/log.h" |
22 #include "bin/thread.h" | 23 #include "bin/thread.h" |
23 | 24 |
24 #include "platform/signal_blocker.h" | 25 #include "platform/signal_blocker.h" |
25 #include "platform/utils.h" | 26 #include "platform/utils.h" |
26 | 27 |
27 | 28 |
28 extern char **environ; | 29 extern char **environ; |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 ReportChildError(); | 629 ReportChildError(); |
629 } | 630 } |
630 VOID_TEMP_FAILURE_RETRY(close(read_err_[1])); | 631 VOID_TEMP_FAILURE_RETRY(close(read_err_[1])); |
631 } | 632 } |
632 | 633 |
633 | 634 |
634 int CleanupAndReturnError() { | 635 int CleanupAndReturnError() { |
635 int actual_errno = errno; | 636 int actual_errno = errno; |
636 // If CleanupAndReturnError is called without an actual errno make | 637 // If CleanupAndReturnError is called without an actual errno make |
637 // sure to return an error anyway. | 638 // sure to return an error anyway. |
638 if (actual_errno == 0) actual_errno = EPERM; | 639 if (actual_errno == 0) { |
| 640 actual_errno = EPERM; |
| 641 } |
639 SetChildOsErrorMessage(); | 642 SetChildOsErrorMessage(); |
640 CloseAllPipes(); | 643 CloseAllPipes(); |
641 return actual_errno; | 644 return actual_errno; |
642 } | 645 } |
643 | 646 |
644 | 647 |
645 void SetChildOsErrorMessage() { | 648 void SetChildOsErrorMessage() { |
646 const int kBufferSize = 1024; | 649 const int kBufferSize = 1024; |
647 char error_message[kBufferSize]; | 650 char* error_message = DartUtils::ScopedCString(kBufferSize); |
648 Utils::StrError(errno, error_message, kBufferSize); | 651 Utils::StrError(errno, error_message, kBufferSize); |
649 *os_error_message_ = strdup(error_message); | 652 *os_error_message_ = error_message; |
650 } | 653 } |
651 | 654 |
652 | 655 |
653 void ReportChildError() { | 656 void ReportChildError() { |
654 // In the case of failure in the child process write the errno and | 657 // In the case of failure in the child process write the errno and |
655 // the OS error message to the exec control pipe and exit. | 658 // the OS error message to the exec control pipe and exit. |
656 int child_errno = errno; | 659 int child_errno = errno; |
657 const int kBufferSize = 1024; | 660 const int kBufferSize = 1024; |
658 char os_error_message[kBufferSize]; | 661 char os_error_message[kBufferSize]; |
659 Utils::StrError(errno, os_error_message, kBufferSize); | 662 Utils::StrError(errno, os_error_message, kBufferSize); |
(...skipping 14 matching lines...) Expand all Loading... |
674 // is communicated using the exec control pipe. | 677 // is communicated using the exec control pipe. |
675 int bytes_written = | 678 int bytes_written = |
676 FDUtils::WriteToBlocking(exec_control_[1], &pid, sizeof(pid)); | 679 FDUtils::WriteToBlocking(exec_control_[1], &pid, sizeof(pid)); |
677 ASSERT(bytes_written == sizeof(int)); | 680 ASSERT(bytes_written == sizeof(int)); |
678 USE(bytes_written); | 681 USE(bytes_written); |
679 } | 682 } |
680 | 683 |
681 | 684 |
682 void ReadChildError() { | 685 void ReadChildError() { |
683 const int kMaxMessageSize = 256; | 686 const int kMaxMessageSize = 256; |
684 char* message = static_cast<char*>(malloc(kMaxMessageSize)); | 687 char* message = DartUtils::ScopedCString(kMaxMessageSize); |
685 if (message != NULL) { | 688 if (message != NULL) { |
686 FDUtils::ReadFromBlocking(exec_control_[0], message, kMaxMessageSize); | 689 FDUtils::ReadFromBlocking(exec_control_[0], message, kMaxMessageSize); |
687 message[kMaxMessageSize - 1] = '\0'; | 690 message[kMaxMessageSize - 1] = '\0'; |
688 *os_error_message_ = message; | 691 *os_error_message_ = message; |
689 } else { | 692 } else { |
690 // Could not get error message. It will be NULL. | 693 // Could not get error message. It will be NULL. |
691 ASSERT(*os_error_message_ == NULL); | 694 ASSERT(*os_error_message_ == NULL); |
692 } | 695 } |
693 } | 696 } |
694 | 697 |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 bzero(&act, sizeof(act)); | 1002 bzero(&act, sizeof(act)); |
1000 act.sa_handler = SIG_DFL; | 1003 act.sa_handler = SIG_DFL; |
1001 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); | 1004 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); |
1002 } | 1005 } |
1003 } | 1006 } |
1004 | 1007 |
1005 } // namespace bin | 1008 } // namespace bin |
1006 } // namespace dart | 1009 } // namespace dart |
1007 | 1010 |
1008 #endif // defined(TARGET_OS_ANDROID) | 1011 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |