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