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

Unified Diff: runtime/bin/process_android.cc

Issue 11558012: Use FormatMessageW for Windows error messages to handle internationalized messages correctly. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/process.cc ('k') | runtime/bin/process_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/process_android.cc
diff --git a/runtime/bin/process_android.cc b/runtime/bin/process_android.cc
index 3d593e259535b41ca3847b11104bb2c3ab2ae246..d18c92b79a83a571d6e55f1f41fd675fba60faca 100644
--- a/runtime/bin/process_android.cc
+++ b/runtime/bin/process_android.cc
@@ -258,16 +258,8 @@ bool ExitCodeHandler::thread_terminated_ = false;
dart::Monitor ExitCodeHandler::thread_terminate_monitor_;
-static char* SafeStrNCpy(char* dest, const char* src, size_t n) {
- strncpy(dest, src, n);
- dest[n - 1] = '\0';
- return dest;
-}
-
-
-static void SetChildOsErrorMessage(char* os_error_message,
- int os_error_message_len) {
- SafeStrNCpy(os_error_message, strerror(errno), os_error_message_len);
+static void SetChildOsErrorMessage(char** os_error_message) {
+ *os_error_message = strdup(strerror(errno));
}
@@ -315,8 +307,7 @@ int Process::Start(const char* path,
intptr_t* err,
intptr_t* id,
intptr_t* exit_event,
- char* os_error_message,
- int os_error_message_len) {
+ char** os_error_message) {
pid_t pid;
int read_in[2]; // Pipe for stdout to child process.
int read_err[2]; // Pipe for stderr to child process.
@@ -326,49 +317,49 @@ int Process::Start(const char* path,
bool initialized = ExitCodeHandler::EnsureInitialized();
if (!initialized) {
- SetChildOsErrorMessage(os_error_message, os_error_message_len);
+ SetChildOsErrorMessage(os_error_message);
Log::PrintErr("Error initializing exit code handler: %s\n",
- os_error_message);
+ *os_error_message);
return errno;
}
result = TEMP_FAILURE_RETRY(pipe(read_in));
if (result < 0) {
- SetChildOsErrorMessage(os_error_message, os_error_message_len);
- Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
+ SetChildOsErrorMessage(os_error_message);
+ Log::PrintErr("Error pipe creation failed: %s\n", *os_error_message);
return errno;
}
result = TEMP_FAILURE_RETRY(pipe(read_err));
if (result < 0) {
- SetChildOsErrorMessage(os_error_message, os_error_message_len);
+ SetChildOsErrorMessage(os_error_message);
TEMP_FAILURE_RETRY(close(read_in[0]));
TEMP_FAILURE_RETRY(close(read_in[1]));
- Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
+ Log::PrintErr("Error pipe creation failed: %s\n", *os_error_message);
return errno;
}
result = TEMP_FAILURE_RETRY(pipe(write_out));
if (result < 0) {
- SetChildOsErrorMessage(os_error_message, os_error_message_len);
+ SetChildOsErrorMessage(os_error_message);
TEMP_FAILURE_RETRY(close(read_in[0]));
TEMP_FAILURE_RETRY(close(read_in[1]));
TEMP_FAILURE_RETRY(close(read_err[0]));
TEMP_FAILURE_RETRY(close(read_err[1]));
- Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
+ Log::PrintErr("Error pipe creation failed: %s\n", *os_error_message);
return errno;
}
result = TEMP_FAILURE_RETRY(pipe(exec_control));
if (result < 0) {
- SetChildOsErrorMessage(os_error_message, os_error_message_len);
+ SetChildOsErrorMessage(os_error_message);
TEMP_FAILURE_RETRY(close(read_in[0]));
TEMP_FAILURE_RETRY(close(read_in[1]));
TEMP_FAILURE_RETRY(close(read_err[0]));
TEMP_FAILURE_RETRY(close(read_err[1]));
TEMP_FAILURE_RETRY(close(write_out[0]));
TEMP_FAILURE_RETRY(close(write_out[1]));
- Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
+ Log::PrintErr("Error pipe creation failed: %s\n", *os_error_message);
return errno;
}
@@ -378,7 +369,7 @@ int Process::Start(const char* path,
F_SETFD,
TEMP_FAILURE_RETRY(fcntl(exec_control[1], F_GETFD)) | FD_CLOEXEC));
if (result < 0) {
- SetChildOsErrorMessage(os_error_message, os_error_message_len);
+ SetChildOsErrorMessage(os_error_message);
TEMP_FAILURE_RETRY(close(read_in[0]));
TEMP_FAILURE_RETRY(close(read_in[1]));
TEMP_FAILURE_RETRY(close(read_err[0]));
@@ -387,7 +378,7 @@ int Process::Start(const char* path,
TEMP_FAILURE_RETRY(close(write_out[1]));
TEMP_FAILURE_RETRY(close(exec_control[0]));
TEMP_FAILURE_RETRY(close(exec_control[1]));
- Log::PrintErr("fcntl failed: %s\n", os_error_message);
+ Log::PrintErr("fcntl failed: %s\n", *os_error_message);
return errno;
}
@@ -416,7 +407,7 @@ int Process::Start(const char* path,
}
pid = TEMP_FAILURE_RETRY(fork());
if (pid < 0) {
- SetChildOsErrorMessage(os_error_message, os_error_message_len);
+ SetChildOsErrorMessage(os_error_message);
delete[] program_arguments;
TEMP_FAILURE_RETRY(close(read_in[0]));
TEMP_FAILURE_RETRY(close(read_in[1]));
@@ -481,14 +472,14 @@ int Process::Start(const char* path,
int event_fds[2];
result = TEMP_FAILURE_RETRY(pipe(event_fds));
if (result < 0) {
- SetChildOsErrorMessage(os_error_message, os_error_message_len);
+ SetChildOsErrorMessage(os_error_message);
TEMP_FAILURE_RETRY(close(read_in[0]));
TEMP_FAILURE_RETRY(close(read_in[1]));
TEMP_FAILURE_RETRY(close(read_err[0]));
TEMP_FAILURE_RETRY(close(read_err[1]));
TEMP_FAILURE_RETRY(close(write_out[0]));
TEMP_FAILURE_RETRY(close(write_out[1]));
- Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
+ Log::PrintErr("Error pipe creation failed: %s\n", *os_error_message);
return errno;
}
@@ -514,10 +505,13 @@ int Process::Start(const char* path,
FDUtils::ReadFromBlocking(
exec_control[0], &child_errno, sizeof(child_errno));
if (bytes_read == sizeof(child_errno)) {
- bytes_read = FDUtils::ReadFromBlocking(exec_control[0],
- os_error_message,
- os_error_message_len);
- os_error_message[os_error_message_len - 1] = '\0';
+ static const int kMaxMessageSize = 256;
+ char* message = static_cast<char*>(malloc(kMaxMessageSize));
+ bytes_read = FDUtils::ReadFromBlocking(exec_control[0],
+ message,
+ kMaxMessageSize);
+ message[kMaxMessageSize - 1] = '\0';
+ *os_error_message = message;
}
TEMP_FAILURE_RETRY(close(exec_control[0]));
« no previous file with comments | « runtime/bin/process.cc ('k') | runtime/bin/process_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698