| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 while ((pid = TEMP_FAILURE_RETRY(waitpid(-1, &status, WNOHANG))) > 0) { | 93 while ((pid = TEMP_FAILURE_RETRY(waitpid(-1, &status, WNOHANG))) > 0) { |
| 94 int exit_code = 0; | 94 int exit_code = 0; |
| 95 int negative = 0; | 95 int negative = 0; |
| 96 if (WIFEXITED(status)) { | 96 if (WIFEXITED(status)) { |
| 97 exit_code = WEXITSTATUS(status); | 97 exit_code = WEXITSTATUS(status); |
| 98 } | 98 } |
| 99 if (WIFSIGNALED(status)) { | 99 if (WIFSIGNALED(status)) { |
| 100 exit_code = WTERMSIG(status); | 100 exit_code = WTERMSIG(status); |
| 101 negative = 1; | 101 negative = 1; |
| 102 } | 102 } |
| 103 // Lookup the process and extract all needed information from |
| 104 // it. The WriteToBlocking call below can cause the deletion of |
| 105 // the process object (because this signal handler can be running |
| 106 // on an arbitrary thread, not just the main thread) so we cannot |
| 107 // touch it after that call. |
| 103 ProcessInfo* process = LookupProcess(pid); | 108 ProcessInfo* process = LookupProcess(pid); |
| 109 intptr_t exit_code_fd = process->fd(); |
| 104 if (process != NULL) { | 110 if (process != NULL) { |
| 105 int message[3] = { pid, exit_code, negative }; | 111 int message[3] = { pid, exit_code, negative }; |
| 106 intptr_t result = | 112 intptr_t result = |
| 107 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message)); | 113 FDUtils::WriteToBlocking(exit_code_fd, &message, sizeof(message)); |
| 108 if (result != sizeof(message) && errno != EPIPE) { | 114 if (result != sizeof(message) && errno != EPIPE) { |
| 109 perror("ExitHandler notification failed"); | 115 perror("ExitHandler notification failed"); |
| 110 } | 116 } |
| 111 TEMP_FAILURE_RETRY(close(process->fd())); | 117 TEMP_FAILURE_RETRY(close(exit_code_fd)); |
| 112 } | 118 } |
| 113 } | 119 } |
| 114 errno = entry_errno; | 120 errno = entry_errno; |
| 115 } | 121 } |
| 116 | 122 |
| 117 | 123 |
| 118 static void ReportChildError(int exec_control_fd) { | 124 static void ReportChildError(int exec_control_fd) { |
| 119 // In the case of failure in the child process write the errno and | 125 // In the case of failure in the child process write the errno and |
| 120 // the OS error message to the exec control pipe and exit. | 126 // the OS error message to the exec control pipe and exit. |
| 121 int child_errno = errno; | 127 int child_errno = errno; |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 if (result == -1) { | 364 if (result == -1) { |
| 359 return false; | 365 return false; |
| 360 } | 366 } |
| 361 return true; | 367 return true; |
| 362 } | 368 } |
| 363 | 369 |
| 364 | 370 |
| 365 void Process::Exit(intptr_t id) { | 371 void Process::Exit(intptr_t id) { |
| 366 RemoveProcess(id); | 372 RemoveProcess(id); |
| 367 } | 373 } |
| OLD | NEW |