| 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 <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 261 |
| 262 | 262 |
| 263 dart::Mutex* ExitCodeHandler::mutex_ = new dart::Mutex(); | 263 dart::Mutex* ExitCodeHandler::mutex_ = new dart::Mutex(); |
| 264 bool ExitCodeHandler::initialized_ = false; | 264 bool ExitCodeHandler::initialized_ = false; |
| 265 int ExitCodeHandler::sig_chld_fds_[2] = { 0, 0 }; | 265 int ExitCodeHandler::sig_chld_fds_[2] = { 0, 0 }; |
| 266 bool ExitCodeHandler::thread_terminated_ = false; | 266 bool ExitCodeHandler::thread_terminated_ = false; |
| 267 dart::Monitor* ExitCodeHandler::thread_terminate_monitor_ = new dart::Monitor(); | 267 dart::Monitor* ExitCodeHandler::thread_terminate_monitor_ = new dart::Monitor(); |
| 268 | 268 |
| 269 | 269 |
| 270 static void SetChildOsErrorMessage(char** os_error_message) { | 270 static void SetChildOsErrorMessage(char** os_error_message) { |
| 271 *os_error_message = strdup(strerror(errno)); | 271 const int kBufferSize = 1024; |
| 272 char error_message[kBufferSize]; |
| 273 strerror_r(errno, error_message, kBufferSize); |
| 274 *os_error_message = strdup(error_message); |
| 272 } | 275 } |
| 273 | 276 |
| 274 | 277 |
| 275 static void SigChldHandler(int process_signal, siginfo_t* siginfo, void* tmp) { | 278 static void SigChldHandler(int process_signal, siginfo_t* siginfo, void* tmp) { |
| 276 // Save errno so it can be restored at the end. | 279 // Save errno so it can be restored at the end. |
| 277 int entry_errno = errno; | 280 int entry_errno = errno; |
| 278 // Signal the exit code handler where the actual processing takes | 281 // Signal the exit code handler where the actual processing takes |
| 279 // place. | 282 // place. |
| 280 ssize_t result = | 283 ssize_t result = |
| 281 TEMP_FAILURE_RETRY(write(ExitCodeHandler::WakeUpFd(), "", 1)); | 284 TEMP_FAILURE_RETRY(write(ExitCodeHandler::WakeUpFd(), "", 1)); |
| 282 if (result < 1) { | 285 if (result < 1) { |
| 283 perror("Failed to write to wake-up fd in SIGCHLD handler"); | 286 perror("Failed to write to wake-up fd in SIGCHLD handler"); |
| 284 } | 287 } |
| 285 // Restore errno. | 288 // Restore errno. |
| 286 errno = entry_errno; | 289 errno = entry_errno; |
| 287 } | 290 } |
| 288 | 291 |
| 289 | 292 |
| 290 static void ReportChildError(int exec_control_fd) { | 293 static void ReportChildError(int exec_control_fd) { |
| 291 // In the case of failure in the child process write the errno and | 294 // In the case of failure in the child process write the errno and |
| 292 // the OS error message to the exec control pipe and exit. | 295 // the OS error message to the exec control pipe and exit. |
| 293 int child_errno = errno; | 296 int child_errno = errno; |
| 294 char* os_error_message = strerror(errno); | 297 const int kBufferSize = 1024; |
| 298 char os_error_message[kBufferSize]; |
| 299 strerror_r(errno, os_error_message, kBufferSize); |
| 295 ASSERT(sizeof(child_errno) == sizeof(errno)); | 300 ASSERT(sizeof(child_errno) == sizeof(errno)); |
| 296 int bytes_written = | 301 int bytes_written = |
| 297 FDUtils::WriteToBlocking( | 302 FDUtils::WriteToBlocking( |
| 298 exec_control_fd, &child_errno, sizeof(child_errno)); | 303 exec_control_fd, &child_errno, sizeof(child_errno)); |
| 299 if (bytes_written == sizeof(child_errno)) { | 304 if (bytes_written == sizeof(child_errno)) { |
| 300 FDUtils::WriteToBlocking( | 305 FDUtils::WriteToBlocking( |
| 301 exec_control_fd, os_error_message, strlen(os_error_message) + 1); | 306 exec_control_fd, os_error_message, strlen(os_error_message) + 1); |
| 302 } | 307 } |
| 303 VOID_TEMP_FAILURE_RETRY(close(exec_control_fd)); | 308 VOID_TEMP_FAILURE_RETRY(close(exec_control_fd)); |
| 304 exit(1); | 309 exit(1); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 | 578 |
| 574 | 579 |
| 575 intptr_t Process::CurrentProcessId() { | 580 intptr_t Process::CurrentProcessId() { |
| 576 return static_cast<intptr_t>(getpid()); | 581 return static_cast<intptr_t>(getpid()); |
| 577 } | 582 } |
| 578 | 583 |
| 579 } // namespace bin | 584 } // namespace bin |
| 580 } // namespace dart | 585 } // namespace dart |
| 581 | 586 |
| 582 #endif // defined(TARGET_OS_MACOS) | 587 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |