Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: runtime/bin/process_android.cc

Issue 22634003: Replaced strerror() calls with threadsafe strerror_r() (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file_macos.cc ('k') | runtime/bin/process_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 260
261 261
262 dart::Mutex* ExitCodeHandler::mutex_ = new dart::Mutex(); 262 dart::Mutex* ExitCodeHandler::mutex_ = new dart::Mutex();
263 bool ExitCodeHandler::initialized_ = false; 263 bool ExitCodeHandler::initialized_ = false;
264 int ExitCodeHandler::sig_chld_fds_[2] = { 0, 0 }; 264 int ExitCodeHandler::sig_chld_fds_[2] = { 0, 0 };
265 bool ExitCodeHandler::thread_terminated_ = false; 265 bool ExitCodeHandler::thread_terminated_ = false;
266 dart::Monitor* ExitCodeHandler::thread_terminate_monitor_ = new dart::Monitor(); 266 dart::Monitor* ExitCodeHandler::thread_terminate_monitor_ = new dart::Monitor();
267 267
268 268
269 static void SetChildOsErrorMessage(char** os_error_message) { 269 static void SetChildOsErrorMessage(char** os_error_message) {
270 *os_error_message = strdup(strerror(errno)); 270 const int kBufferSize = 1024;
271 char error_message[kBufferSize];
272 strerror_r(errno, error_message, kBufferSize);
273 *os_error_message = strdup(error_message);
271 } 274 }
272 275
273 276
274 static void SigChldHandler(int process_signal, siginfo_t* siginfo, void* tmp) { 277 static void SigChldHandler(int process_signal, siginfo_t* siginfo, void* tmp) {
275 // Save errno so it can be restored at the end. 278 // Save errno so it can be restored at the end.
276 int entry_errno = errno; 279 int entry_errno = errno;
277 // Signal the exit code handler where the actual processing takes 280 // Signal the exit code handler where the actual processing takes
278 // place. 281 // place.
279 ssize_t result = 282 ssize_t result =
280 TEMP_FAILURE_RETRY(write(ExitCodeHandler::WakeUpFd(), "", 1)); 283 TEMP_FAILURE_RETRY(write(ExitCodeHandler::WakeUpFd(), "", 1));
281 if (result < 1) { 284 if (result < 1) {
282 perror("Failed to write to wake-up fd in SIGCHLD handler"); 285 perror("Failed to write to wake-up fd in SIGCHLD handler");
283 } 286 }
284 // Restore errno. 287 // Restore errno.
285 errno = entry_errno; 288 errno = entry_errno;
286 } 289 }
287 290
288 291
289 static void ReportChildError(int exec_control_fd) { 292 static void ReportChildError(int exec_control_fd) {
290 // In the case of failure in the child process write the errno and 293 // In the case of failure in the child process write the errno and
291 // the OS error message to the exec control pipe and exit. 294 // the OS error message to the exec control pipe and exit.
292 int child_errno = errno; 295 int child_errno = errno;
293 char* os_error_message = strerror(errno); 296 const int kBufferSize = 1024;
297 char os_error_message[kBufferSize];
298 strerror_r(errno, os_error_message, kBufferSize);
294 ASSERT(sizeof(child_errno) == sizeof(errno)); 299 ASSERT(sizeof(child_errno) == sizeof(errno));
295 int bytes_written = 300 int bytes_written =
296 FDUtils::WriteToBlocking( 301 FDUtils::WriteToBlocking(
297 exec_control_fd, &child_errno, sizeof(child_errno)); 302 exec_control_fd, &child_errno, sizeof(child_errno));
298 if (bytes_written == sizeof(child_errno)) { 303 if (bytes_written == sizeof(child_errno)) {
299 FDUtils::WriteToBlocking( 304 FDUtils::WriteToBlocking(
300 exec_control_fd, os_error_message, strlen(os_error_message) + 1); 305 exec_control_fd, os_error_message, strlen(os_error_message) + 1);
301 } 306 }
302 TEMP_FAILURE_RETRY(close(exec_control_fd)); 307 TEMP_FAILURE_RETRY(close(exec_control_fd));
303 exit(1); 308 exit(1);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 583
579 584
580 intptr_t Process::CurrentProcessId() { 585 intptr_t Process::CurrentProcessId() {
581 return static_cast<intptr_t>(getpid()); 586 return static_cast<intptr_t>(getpid());
582 } 587 }
583 588
584 } // namespace bin 589 } // namespace bin
585 } // namespace dart 590 } // namespace dart
586 591
587 #endif // defined(TARGET_OS_ANDROID) 592 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/bin/file_macos.cc ('k') | runtime/bin/process_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698