OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { | 90 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { |
91 int exit_code = 0; | 91 int exit_code = 0; |
92 // TODO(ager): Transform exit_code 255 to -1. | 92 int negative = 0; |
93 if (WIFEXITED(status)) exit_code = WEXITSTATUS(status); | 93 if (WIFEXITED(status)) { |
94 // TODO(ager): Transform termsig to -termsig to destinguish from | 94 exit_code = WEXITSTATUS(status); |
95 // exit codes. | 95 if (exit_code == 255) { |
96 if (WIFSIGNALED(status)) exit_code = WTERMSIG(status); | 96 exit_code = 1; |
| 97 negative = 1; |
| 98 } |
| 99 } |
| 100 if (WIFSIGNALED(status)) { |
| 101 exit_code = WTERMSIG(status); |
| 102 negative = 1; |
| 103 } |
97 ProcessInfo* process = LookupProcess(pid); | 104 ProcessInfo* process = LookupProcess(pid); |
98 if (process != NULL) { | 105 if (process != NULL) { |
99 intptr_t message[2] = { pid, exit_code }; | 106 int message[3] = { pid, exit_code, negative }; |
100 intptr_t result = | 107 intptr_t result = |
101 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message)); | 108 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message)); |
102 if (result != sizeof(message)) { | 109 if (result != sizeof(message)) { |
103 perror("ExitHandler notification failed"); | 110 perror("ExitHandler notification failed"); |
104 } | 111 } |
105 close(process->fd()); | 112 close(process->fd()); |
106 } | 113 } |
107 } | 114 } |
108 } | 115 } |
109 | 116 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 if (result == -1) { | 334 if (result == -1) { |
328 return false; | 335 return false; |
329 } | 336 } |
330 return true; | 337 return true; |
331 } | 338 } |
332 | 339 |
333 | 340 |
334 void Process::Exit(intptr_t id) { | 341 void Process::Exit(intptr_t id) { |
335 RemoveProcess(id); | 342 RemoveProcess(id); |
336 } | 343 } |
OLD | NEW |