| OLD | NEW |
| 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 "bin/process.h" | 5 #include "bin/process.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <signal.h> | 9 #include <signal.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 static void SetChildOsErrorMessage(char* os_error_message, | 81 static void SetChildOsErrorMessage(char* os_error_message, |
| 82 int os_error_message_len) { | 82 int os_error_message_len) { |
| 83 SafeStrNCpy(os_error_message, strerror(errno), os_error_message_len); | 83 SafeStrNCpy(os_error_message, strerror(errno), os_error_message_len); |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 void ExitHandler(int process_signal, siginfo_t* siginfo, void* tmp) { | 87 void ExitHandler(int process_signal, siginfo_t* siginfo, void* tmp) { |
| 88 int pid = 0; | 88 int pid = 0; |
| 89 int status = 0; | 89 int status = 0; |
| 90 // Save errno so it can be restored at the end. |
| 91 int entry_errno = errno; |
| 90 while ((pid = TEMP_FAILURE_RETRY(waitpid(-1, &status, WNOHANG))) > 0) { | 92 while ((pid = TEMP_FAILURE_RETRY(waitpid(-1, &status, WNOHANG))) > 0) { |
| 91 int exit_code = 0; | 93 int exit_code = 0; |
| 92 int negative = 0; | 94 int negative = 0; |
| 93 if (WIFEXITED(status)) { | 95 if (WIFEXITED(status)) { |
| 94 exit_code = WEXITSTATUS(status); | 96 exit_code = WEXITSTATUS(status); |
| 95 } | 97 } |
| 96 if (WIFSIGNALED(status)) { | 98 if (WIFSIGNALED(status)) { |
| 97 exit_code = WTERMSIG(status); | 99 exit_code = WTERMSIG(status); |
| 98 negative = 1; | 100 negative = 1; |
| 99 } | 101 } |
| 100 ProcessInfo* process = LookupProcess(pid); | 102 ProcessInfo* process = LookupProcess(pid); |
| 101 if (process != NULL) { | 103 if (process != NULL) { |
| 102 int message[3] = { pid, exit_code, negative }; | 104 int message[3] = { pid, exit_code, negative }; |
| 103 intptr_t result = | 105 intptr_t result = |
| 104 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message)); | 106 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message)); |
| 105 if (result != sizeof(message) && errno != EPIPE) { | 107 if (result != sizeof(message) && errno != EPIPE) { |
| 106 perror("ExitHandler notification failed"); | 108 perror("ExitHandler notification failed"); |
| 107 } | 109 } |
| 108 TEMP_FAILURE_RETRY(close(process->fd())); | 110 TEMP_FAILURE_RETRY(close(process->fd())); |
| 109 } | 111 } |
| 110 } | 112 } |
| 113 errno = entry_errno; |
| 111 } | 114 } |
| 112 | 115 |
| 113 | 116 |
| 114 static void ReportChildError(int exec_control_fd) { | 117 static void ReportChildError(int exec_control_fd) { |
| 115 // In the case of failure in the child process write the errno and | 118 // In the case of failure in the child process write the errno and |
| 116 // the OS error message to the exec control pipe and exit. | 119 // the OS error message to the exec control pipe and exit. |
| 117 int child_errno = errno; | 120 int child_errno = errno; |
| 118 char* os_error_message = strerror(errno); | 121 char* os_error_message = strerror(errno); |
| 119 ASSERT(sizeof(child_errno) == sizeof(errno)); | 122 ASSERT(sizeof(child_errno) == sizeof(errno)); |
| 120 int bytes_written = | 123 int bytes_written = |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 if (result == -1) { | 357 if (result == -1) { |
| 355 return false; | 358 return false; |
| 356 } | 359 } |
| 357 return true; | 360 return true; |
| 358 } | 361 } |
| 359 | 362 |
| 360 | 363 |
| 361 void Process::Exit(intptr_t id) { | 364 void Process::Exit(intptr_t id) { |
| 362 RemoveProcess(id); | 365 RemoveProcess(id); |
| 363 } | 366 } |
| OLD | NEW |