| Index: runtime/bin/process_macos.cc
|
| diff --git a/runtime/bin/process_macos.cc b/runtime/bin/process_macos.cc
|
| index 9a1d178864d969416f65c13f7c5bb362f323e9c1..eced5f82085dc282bc2588e85a8281e6bd872dcd 100644
|
| --- a/runtime/bin/process_macos.cc
|
| +++ b/runtime/bin/process_macos.cc
|
| @@ -52,7 +52,7 @@ static ProcessInfo* LookupProcess(pid_t pid) {
|
| }
|
|
|
|
|
| -static ProcessInfo* RemoveProcess(pid_t pid) {
|
| +static void RemoveProcess(pid_t pid) {
|
| ProcessInfo* prev = NULL;
|
| ProcessInfo* current = active_processes;
|
| while (current != NULL) {
|
| @@ -62,12 +62,12 @@ static ProcessInfo* RemoveProcess(pid_t pid) {
|
| } else {
|
| prev->set_next(current->next());
|
| }
|
| - return current;
|
| + delete current;
|
| + return;
|
| }
|
| prev = current;
|
| current = current->next();
|
| }
|
| - return NULL;
|
| }
|
|
|
|
|
| @@ -115,6 +115,24 @@ void ExitHandler(int process_signal, siginfo_t* siginfo, void* tmp) {
|
| }
|
|
|
|
|
| +static void ReportChildError(int exec_control_fd) {
|
| + // In the case of failure in the child process write the errno and
|
| + // the OS error message to the exec control pipe and exit.
|
| + int child_errno = errno;
|
| + char* os_error_message = strerror(errno);
|
| + ASSERT(sizeof(child_errno) == sizeof(errno));
|
| + int bytes_written =
|
| + FDUtils::WriteToBlocking(
|
| + exec_control_fd, &child_errno, sizeof(child_errno));
|
| + if (bytes_written == sizeof(child_errno)) {
|
| + FDUtils::WriteToBlocking(
|
| + exec_control_fd, os_error_message, strlen(os_error_message) + 1);
|
| + }
|
| + close(exec_control_fd);
|
| + exit(1);
|
| +}
|
| +
|
| +
|
| int Process::Start(const char* path,
|
| char* arguments[],
|
| intptr_t arguments_length,
|
| @@ -230,30 +248,23 @@ int Process::Start(const char* path,
|
| close(read_err[0]);
|
| close(exec_control[0]);
|
|
|
| - dup2(write_out[0], STDIN_FILENO);
|
| + if (dup2(write_out[0], STDIN_FILENO) == -1) {
|
| + ReportChildError(exec_control[1]);
|
| + }
|
| close(write_out[0]);
|
|
|
| - dup2(read_in[1], STDOUT_FILENO);
|
| + if (dup2(read_in[1], STDOUT_FILENO) == -1) {
|
| + ReportChildError(exec_control[1]);
|
| + }
|
| close(read_in[1]);
|
|
|
| - dup2(read_err[1], STDERR_FILENO);
|
| + if (dup2(read_err[1], STDERR_FILENO) == -1) {
|
| + ReportChildError(exec_control[1]);
|
| + }
|
| close(read_err[1]);
|
|
|
| execvp(path, const_cast<char* const*>(program_arguments));
|
| - // In the case of failure write the errno and the OS error message
|
| - // to the exec control pipe.
|
| - int child_errno = errno;
|
| - char* os_error_message = strerror(errno);
|
| - ASSERT(sizeof(child_errno) == sizeof(errno));
|
| - int bytes_written =
|
| - FDUtils::WriteToBlocking(
|
| - exec_control[1], &child_errno, sizeof(child_errno));
|
| - if (bytes_written == sizeof(child_errno)) {
|
| - FDUtils::WriteToBlocking(
|
| - exec_control[1], os_error_message, strlen(os_error_message) + 1);
|
| - }
|
| - close(exec_control[1]);
|
| - exit(1);
|
| + ReportChildError(exec_control[1]);
|
| }
|
|
|
| // The arguments for the spawned process are not needed any longer.
|
|
|