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

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

Powered by Google App Engine
This is Rietveld 408576698