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

Unified Diff: runtime/bin/process_android.cc

Issue 23428002: Fix android compilation by copying process_linux.cc to process_android.cc. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | 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 30a488b2432d786604f74345f3fa2cb94a5629bf..43950766539908e2a327e5d52532eed571aee275 100644
--- a/runtime/bin/process_android.cc
+++ b/runtime/bin/process_android.cc
@@ -22,6 +22,9 @@
#include "bin/thread.h"
+extern char **environ;
+
+
namespace dart {
namespace bin {
@@ -332,7 +335,7 @@ int Process::Start(const char* path,
if (!initialized) {
SetChildOsErrorMessage(os_error_message);
Log::PrintErr("Error initializing exit code handler: %s\n",
- *os_error_message);
+ *os_error_message);
return errno;
}
@@ -465,15 +468,13 @@ int Process::Start(const char* path,
ReportChildError(exec_control[1]);
}
- if (environment != NULL) {
- TEMP_FAILURE_RETRY(
- execve(path,
- const_cast<char* const*>(program_arguments),
- program_environment));
- } else {
- TEMP_FAILURE_RETRY(
- execvp(path, const_cast<char* const*>(program_arguments)));
+ if (program_environment != NULL) {
+ environ = program_environment;
}
+
+ TEMP_FAILURE_RETRY(
+ execvp(path, const_cast<char* const*>(program_arguments)));
+
ReportChildError(exec_control[1]);
}
@@ -568,15 +569,128 @@ int Process::Start(const char* path,
}
-bool Process::Kill(intptr_t id, int signal) {
- int result = TEMP_FAILURE_RETRY(kill(id, signal));
- if (result == -1) {
- return false;
+class BufferList: public BufferListBase {
+ public:
+ bool Read(int fd, intptr_t available) {
+ // Read all available bytes.
+ while (available > 0) {
+ if (free_size_ == 0) Allocate();
+ ASSERT(free_size_ > 0);
+ ASSERT(free_size_ <= kBufferSize);
+ intptr_t block_size = dart::Utils::Minimum(free_size_, available);
+ intptr_t bytes = TEMP_FAILURE_RETRY(read(
+ fd,
+ reinterpret_cast<void*>(FreeSpaceAddress()),
+ block_size));
+ if (bytes < 0) return false;
+ data_size_ += bytes;
+ free_size_ -= bytes;
+ available -= bytes;
+ }
+ return true;
}
+};
+
+
+static bool CloseProcessBuffers(struct pollfd fds[3]) {
+ int e = errno;
+ VOID_TEMP_FAILURE_RETRY(close(fds[0].fd));
+ VOID_TEMP_FAILURE_RETRY(close(fds[1].fd));
+ VOID_TEMP_FAILURE_RETRY(close(fds[2].fd));
+ errno = e;
+ return false;
+}
+
+
+bool Process::Wait(intptr_t pid,
+ intptr_t in,
+ intptr_t out,
+ intptr_t err,
+ intptr_t exit_event,
+ ProcessResult* result) {
+ // Close input to the process right away.
+ VOID_TEMP_FAILURE_RETRY(close(in));
+
+ // There is no return from this function using Dart_PropagateError
+ // as memory used by the buffer lists is freed through their
+ // destructors.
+ BufferList out_data;
+ BufferList err_data;
+ union {
+ uint8_t bytes[8];
+ int32_t ints[2];
+ } exit_code_data;
+
+ struct pollfd fds[3];
+ fds[0].fd = out;
+ fds[1].fd = err;
+ fds[2].fd = exit_event;
+
+ for (int i = 0; i < 3; i++) {
+ fds[i].events = POLLIN;
+ }
+
+ int alive = 3;
+ while (alive > 0) {
+ // Blocking call waiting for events from the child process.
+ if (TEMP_FAILURE_RETRY(poll(fds, alive, -1)) <= 0) {
+ return CloseProcessBuffers(fds);
+ }
+
+ // Process incoming data.
+ int current_alive = alive;
+ for (int i = 0; i < current_alive; i++) {
+ if (fds[i].revents & POLLIN) {
+ intptr_t avail = FDUtils::AvailableBytes(fds[i].fd);
+ if (fds[i].fd == out) {
+ if (!out_data.Read(out, avail)) {
+ return CloseProcessBuffers(fds);
+ }
+ } else if (fds[i].fd == err) {
+ if (!err_data.Read(err, avail)) {
+ return CloseProcessBuffers(fds);
+ }
+ } else if (fds[i].fd == exit_event) {
+ if (avail == 8) {
+ intptr_t b = TEMP_FAILURE_RETRY(read(exit_event,
+ exit_code_data.bytes, 8));
+ if (b != 8) {
+ return CloseProcessBuffers(fds);
+ }
+ }
+ } else {
+ UNREACHABLE();
+ }
+ }
+ if (fds[i].revents & POLLHUP) {
+ VOID_TEMP_FAILURE_RETRY(close(fds[i].fd));
+ alive--;
+ if (i < alive) {
+ fds[i] = fds[alive];
+ }
+ }
+ }
+ }
+
+ // All handles closed and all data read.
+ result->set_stdout_data(out_data.GetData());
+ result->set_stderr_data(err_data.GetData());
+
+ // Calculate the exit code.
+ intptr_t exit_code = exit_code_data.ints[0];
+ intptr_t negative = exit_code_data.ints[1];
+ if (negative) exit_code = -exit_code;
+ result->set_exit_code(exit_code);
+
return true;
}
+bool Process::Kill(intptr_t id, int signal) {
+ return (TEMP_FAILURE_RETRY(kill(id, signal)) != -1);
+}
+
+
void Process::TerminateExitCodeHandler() {
ExitCodeHandler::TerminateExitCodeThread();
}
« no previous file with comments | « no previous file | runtime/bin/process_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698